### Pre-commit Configuration Example Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md An example of a .pre-commit-config.yaml file demonstrating how to integrate various hooks. ```yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: # Format checkers - id: check-ast - id: check-json - id: check-yaml # Security checkers - id: detect-private-key - id: detect-aws-credentials # File fixers - id: end-of-file-fixer - id: trailing-whitespace-fixer - id: pretty-format-json args: ['--autofix'] # Protection hooks - id: no-commit-to-branch args: ['--branch', 'main', '--branch', 'develop'] ``` -------------------------------- ### Transformation Example: Before and After Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/requirements_txt_fixer.md Shows a practical example of how the requirements.txt file is transformed by the hook, demonstrating sorting, deduplication, and removal of specific package versions. ```bash # Before: # Top comment zebra==1.0 apple==2.0 # Middle comment banana==1.5 pkg-resources==0.0.0 apple==2.0 # After: # Top comment apple==2.0 # Middle comment banana==1.5 zebra==1.0 ``` -------------------------------- ### check_file Usage Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_builtin_literals.md Demonstrates how to use the `check_file` function with different configurations. Examples include checking with default settings, ignoring specific types, and disallowing dict keyword arguments. ```python from pre_commit_hooks.check_builtin_literals import check_file # Check file with defaults violations = check_file('script.py') # Ignore 'list' and 'dict' violations violations = check_file('script.py', ignore={'list', 'dict'}) # Disallow dict with keywords violations = check_file('script.py', allow_dict_kwargs=False) ``` -------------------------------- ### Detect AWS Credentials Hook Usage Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/detect_aws_credentials.md Examples demonstrating how to use the detect-aws-credentials hook with different configurations, including default files, custom files, and allowing missing credentials. ```bash # Check files with default credential files detect-aws-credentials app.py main.py ``` ```bash # Use custom credentials file detect-aws-credentials --credentials-file ~/.aws/custom config.py ``` ```bash # Allow missing credentials (don't fail if no creds found) detect-aws-credentials --allow-missing-credentials app.py ``` ```bash # Multiple credential files detect-aws-credentials --credentials-file ~/.aws/credentials --credentials-file /etc/aws/creds.ini app.py ``` -------------------------------- ### Command-line Usage Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/debug_statement_hook.md Provides examples of how to use the debug-statement-hook from the command line to check single or multiple Python files. It also shows typical output when violations are detected. ```bash # Check single file debug-statement-hook app.py # Check multiple files debug-statement-hook app.py main.py utils.py # Typical output on violation: # app.py:5:0: pdb imported # app.py:12:4: breakpoint called ``` -------------------------------- ### Example: Fix all files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Demonstrates fixing all specified files using the trailing-whitespace-fixer hook. ```bash # Fix all files trailing-whitespace-fixer script.py README.md ``` -------------------------------- ### Example: Treat all files as Markdown Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Demonstrates using '*' with --markdown-linebreak-ext to treat all files as Markdown and preserve hard line breaks. ```bash # Treat all files as Markdown trailing-whitespace-fixer --markdown-linebreak-ext "*" document.txt ``` -------------------------------- ### Bash Example: sort-simple-yaml command-line usage Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/sort_simple_yaml.md Shows how to use the sort-simple-yaml hook from the command line to sort single or multiple YAML files. It also includes an example of how to configure it within a .pre-commit-config.yaml file. ```bash # Sort single file sort-simple-yaml config.yaml # Sort multiple files sort-simple-yaml config1.yaml config2.yaml # In pre-commit config (must specify files) - repo: https://github.com/pre-commit/pre-commit-hooks hooks: - id: sort-simple-yaml files: ^config/simple/ ``` -------------------------------- ### Python Example: first_key() usage Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/sort_simple_yaml.md Demonstrates extracting a sort key from a YAML block using the first_key() function. This example shows how comments are ignored and leading quotes are handled. ```python from pre_commit_hooks.sort_simple_yaml import first_key block = ["# comment", "'foo': true"] key = first_key(block) # Returns: "foo': true" (after stripping leading quote) ``` -------------------------------- ### Python Argument Parsing: Options Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of adding an option with a specified type and default value. ```python parser.add_argument('--maxkb', type=int, default=500) ``` -------------------------------- ### Debug Named Tuple Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/types.md Examples of Debug named tuples, showing an import statement and a breakpoint() call. ```python Debug(line=5, col=0, name='pdb', reason='imported') # import pdb Debug(line=10, col=4, name='breakpoint', reason='called') # breakpoint() ``` -------------------------------- ### Example: Multiple Markdown extensions Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Illustrates specifying multiple file extensions to be treated as Markdown for preserving hard line breaks. ```bash # Multiple Markdown extensions trailing-whitespace-fixer --markdown-linebreak-ext md,txt --markdown-linebreak-ext rst content.md ``` -------------------------------- ### File I/O: Read/Write Mode for In-place Fixes Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of opening a file in read/write binary mode to apply in-place fixes. ```python with open(filename, 'rb+') as f: contents = f.read() fixed = apply_fixes(contents) f.seek(0) f.write(fixed) f.truncate() ``` -------------------------------- ### Example Usage of fix_requirements Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/requirements_txt_fixer.md Demonstrates how to use the `fix_requirements` function by opening a 'requirements.txt' file in binary read/write mode and checking the result. ```python from pre_commit_hooks.requirements_txt_fixer import fix_requirements with open('requirements.txt', 'rb+') as f: result = fix_requirements(f) if result == 1: print('File was modified') ``` -------------------------------- ### Bash Example: Sort multiple files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Applies sorting to multiple specified files. ```bash file-contents-sorter allowlist.txt blocklist.txt rules.txt ``` -------------------------------- ### Example: Combine options Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Combines multiple options, including Markdown extension and custom characters, for flexible whitespace stripping. ```bash # Combine options trailing-whitespace-fixer --markdown-linebreak-ext md --chars " " docs.md script.py ``` -------------------------------- ### Python Argument Parsing: Standard Arguments Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of adding a standard argument for filenames to be processed. ```python parser.add_argument('filenames', nargs='*') # Files to process ``` -------------------------------- ### Command-line Usage Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/mixed_line_ending.md Demonstrates various command-line options for checking and fixing line endings, including different fix modes and file selections. ```bash # Check for mixed line endings (no changes) mixed-line-ending --fix no script.py # Auto-fix to most common line ending mixed-line-ending script.py # Force all files to Unix line endings mixed-line-ending --fix lf script.py main.py # Force Windows line endings mixed-line-ending --fix crlf windows-script.bat # Force old Mac line endings mixed-line-ending --fix cr legacy-file.txt ``` -------------------------------- ### Call Named Tuple Example Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/types.md An example of a Call named tuple, indicating a dict() call at a specific line and column. ```python Call(name='dict', line=5, column=8) # dict() call at line 5 ``` -------------------------------- ### Python Argument Parsing: Repeatable Arguments Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of adding an argument that can be specified multiple times. ```python parser.add_argument('--branch', action='append') ``` -------------------------------- ### Example Usage of check_file() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/debug_statement_hook.md Demonstrates how to use the `check_file` function to scan a Python script for debug statements and handle the result. ```python from pre_commit_hooks.debug_statement_hook import check_file result = check_file('script.py') if result: print("Debug statements found") ``` -------------------------------- ### Example: Custom characters to strip Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Shows how to specify custom characters (e.g., space and tab) to be stripped as trailing whitespace. ```bash # Custom characters to strip trailing-whitespace-fixer --chars " \t" script.py ``` -------------------------------- ### Bash Example: Sort file with default ordering Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Sorts a file using the default lexicographical ordering. ```bash file-contents-sorter allowlist.txt ``` -------------------------------- ### YAML Example: Pre-commit configuration for file-contents-sorter Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Shows how to integrate the file-contents-sorter hook into a pre-commit configuration file, specifying arguments and file patterns. ```yaml - repo: https://github.com/pre-commit/pre-commit-hooks hooks: - id: file-contents-sorter args: ['--ignore-case'] files: ^(allowlist|blocklist)\.txt$ ``` -------------------------------- ### Command-line Usage Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/requirements_txt_fixer.md Illustrates various ways to invoke the requirements-txt-fixer from the command line, including fixing a single file, multiple files, and checking for changes without modifying. ```bash # Sort single requirements file requirements-txt-fixer requirements.txt # Sort multiple files requirements-txt-fixer requirements.txt requirements-dev.txt constraints.txt # Check without modifying (return code indicates if changes needed) requirements-txt-fixer requirements.txt > /dev/null ``` -------------------------------- ### Example Output of Destroyed Symlinks Hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/destroyed_symlinks.md Illustrates the typical output when destroyed symlinks are detected, including remediation commands. ```text Destroyed symlinks: - docs/README - link_to_config.conf You should unstage affected files: git reset HEAD -- docs/README link_to_config.conf And retry commit. As a long term solution you may try to explicitly tell git that your environment does not support symlinks: git config core.symlinks false ``` -------------------------------- ### check-yaml Hook Command-Line Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_yaml.md Demonstrates various ways to use the check-yaml hook from the command line, including checking single-document, multi-document, and unsafe YAML files. ```bash # Check single-document YAML check-yaml config.yml ``` ```bash # Allow multiple documents check-yaml --multi kubernetes-manifests.yaml ``` ```bash # Use unsafe parsing (for YAML with extensions) check-yaml --unsafe extended-config.yaml ``` ```bash # Both flags check-yaml --unsafe --multi output.yaml ``` -------------------------------- ### Python Argument Parsing: Flags Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of adding a boolean flag argument. ```python parser.add_argument('--autofix', action='store_true') ``` -------------------------------- ### File I/O: Text Mode for Parsing Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of reading a file in text mode with UTF-8 encoding for parsing. ```python with open(filename, 'r', encoding='UTF-8') as f: lines = f.readlines() ``` -------------------------------- ### Example: Preserve Markdown hard breaks Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Shows how to use the --markdown-linebreak-ext option to preserve Markdown hard breaks for specific file extensions. ```bash # Preserve Markdown hard breaks trailing-whitespace-fixer --markdown-linebreak-ext md README.md ``` -------------------------------- ### Bash Example: Case-insensitive sort Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Sorts a file using case-insensitive ordering. ```bash file-contents-sorter --ignore-case list.txt ``` -------------------------------- ### Subprocess Integration: Calling Git Commands Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of using subprocess to call git commands and handle potential errors. ```python from pre_commit_hooks.util import cmd_output # Get staged files added = cmd_output('git', 'diff', '--staged', '--name-only') # Handle errors try: output = cmd_output('git', 'check-attr', ...) except CalledProcessError: handle_error() ``` -------------------------------- ### Examples of Detected Violations Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_builtin_literals.md Illustrates common Python code patterns that trigger violations in the check-builtin-literals hook. These examples show the use of builtin type constructors that should ideally be replaced with their literal equivalents. ```python # Each of these triggers a violation: x = dict() # Use {} instead y = list() # Use [] instead z = tuple() # Use () instead s = str() # Use '' instead f = float() # Use 0.0 instead i = int() # Use 0 instead c = complex() # Use 0j instead ``` -------------------------------- ### Example JSON Decode Error Message Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/errors.md Illustrates a typical error message for duplicate keys when decoding JSON. ```text Duplicate key: name ``` -------------------------------- ### Python Example Usage of is_on_branch() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md Demonstrates how to use the is_on_branch function to check for protection against specific branch names and regex patterns. ```python from pre_commit_hooks.no_commit_to_branch import is_on_branch # Check specific branches protected = frozenset(['main', 'develop']) if is_on_branch(protected): print("Cannot commit to protected branch") # With regex patterns protected = frozenset(['main', 'master']) patterns = frozenset(['release/.*', 'hotfix/.*']) if is_on_branch(protected, patterns): print("Branch is protected") ``` -------------------------------- ### Command-line Usage Examples Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_builtin_literals.md Demonstrates various ways to invoke the check-builtin-literals hook from the command line, including checking a single file, ignoring specific types, disallowing dict keyword arguments, and checking multiple files. ```bash # Check file (default allows dict with kwargs) check-builtin-literals script.py # Ignore list and dict check-builtin-literals --ignore list,dict script.py # Disallow dict(key=value) check-builtin-literals --no-allow-dict-kwargs script.py # Check multiple files check-builtin-literals app.py main.py utils.py ``` -------------------------------- ### Bash Example: Protect main and master (default) Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This command runs the no-commit-to-branch hook with default settings, protecting 'main' and 'master' branches. ```bash # Protect main and master (default) no-commit-to-branch ``` -------------------------------- ### Bash Example: Combine exact and pattern matching Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This command demonstrates how to use both exact branch names and regex patterns to define protected branches for the no-commit-to-branch hook. ```bash # Combine exact and pattern matching no-commit-to-branch \ --branch main \ --branch staging \ --pattern release/v.* \ --pattern hotfix/.* ``` -------------------------------- ### Python Examples for sort_file_contents Function Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Demonstrates various ways to use the `sort_file_contents` function, including standard sorting, case-insensitive sorting, and case-insensitive sorting with duplicate removal. ```python from pre_commit_hooks.file_contents_sorter import sort_file_contents # Standard sort with open('list.txt', 'rb+') as f: result = sort_file_contents(f, None) # Case-insensitive sort with open('list.txt', 'rb+') as f: result = sort_file_contents(f, bytes.lower) # Case-insensitive with deduplication with open('list.txt', 'rb+') as f: result = sort_file_contents(f, bytes.lower, unique=True) ``` -------------------------------- ### Bash Example: Protect specific branches Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This command configures the no-commit-to-branch hook to protect 'main' and 'develop' branches. ```bash # Protect specific branches no-commit-to-branch --branch main --branch develop ``` -------------------------------- ### File I/O: Binary Mode for Line Ending Detection Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Example of reading a file in binary mode to detect CRLF line endings. ```python with open(filename, 'rb') as f: contents = f.read() # Detect line endings if b'\r\n' in contents: print("CRLF line endings") ``` -------------------------------- ### YAML Example: Patterns in pre-commit configuration Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This YAML configuration sets up the no-commit-to-branch hook to protect branches matching specified regex patterns. ```yaml # With patterns - repo: https://github.com/pre-commit/pre-commit-hooks hooks: - id: no-commit-to-branch args: ['--pattern', 'release/.*', '--pattern', 'hotfix/.*'] ``` -------------------------------- ### YAML Example: Default pre-commit configuration Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This YAML configuration sets up the no-commit-to-branch hook with its default behavior, protecting 'main' and 'master' branches. ```yaml # Default (protect main and master) - repo: https://github.com/pre-commit/pre-commit-hooks hooks: - id: no-commit-to-branch ``` -------------------------------- ### Python Usage: find_large_added_files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_added_large_files.md Demonstrates how to use the find_large_added_files function. The first example checks files against a 500 KB limit, while the second enforces the limit on all files with a 1000 KB limit. ```python from pre_commit_hooks.check_added_large_files import find_large_added_files # Check files are under 500 KB (default) retval = find_large_added_files(['large_file.bin'], maxkb=500) # Enforce limit on all files, not just new ones retval = find_large_added_files(['file.iso'], maxkb=1000, enforce_all=True) ``` -------------------------------- ### Python Command Line Usage: main Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_added_large_files.md Demonstrates how to invoke the main function of the check-added-large-files hook programmatically from Python. This example calls main with a list of arguments simulating command-line input. ```python # From Python from pre_commit_hooks.check_added_large_files import main exit_code = main(['large_file.bin', '--maxkb', '1000']) ``` -------------------------------- ### Python Example: sort() usage Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/sort_simple_yaml.md Demonstrates how to use the sort() function with a list of YAML lines. The function sorts the keys alphabetically and maintains empty lines between sorted blocks. ```python from pre_commit_hooks.sort_simple_yaml import sort lines = ['z_key: 1', 'a_key: 2', 'b_key: 3'] result = sort(lines) # Returns: ['a_key: 2', '', 'b_key: 3', '', 'z_key: 1'] ``` -------------------------------- ### Execute Command and Get Output Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/util.md Executes a subprocess command and returns its standard output as a decoded string. Can optionally ignore the return code. ```python from pre_commit_hooks.util import cmd_output # Get git status output = cmd_output('git', 'status', '--porcelain') # Ignore return code output = cmd_output('git', 'merge-base', 'main', 'HEAD', retcode=None) ``` -------------------------------- ### Keep Specific Keys at Top Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md Use the --top-keys flag to ensure specific keys are always placed at the beginning of the JSON object. This example keeps 'name', 'version', and 'description' at the top. ```bash pretty-format-json --top-keys name,version,description package.json ``` -------------------------------- ### Configure JSON Formatting with Custom Indentation Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Customize the indentation level for pretty-printing JSON files. This example sets indentation to 4 spaces. ```yaml - id: pretty-format-json args: [--indent, " "] ``` -------------------------------- ### Markdown Hard Breaks Example Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/trailing_whitespace_fixer.md Illustrates Markdown's use of two trailing spaces for hard line breaks, which the hook preserves. ```markdown Line one Line two ``` -------------------------------- ### Example Debug Statement Patterns Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/debug_statement_hook.md Illustrates common patterns of debugger imports and breakpoint calls that the hook will detect. These include direct imports, from-imports, and breakpoint() calls. ```python import pdb # Detected from ipdb import set_trace # Detected breakpoint() # Detected (Python 3.7+) ``` -------------------------------- ### Detect AWS Credentials Example Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/configuration.md Use this hook to detect AWS credentials in specified files. You can provide custom credentials files using the `--credentials-file` option. ```bash detect-aws-credentials --credentials-file ~/.aws/creds.ini app.py ``` -------------------------------- ### Custom Indentation Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md Specify custom indentation levels for JSON files using the --indent flag. This example sets indentation to 4 spaces. ```bash pretty-format-json --indent 4 config.json ``` -------------------------------- ### YAML Example: Custom branches in pre-commit configuration Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This YAML configuration customizes the no-commit-to-branch hook to protect specific branches like 'main' and 'develop'. ```yaml # Custom branches - repo: https://github.com/pre-commit/pre-commit-hooks hooks: - id: no-commit-to-branch args: ['--branch', 'main', '--branch', 'develop'] ``` -------------------------------- ### Bash: Protect release branches using regex Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This command protects branches that start with 'release/' or match the pattern 'v[0-9]+.[0-9]+.*'. ```bash no-commit-to-branch --pattern 'release/.*' --pattern 'v[0-9]+\.[0-9]+.*' ``` -------------------------------- ### Bash Example: Protect branches matching patterns Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/no_commit_to_branch.md This command configures the no-commit-to-branch hook to protect branches whose names match the provided regex patterns. ```bash # Protect branches matching patterns no-commit-to-branch --pattern release/.* --pattern hotfix/.* ``` -------------------------------- ### Main Entry Point for Destroyed Symlinks Hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/destroyed_symlinks.md The main function for the destroyed-symlinks hook, which detects destroyed symlinks and guides users on remediation steps. ```python def main(argv: Sequence[str] | None = None) -> int: """ Detect destroyed symlinks and provide remediation steps. Args: argv: Command-line arguments Returns: Exit code: 0 = no destroyed symlinks, 1 = found """ ``` -------------------------------- ### Get Added Files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/util.md Retrieves the set of files staged for addition in git. Use this to identify newly added files in the current git commit. ```python from pre_commit_hooks.util import added_files files = added_files() # Returns: {'new_file.py', 'another_file.txt'} ``` -------------------------------- ### _get_pretty_format() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md Formats JSON content with consistent indentation and key ordering. It sorts keys alphabetically by default and can be configured to keep specific top-level keys at the start. ```APIDOC ## _get_pretty_format() ### Description Format JSON content with consistent indentation and key ordering. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method None (Python function) ### Endpoint None (Python function) ### Parameters - **contents** (str) - Required - JSON string to format - **indent** (str) - Required - Indentation (string like "2" or "\t") - **ensure_ascii** (bool) - Optional - Default: True - If True, escape non-ASCII characters - **sort_keys** (bool) - Optional - Default: True - If True, sort all keys alphabetically - **top_keys** (Sequence[str]) - Optional - Default: () - List of keys to keep at top of object ### Returns `str` - Formatted JSON string with trailing newline ### Raises `ValueError` - If JSON is malformed ### Example ```python from pre_commit_hooks.pretty_format_json import _get_pretty_format json_str = '{"z": 1, "a": 2}' formatted = _get_pretty_format(json_str, '2') # Result: '{ "a": 2, "z": 1 } ' # With top keys formatted = _get_pretty_format(json_str, '2', top_keys=['z']) # Result: '{ "z": 1, "a": 2 } ' ``` ``` -------------------------------- ### Sort File Contents Example Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/configuration.md This hook sorts lines within specified files. It supports case-insensitive sorting and ensures unique lines when the respective flags are used. ```bash file-contents-sorter --ignore-case --unique allowlist.txt ``` -------------------------------- ### main() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md The main entry point for the pretty-format-json hook. It formats JSON files or displays diffs based on command-line arguments. ```APIDOC ## main() ### Description Format JSON files or display diffs. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method None (Python function) ### Endpoint None (Python function) ### Command-line Arguments: - **filenames** (str, multiple) - Optional - JSON files to check/fix - **--autofix** (flag) - Optional - Default: False - Fix files in-place instead of showing diff - **--indent** (str | int) - Optional - Default: 2 - Indentation (number of spaces or string like "\t") - **--no-ensure-ascii** (flag) - Optional - Default: False - Preserve non-ASCII characters (don't escape) - **--no-sort-keys** (flag) - Optional - Default: False - Keep original key order instead of sorting - **--top-keys** (str) - Optional - Default: "" - Comma-separated keys to keep at top ### Returns `int` - Exit code: 0 = all files formatted correctly, 1 = fixes needed ### Output: - Without `--autofix`: Prints unified diff to stdout - With `--autofix`: Prints "Fixing file {filename}" to stdout - Errors: Prints error message and continues to next file ### Example: ```bash # Example usage (assuming the hook is configured in .pre-commit-config.yaml) # To check and show diffs: pre-commit run pretty-format-json --files path/to/your/file.json # To fix files in-place: pre-commit run pretty-format-json --files path/to/your/file.json -- --autofix # With custom indentation and top keys: pre-commit run pretty-format-json --files path/to/your/file.json -- --indent=4 --top-keys=name,version ``` ``` -------------------------------- ### Bash Command Line Usage: check-added-large-files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_added_large_files.md Provides examples of using the check-added-large-files hook from the command line. The first command checks a specific file with a custom maxkb, and the second checks multiple files with a different maxkb and enforces checking all files. ```bash # From command line check-added-large-files large_file.bin --maxkb 1000 check-added-large-files --maxkb 2000 --enforce-all file1.iso file2.iso ``` -------------------------------- ### main() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_added_large_files.md The main entry point for the check-added-large-files hook, responsible for parsing command-line arguments and initiating the file size check. ```APIDOC ## main() ### Description Entry point for the check-added-large-files hook. Parse arguments and check for large files. ### Method Signature `main(argv: Sequence[str] | None = None) -> int` ### Parameters #### Command-line Arguments - **filenames** (str, multiple) - Optional - Files to check - **--maxkb** (int) - Optional - Maximum file size in KB. Defaults to 500. - **--enforce-all** (flag) - Optional - Check all files, not just staged additions ### Returns `int` - Exit code: 0 = success, 1 = large files detected ### Output Prints violations to stdout in format: `filename (KB) exceeds maxkb KB.` ### Example ```bash # From command line check-added-large-files large_file.bin --maxkb 1000 check-added-large-files --maxkb 2000 --enforce-all file1.iso file2.iso # From Python from pre_commit_hooks.check_added_large_files import main exit_code = main(['large_file.bin', '--maxkb', '1000']) ``` ``` -------------------------------- ### Bash Example: Remove duplicates Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Sorts a file and removes duplicate lines, without case-insensitivity. ```bash file-contents-sorter --unique list.txt ``` -------------------------------- ### Command-line Usage of Destroyed Symlinks Hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/destroyed_symlinks.md Demonstrates how to run the destroyed-symlinks hook from the command line to check for issues. ```bash # Check for destroyed symlinks destroyed-symlinks README.md docs.txt # Typical output on Windows clone # destroyed-symlinks link_to_config.txt # Destroyed symlinks: # - link_to_config.txt # You should unstage affected files: # git reset HEAD -- link_to_config.txt ``` -------------------------------- ### main() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/sort_simple_yaml.md The main entry point for the sort-simple-yaml hook. It accepts command-line arguments specifying the YAML files to sort. It returns an exit code of 0 if the files were unchanged and 1 if they were sorted. The hook prints 'Fixing file {filename}' for each modified file. ```APIDOC ## main() ### Description Entry point for the sort-simple-yaml hook. ### Command-line Arguments: - `filenames` (str) - Optional - YAML files to sort ### Returns: `int` — 0 if files unchanged, 1 if files were sorted ### Output: Prints `Fixing file \`{filename}\`` for each modified file. ### Example: ```bash # Sort single file sort-simple-yaml config.yaml # Sort multiple files sort-simple-yaml config1.yaml config2.yaml # In pre-commit config (must specify files) - repo: https://github.com/pre-commit/pre-commit-hooks hooks: - id: sort-simple-yaml files: ^config/simple/ ``` ``` -------------------------------- ### Configure check-yaml hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Attempts to load all YAML files to verify syntax. Use `--allow-multiple-documents` for multi-document files or `--unsafe` for syntax-only checks. ```yaml - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - id: check-yaml args: ['--unsafe'] ``` -------------------------------- ### main() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/mixed_line_ending.md The entry point for the mixed-line-ending hook, designed to be called from the command line. It processes multiple files, applying specified fix modes or simply checking for mixed line endings. ```APIDOC ## main() ### Description Entry point for the mixed-line-ending hook. Check and fix mixed line endings across multiple files. ### Command-line Arguments - **filenames** (str, multiple) - Optional - Files to check/fix - **-f, --fix** (str) - Optional - Fix mode: auto, no, lf, crlf, cr (default: auto) ### Returns - **int** - 1 if any file has mixed endings (or was fixed), 0 if all clean ### Output - With `--fix no`: Prints `{filename}: mixed line endings` - With other modes: Prints `{filename}: fixed mixed line endings` ### Example ```bash # Check for mixed line endings (no changes) mixed-line-ending --fix no script.py # Auto-fix to most common line ending mixed-line-ending script.py # Force all files to Unix line endings mixed-line-ending --fix lf script.py main.py # Force Windows line endings mixed-line-ending --fix crlf windows-script.bat # Force old Mac line endings mixed-line-ending --fix cr legacy-file.txt ``` ``` -------------------------------- ### Main Entry Point for pretty-format-json Hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md The main function orchestrates the JSON formatting process, handling file arguments, autofixing, and various formatting options. It returns an exit code indicating success or the need for fixes. ```python def main(argv: Sequence[str] | None = None) -> int: """ Format JSON files or display diffs. Args: argv: Command-line arguments Returns: Exit code: 0 = all files formatted correctly, 1 = fixes needed """ ``` -------------------------------- ### Configure pre-commit-hooks in .pre-commit-config.yaml Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Add this configuration to your .pre-commit-config.yaml file to integrate pre-commit-hooks into your workflow. Specify the repository and the desired revision. ```yaml - 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: ... ``` -------------------------------- ### Parse Top-Level Keys Argument Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md Splits a comma-separated string into a list of strings, representing top-level keys to be preserved at the start of JSON objects during formatting. ```python def parse_topkeys(s: str) -> list[str]: """Split comma-separated string into list of keys.""" ``` -------------------------------- ### Configure JSON Pretty Formatting Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Automatically format JSON files to ensure consistent indentation and sorted keys. Use --autofix to enable automatic formatting. ```yaml - id: pretty-format-json args: [--autofix] ``` -------------------------------- ### Bash Example: File modified exit code Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Demonstrates the exit code when the file-contents-sorter modifies a file. An exit code of 1 indicates changes were made. ```bash # File modified $ file-contents-sorter list.txt Sorting list.txt $ echo $? ``` -------------------------------- ### Format JSON Files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/pretty_format_json.md Basic usage to format specified JSON files. This command checks and displays diffs for the files. ```bash pretty-format-json config.json package.json ``` -------------------------------- ### Python Usage: filter_lfs_files Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_added_large_files.md Shows how to use the filter_lfs_files function to remove git-lfs tracked files from a set. The example modifies a set containing both LFS and non-LFS files. ```python from pre_commit_hooks.check_added_large_files import filter_lfs_files files = {'large_model.safetensors', 'code.py'} filter_lfs_files(files) # files now contains only non-lfs files ``` -------------------------------- ### Testing Directory Structure Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md Illustrates the organization of test-related files within the project's testing directory. This structure includes fixtures, resources, and test modules. ```text testing/ ├── fixtures/ # Test data files ├── resources/ # Test resources └── test_*.py # Test modules ``` -------------------------------- ### Main Entry Point for requirements-txt-fixer Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/requirements_txt_fixer.md The main function serves as the entry point for the hook, processing command-line arguments to fix multiple requirement files. It returns a status code indicating overall modification. ```python def main(argv: Sequence[str] | None = None) -> int: """ Sort and deduplicate requirement files. Args: argv: Command-line arguments Returns: 0 if all files unchanged, 1 if any file was modified """ ``` -------------------------------- ### Bash Example: No changes exit code Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/file_contents_sorter.md Demonstrates the exit code when the file-contents-sorter makes no changes to a file. An exit code of 0 indicates the file was already sorted. ```bash # No changes needed $ file-contents-sorter list.txt $ echo $? ``` -------------------------------- ### Command-line Usage Pattern for Hooks Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/OVERVIEW.md All hooks in the pre-commit-hooks library follow a consistent command-line pattern. Exit codes indicate success (0), failure (1), or configuration errors (2). ```bash # All hooks follow this pattern {hook-name} [OPTIONS] [FILENAMES] # Exit codes # 0 = success (file is valid/no changes needed) # 1 = failure (file invalid or changes made) # 2 = error (configuration error, not used by most hooks) ``` -------------------------------- ### main() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/debug_statement_hook.md The entry point for the debug-statements hook, which checks multiple Python files for debug statements. It accepts a list of filenames and returns an exit code indicating the overall result. ```APIDOC ## main(argv: Sequence[str] | None = None) -> int ### Description Check Python files for debug statements. ### Parameters #### Path Parameters - **filenames** (str) - Optional - Python files to check (can be multiple) ### Returns `int` — 0 if all files clean, 1 if any file has debug statements ### Output: Prints location and name of each debug statement ### Command-line Arguments: #### filenames - Type: str (multiple) - Required: No - Default: — - Description: Python files to check ### Example: ```bash # Check single file debug-statement-hook app.py # Check multiple files debug-statement-hook app.py main.py utils.py # Typical output on violation: # app.py:5:0: pdb imported # app.py:12:4: breakpoint called ``` ``` -------------------------------- ### Configure Requirements TXT Fixer Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Automatically sorts entries in requirements.txt and constraints.txt files and removes the incorrect entry for pkg-resources. ```yaml - id: requirements-txt-fixer ``` -------------------------------- ### Python Hook Entry Point Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_builtin_literals.md The main function serves as the entry point for the check-builtin-literals hook. It accepts command-line arguments to specify files to check and options for ignoring types or controlling dict keyword argument usage. ```python def main(argv: Sequence[str] | None = None) -> int: """ Check Python files for builtin type constructor usage. Args: argv: Command-line arguments Returns: Exit code: 0 = no violations, 1 = violations found """ ``` -------------------------------- ### Get AWS Secrets from Environment Variables Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/detect_aws_credentials.md Extracts AWS secret access keys and security tokens from environment variables such as AWS_SECRET_ACCESS_KEY. Returns a set of secret values. ```python def get_aws_secrets_from_env() -> set[str]: """ Get AWS secrets from environment variables. Checks: AWS_SECRET_ACCESS_KEY, AWS_SECURITY_TOKEN, AWS_SESSION_TOKEN Returns: Set of secret values found in environment """ ``` ```python from pre_commit_hooks.detect_aws_credentials import get_aws_secrets_from_env secrets = get_aws_secrets_from_env() ``` -------------------------------- ### Python Function: main() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/sort_simple_yaml.md The entry point for the sort-simple-yaml hook. It sorts simple YAML files and returns an exit code indicating whether changes were made. Use this as the main execution function for the hook. ```python def main(argv: Sequence[str] | None = None) -> int: """ Sort simple YAML files. Args: argv: Command-line arguments Returns: Exit code: 0 = unchanged, 1 = sorted """ ``` -------------------------------- ### File Structure of pre-commit-hooks Documentation Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/00-START-HERE.md This code block displays the directory structure for the pre-commit-hooks documentation, indicating the location of various reference files. ```markdown output/ ├── 00-START-HERE.md ← You are here ├── README.md ← Overview of documentation ├── INDEX.md ← Navigation guide ├── OVERVIEW.md ← Architecture & patterns ├── configuration.md ← All CLI options ├── types.md ← Data structures ├── errors.md ← Exit codes & errors └── api-reference/ ├── util.md ├── check_added_large_files.md ├── check_builtin_literals.md ├── check_yaml.md ├── debug_statement_hook.md ├── destroyed_symlinks.md ├── detect_aws_credentials.md ├── file_contents_sorter.md ├── mixed_line_ending.md ├── no_commit_to_branch.md ├── pretty_format_json.md ├── requirements_txt_fixer.md ├── sort_simple_yaml.md └── trailing_whitespace_fixer.md ``` -------------------------------- ### added_files() Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/util.md Get the set of files staged for addition in git. This function retrieves all files that are staged for addition using `git diff --staged --name-only --diff-filter=A`. ```APIDOC ## added_files() ### Description Get the set of files staged for addition in git. ### Returns `set[str]` — Set of filenames staged for addition. ### Example ```python from pre_commit_hooks.util import added_files files = added_files() # Returns: {'new_file.py', 'another_file.txt'} ``` ``` -------------------------------- ### Handling Subprocess Errors in Python Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/errors.md Demonstrates how to catch and handle `CalledProcessError` when a subprocess command fails. ```python from pre_commit_hooks.util import CalledProcessError, cmd_output try: output = cmd_output('git', 'status') except CalledProcessError as e: print(f"Command failed: {e}") ``` -------------------------------- ### Get AWS Credential File Paths from Environment Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/detect_aws_credentials.md Extracts AWS credential file paths by checking common environment variables like AWS_CONFIG_FILE and BOTO_CONFIG. Returns a set of file paths. ```python def get_aws_cred_files_from_env() -> set[str]: """ Get AWS credential file paths from environment variables. Checks: AWS_CONFIG_FILE, AWS_CREDENTIAL_FILE, AWS_SHARED_CREDENTIALS_FILE, BOTO_CONFIG Returns: Set of credential file paths from environment """ ``` ```python from pre_commit_hooks.detect_aws_credentials import get_aws_cred_files_from_env files = get_aws_cred_files_from_env() # Returns: {'/home/user/.aws/credentials', ...} ``` -------------------------------- ### Main Function for Hook Execution Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/mixed_line_ending.md Entry point for the mixed-line-ending hook, processing multiple files. Returns 1 if any file has mixed endings or was fixed, 0 otherwise. ```python def main(argv: Sequence[str] | None = None) -> int: """ Check and fix mixed line endings across multiple files. Args: argv: Command-line arguments Returns: 1 if any file has mixed endings (or was fixed), 0 otherwise """ ``` -------------------------------- ### Get AWS Secrets from Credentials File Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/detect_aws_credentials.md Extracts AWS secret values from a specified INI-style credentials file, supporting tilde expansion for paths. It handles missing files and malformed INI content gracefully. ```python def get_aws_secrets_from_file(credentials_file: str) -> set[str]: """ Extract AWS secrets from AWS CLI configuration file. Reads ini-style file and extracts secret keys from sections. Args: credentials_file: Path to credentials file (supports ~ expansion) Returns: Set of AWS secret values found in file """ ``` ```python from pre_commit_hooks.detect_aws_credentials import get_aws_secrets_from_file secrets = get_aws_secrets_from_file('~/.aws/credentials') ``` -------------------------------- ### Requirement Class Properties and Methods Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/types.md Defines the 'name' property, '__lt__' comparison method, and 'is_complete' method for the Requirement class. ```python @property def name(self) -> bytes: """Normalized package name for sorting.""" def __lt__(self, requirement: Requirement) -> bool: """Comparison for sorting requirements.""" def is_complete() -> bool: """Check if requirement is fully parsed (no line continuation).""" ``` -------------------------------- ### main() Function for check-yaml Hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/check_yaml.md The entry point for the check-yaml hook, responsible for validating YAML syntax in provided files. It returns an exit code indicating success or failure. ```python def main(argv: Sequence[str] | None = None) -> int: """ Validate YAML syntax in files. Args: argv: Command-line arguments Returns: Exit code: 0 = valid YAML, 1 = parse error """ ``` -------------------------------- ### detect-private-key Error Format Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/errors.md This format indicates the detection of private keys within files. The detect-private-key hook uses this to alert users about sensitive key material, listing the filename where a private key was found. ```text Private key found: {filename} ``` ```text Private key found: ~/.ssh/id_rsa ``` ```text Private key found: config/pem/cert.pem ``` -------------------------------- ### Pretty Format JSON Error Output (Diff) Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/errors.md Shows the diff output when JSON files need formatting. ```diff --- {filename} +++ {filename} @@ -1,3 +1,3 @@ { - "z": 1, "a": 2, + "z": 1, } ``` -------------------------------- ### Configure check-builtin-literals hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Require literal syntax for initializing empty or zero Python builtin types. Ignore specific types with `--ignore` or forbid dict keyword syntax with `--no-allow-dict-kwargs`. ```yaml - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - id: check-builtin-literals args: ['--ignore=dict,list'] ``` -------------------------------- ### Using Exit Codes in Python Scripts Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/errors.md Demonstrates how to check the exit code returned by a pre-commit hook's main function in Python. ```python from pre_commit_hooks.check_added_large_files import main exit_code = main(['large_file.bin', '--maxkb', '500']) if exit_code == 0: print("File is within size limit") elif exit_code == 1: print("File exceeds size limit") ``` -------------------------------- ### Configure Simple YAML Sorting Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Sorts simple YAML files consisting only of top-level keys. Comments and blocks are preserved. You must specify files to opt-in. ```yaml - id: sort-simple-yaml files: ^config/simple/ ``` -------------------------------- ### Pretty Format JSON Error Output (Autofix) Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/errors.md Indicates that a JSON file is being fixed. ```text Fixing file {filename} ``` -------------------------------- ### Main Entry Point for Debug-Statements Hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/_autodocs/api-reference/debug_statement_hook.md The main function serves as the entry point for the debug-statements hook. It processes command-line arguments to check specified Python files for debug statements. ```python def main(argv: Sequence[str] | None = None) -> int: """ Check Python files for debug statements. Args: argv: Command-line arguments Returns: Exit code: 0 = no debug statements, 1 = violations found """ ``` -------------------------------- ### Configure detect-aws-credentials hook Source: https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md Checks for the existence of AWS secrets. Use `--credentials-file` for additional configuration files or `--allow-missing-credentials` to let the hook pass when no credentials are detected. ```yaml - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - id: detect-aws-credentials args: ['--allow-missing-credentials'] ```