Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved pre-commit Hooks #69

Open
AFg6K7h4fhy2 opened this issue Feb 11, 2025 · 0 comments
Open

Resolved pre-commit Hooks #69

AFg6K7h4fhy2 opened this issue Feb 11, 2025 · 0 comments
Assignees

Comments

@AFg6K7h4fhy2
Copy link
Collaborator

This issue exists to generate a consensus on the content of the pre-commit config file employed in this repository.

At present, the author employs the following pre-commit config file.

Author's Pre-Commit Config File
repos:
################################################################################
# GENERAL
################################################################################
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
    -   id: check-added-large-files
        args: ["--maxkb=10000"]
    -   id: check-yaml
        args: ["--allow-multiple-documents"]
    -   id: check-toml
    -   id: end-of-file-fixer
    -   id: mixed-line-ending
    -   id: trailing-whitespace
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
    # prevent giant files from being committed.
    -   id: check-added-large-files
        args: ["--maxkb=10000"]
    # simply check whether files parse as valid
    # python
    -   id: check-ast
    # check for files with names that would
    # conflict on a case-insensitive filesystem
    # like MacOS HFS+ or Windows FAT.
    -   id: check-case-conflict
    # checks for a common error of placing
    # code before the docstring.
    -   id: check-docstring-first
    # attempts to load all yaml files to
    # verify syntax.
    -   id: check-yaml
        # allow yaml files which use the
        # multi-document syntax
        args: ["--allow-multiple-documents"]
    # attempts to load all TOML files to
    # verify syntax.
    -   id: check-toml
    # makes sure files end in a newline and
    # only a newline.
    -   id: end-of-file-fixer
    # replaces or checks mixed line ending.
    -   id: mixed-line-ending
    # verifies that test files are named
    # correctly.
    -   id: name-tests-test
        # ensure tests match test_.*\.py
        args: ["--pytest-test-first"]
    # trims trailing whitespace.
    -   id: trailing-whitespace
    # checks that non-binary executables have
    # a proper shebang.
    -   id: check-executables-have-shebangs
        files: \.sh$
################################################################################
# QUARTO README RENDERING
################################################################################
-   repo: local
    hooks:
    -   id: render-quarto-readme
        name: "render README.qmd as README.md"
        entry: "./scripts/hooks/render-quarto-readme.sh"
        language: script
        always_run: true
        files: "README.(q|)md"
################################################################################
# PYTHON
################################################################################
-   repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.9.4
    hooks:
    # "currently, the Ruff formatter does not sort imports.
    # In order to both sort imports and format, call
    # the Ruff linter and then the formatter:"
    -   id: ruff
        args: [
          "check",
          "--select",
          # isort
          "I",
          "--fix"]
    # run ruff linter; the Ruff Linter is an extremely fast Python linter
    # designed as a drop-in replacement for Flake8 (plus dozens of plugins),
    # isort, pydocstyle, pyupgrade, autoflake, and more
    -   id: ruff
        args: [
          # ambiguous variable name: {name}
          "--ignore=E741",
          # do not assign a lambda expression, use a def
          "--ignore=E731",
          # found useless expression. ignore since .qmd displays
          "--ignore=B018",
          # {name} is too complex ({complexity} > {max_complexity})
          # note: ignored on select repositories
          "--ignore=C901",
          # E and W: pycodestyle, standard PEP8 errors and pycodestyle warnings.
          # F: pyflakes warnings (e.g., unused variables, undefined names).,
          # B: flake8-bugbear (useful best practices).
          # SIM: flake8-simplify
          # C90: McCabe complexity (cyclomatic complexity).
          # UP: pyupgrade, Python version compatibility
          "--select=E,W,F,B,C90,UP,SIM",
          # linter checks for lines, but doesn't fix, default is 88
          "--line-length=79",
          # lint all files in the current directory, and fix any fixable errors.
          "--fix"]
    # run the ruff-formatter; the Ruff formatter is an extremely fast
    # Python code formatter designed as a drop-in replacement for Black
    -   id: ruff-format
        args: [
          "--line-length=79",
        ]
################################################################################
# GITHUB ACTIONS
################################################################################
-   repo: https://github.com/rhysd/actionlint
    rev: v1.7.7
    hooks:
    -   id: actionlint
################################################################################
# SPELLING
################################################################################
-   repo: https://github.com/crate-ci/typos
    rev: typos-dict-v0.12.4
    hooks:
    -   id: typos
        args: ["--force-exclude"]
################################################################################
# COMMIT MESSAGES
################################################################################
-   repo: https://github.com/commitizen-tools/commitizen
    rev: v4.1.1
    hooks:
    -   id: commitizen
-   repo: https://github.com/jorisroovers/gitlint
    rev:  v0.19.1
    hooks:
    -   id: gitlint
################################################################################

Most if not all hooks in this config file have been of use to the author at least several times; however, utility from some of the hooks is infrequent.

Some have suggested that the config file in this repository sync exactly with the one employed in pyrenew (see below), but the author does not perceive this as necessarily useful.

A resolution on the contents of the config file for this repository is wanted by STF members.

Pyrenew-HEW Config File
repos:
  #####
  # Basic file cleanliness
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: check-added-large-files
      - id: check-yaml
      - id: check-toml
      - id: end-of-file-fixer
      - id: mixed-line-ending
      - id: trailing-whitespace
  #####
  # Python
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.7.1
    hooks:
      # Sort imports
      - id: ruff
        args: ["check", "--select", "I", "--fix"]
        # Run the linter
      - id: ruff
        # Run the formatter
      - id: ruff-format
        args: ["--line-length", "79"]
  #####
  # R
  - repo: https://github.com/lorenzwalthert/precommit
    rev: v0.4.3
    hooks:
      - id: style-files
      - id: lintr
  # Secrets
  - repo: https://github.com/Yelp/detect-secrets
    rev: v1.5.0
    hooks:
      - id: detect-secrets
        args: ["--baseline", ".secrets.baseline"]
        exclude: package.lock.json
@AFg6K7h4fhy2 AFg6K7h4fhy2 self-assigned this Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant