From 22c1dffc4bf4814d577ac3fe81307896f0b1ae22 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Fri, 17 Jan 2025 20:21:52 +0200
Subject: [PATCH] pre-commit stuff.

- Replace prospector with Pylint and Bandit. Those are the only tools
  not already configured in pre-commit. This way provides better
  control, better outputs and seems more reliable.
- Remove the GitLab CI linter, doesn't work.
- Address a bunch of pre-commit issues.
---
 .pre-commit-config.yaml            | 53 ++++++++++--------------------
 Documents/Shore/taxes/Makefile     |  2 +-
 Documents/bin/download-password-db |  2 +-
 Documents/bin/git-manage           | 19 +++++------
 Documents/bin/monitor              |  2 +-
 Documents/bin/planet               |  3 +-
 6 files changed, 32 insertions(+), 49 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 01defe8..c2e3409 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -46,33 +46,24 @@ repos:
           - |
             --line-length=79
 
-  - repo: https://github.com/PyCQA/prospector
-    rev: v1.12.1
+  - repo: https://github.com/pylint-dev/pylint.git
+    rev: v3.3.3
     hooks:
-      - id: prospector
+      - id: pylint
+        exclude: *excluded_pythonscripts
+        args: ["--disable", "line-too-long,broad-exception-raised"]
+
+  - repo: https://github.com/DanielNoord/pydocstringformatter.git
+    rev: v0.7.3
+    hooks:
+      - id: pydocstringformatter
+        exclude: *excluded_pythonscripts
+
+  - repo: https://github.com/PyCQA/bandit.git
+    rev: "1.8.0"
+    hooks:
+      - id: bandit
         exclude: *excluded_pythonscripts
-        args:
-          - |-
-            --max-line-length=79
-          - |-
-            --with-tool=pyroma
-          - |-
-            --with-tool=bandit
-          - |-
-            --without-tool=pep257
-          - |-
-            --doc-warnings
-          - |-
-            --test-warnings
-          - |-
-            --full-pep8
-          - |-
-            --strictness=high
-          - |-
-            --no-autodetect
-        additional_dependencies:
-          - bandit
-          - pyroma
 
   - repo: https://github.com/pycqa/flake8.git
     rev: 7.1.1
@@ -92,7 +83,7 @@ repos:
         exclude: rabbitmqadmin|\.config/git/config|Pipfile\.lock|npmrc
 
   - repo: https://git.shore.co.il/nimrod/pre-commit-hooks.git
-    rev: v0.5.1
+    rev: v0.5.2
     hooks:
       - id: shell-validate
         exclude: &excluded_shellscripts |-
@@ -111,18 +102,10 @@ repos:
         types: [text]
 
   - repo: https://github.com/executablebooks/mdformat.git
-    rev: 0.7.17
+    rev: 0.7.21
     hooks:
       - id: mdformat
 
-  - repo: https://gitlab.com/devopshq/gitlab-ci-linter
-    rev: v1.0.6
-    hooks:
-      - id: gitlab-ci-linter
-        args:
-          - "--server"
-          - https://git.shore.co.il
-
   - repo: https://github.com/codespell-project/codespell.git
     rev: v2.3.0
     hooks:
diff --git a/Documents/Shore/taxes/Makefile b/Documents/Shore/taxes/Makefile
index a273fcf..93a6abc 100644
--- a/Documents/Shore/taxes/Makefile
+++ b/Documents/Shore/taxes/Makefile
@@ -1,6 +1,6 @@
 last_month != date +%Y-%m --date 'last month'
 last_zip != find -maxdepth 1 -name '*.zip' \! -name '${last_month}.zip' -printf '%f\n' | sort -r | head -1
-new_files != find reciepts/ -type f -newer ${last_zip}
+new_files != find receipts/ -type f -newer ${last_zip}
 
 .PHONY: send
 send: ${last_month}.zip
diff --git a/Documents/bin/download-password-db b/Documents/bin/download-password-db
index c1003ac..6b2badf 100755
--- a/Documents/bin/download-password-db
+++ b/Documents/bin/download-password-db
@@ -14,7 +14,7 @@ import os.path
 import subprocess  # nosec
 
 DB_PATH = "Documents/Database.kdbx"
-DEST = os.path.expanduser(f"~/{ os.path.dirname(DB_PATH) }")
+DEST = os.path.expanduser(f"~/{os.path.dirname(DB_PATH)}")
 SOURCE = f"nextcloud:{DB_PATH}"
 
 
diff --git a/Documents/bin/git-manage b/Documents/bin/git-manage
index 8f8ee5d..325fed8 100755
--- a/Documents/bin/git-manage
+++ b/Documents/bin/git-manage
@@ -24,7 +24,7 @@ GH_MIRROR_PREFIX = "https://*****@github.com/"
 
 def error(message):
     """Print an error message with the current subparser's usage and exit."""
-    # pylint: disable=protected-access
+    # pylint: disable=protected-access,possibly-used-before-assignment
     sub_parser = arg_parser._subparsers._actions[1].choices[_args.command]
     sub_parser.error(message)
 
@@ -62,7 +62,7 @@ def mirror_project(project, gh_conn, token):
     except github3.exceptions.NotFoundError:
         gh_repo = gh_conn.create_repository(project.name)
         print(
-            f"Created a new GitHub reposiroty {gh_repo.html_url}.",
+            f"Created a new GitHub repository {gh_repo.html_url}.",
             file=sys.stderr,
         )
 
@@ -96,7 +96,7 @@ def get_mirror_token():
     Reads it from a Keepass password database using Passhole.
     """
     ENTRY_PATH = "Web Sites/GitHub".split("/")  # noqa
-    TOKEN_FIELD = "GitLab mirroring token"  # noqa nosec
+    TOKEN_FIELD = "GitLab mirroring token"  # nosec # noqa
 
     # The following line requires an interactive session for getting the
     # password.
@@ -152,9 +152,9 @@ def guess_name(args, gh_conn=None, gl_conn=None):
             error("Name not provided and not in a Git repo.")
 
         remote = guess_remote(
-            remote_type="github"
-            if "github" in args and args.github
-            else "gitlab",
+            remote_type=(
+                "github" if "github" in args and args.github else "gitlab"
+            ),
             gl_conn=gl_conn,
         )
         if remote is None:
@@ -162,11 +162,10 @@ def guess_name(args, gh_conn=None, gl_conn=None):
                 error("Name not provided and could not find a GitHub remote.")
             else:
                 error("Name not provided and could not find a GitLab remote.")
+        if "github" in args and args.github:
+            name = rcfiles.github.url_to_name(remote["url"])
         else:
-            if "github" in args and args.github:
-                name = rcfiles.github.url_to_name(remote["url"])
-            else:
-                name = rcfiles.gitlab.url_to_name(gl_conn, remote["url"])
+            name = rcfiles.gitlab.url_to_name(gl_conn, remote["url"])
         print(
             f"""Name not provided, using {name} from the {remote["name"]} remote.""",  # noqa: E501
             file=sys.stderr,
diff --git a/Documents/bin/monitor b/Documents/bin/monitor
index 0d6944c..0e79d79 100755
--- a/Documents/bin/monitor
+++ b/Documents/bin/monitor
@@ -8,7 +8,7 @@ else
     notify='notify'
 fi
 
-eval "$@" || code="$?"
+eval "$*" || code="$?"
 code="${code:-0}"
 
 if [ "$code" -eq 0 ]
diff --git a/Documents/bin/planet b/Documents/bin/planet
index b6b3ae4..2a1816f 100755
--- a/Documents/bin/planet
+++ b/Documents/bin/planet
@@ -7,7 +7,7 @@ import sys
 import webbrowser
 
 import xdg.BaseDirectory  # pylint: disable=import-error
-import yaml
+import yaml  # pylint: disable=import-error
 
 EXAMPLE_CONFIG = """---
 general:
@@ -46,6 +46,7 @@ def get_config(path=None):
     if path:
         path = path.expanduser()
         if not path.exists() and not path.is_file():
+            # pylint: disable=possibly-used-before-assignment
             arg_parser.error("Configuration file does not exist.")
 
     else:
-- 
GitLab