pre-commit-hooks

repository·main·Indexed 27 days ago

https://github.com/pre-commit/pre-commit-hooks

A collection of out-of-the-box hooks for the pre-commit framework providing common linting, formatting, and security checks. Includes hooks such as trailing-whitespace, check-yaml, detect-aws-credentials, and pretty-format-json. These can be used via a .pre-commit-config.yaml file or installed as a standalone Python package using pip.

Tokens
1K
Snippets
3
Records
16
Agent score
42%

What's inside pre-commit-hooks

  1. Use pre-commit-hooks with pre-commit

    main

    To use these hooks in your project, add the pre-commit-hooks repository to your .pre-commit-config.yaml file. You must specify the repo, a rev (version), and the specific id of the hooks you want to run.

    -   repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v6.0.0  # Use the ref you want to point at
        hooks:
        -   id: trailing-whitespace
        # -   id: ...
  2. Configure trailing-whitespace

    main

    Trims trailing whitespace from lines.

    Arguments:

    • --markdown-linebreak-ext=<ext>: Use to preserve Markdown hard linebreaks (e.g., args: [--markdown-linebreak-ext=md]). Use * to treat all files as markdown.
    • --chars,"<chars to trim>": Specify a custom set of characters to trim instead of the default whitespace.
  3. Configure file-contents-sorter

    main

    Sorts lines in specified files (alphabetical by default). Note: This removes blank lines and ignores comments. All newlines are converted to line feeds (\n).

    Arguments:

    • --ignore-case: Fold lower case to upper case.
    • --unique: Ensure each line is unique.
  4. Configure detect-aws-credentials

    main

    Checks for AWS secrets configured via the AWS CLI.

    Arguments:

    • --credentials-file CREDENTIALS_FILE: Path to an additional AWS CLI style configuration file (can be repeated).
    • --allow-missing-credentials: Allows the hook to pass even if no credentials are detected.
  5. Configure check-yaml

    main

    Verifies YAML syntax.

    Arguments:

    • --allow-multiple-documents: Allows YAML files using multi-document syntax.
    • --unsafe: Performs a syntax-only check without loading files (enables extensions/unsafe constructs). This implies --allow-multiple-documents.
  6. Configure pretty-format-json

    main

    Checks that JSON files are pretty-printed (sorted keys and indented).

    Arguments:

    • --autofix: Automatically formats files.
    • --indent <value>: Indentation level (number or whitespace string). Defaults to 2.
    • --no-ensure-ascii: Preserves unicode characters.
    • --no-sort-keys: Retains original key ordering when autofixing.
    • --top-keys <comma,separated,keys>: Keys to keep at the top of mappings.