ci:
  autofix_commit_msg: "chore: pre-commit fixes"
  autofix_prs: false
  autoupdate_schedule: 'monthly'

exclude: "^cextern"

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.0.0
    hooks:
      - id: check-added-large-files
        args: ["--enforce-all", "--maxkb=300"]
        exclude: "^(\
            cextern/expat/lib/xmlparse.c|\
            cextern/wcslib/C/flexed/.*|\
            CHANGES.rst|\
        )$"
        # Prevent giant files from being committed.
      - id: check-case-conflict
        # Check for files with names that would conflict on a case-insensitive
        # filesystem like MacOS HFS+ or Windows FAT.
      - id: check-json
        # Attempts to load all json files to verify syntax.
      - id: check-merge-conflict
        # Check for files that contain merge conflict strings.
      - id: check-symlinks
        # Checks for symlinks which do not point to anything.
      - id: check-toml
        # Attempts to load all TOML files to verify syntax.
      - id: check-xml
        # Attempts to load all xml files to verify syntax.
      - id: check-yaml
        # Attempts to load all yaml files to verify syntax.
        exclude: ".*(.github.*)$"
      - id: detect-private-key
        # Checks for the existence of private keys.
      - id: end-of-file-fixer
        # Makes sure files end in a newline and only a newline.
        exclude: ".*(data.*|extern.*|licenses.*|_static.*|_parsetab.py)$"
      # - id: fix-encoding-pragma  # covered by pyupgrade
      - id: trailing-whitespace
        # Trims trailing whitespace.
        exclude_types: [python]  # Covered by Ruff W291.
        exclude: ".*(data.*|extern.*|licenses.*|_static.*)$"

  - repo: https://github.com/pre-commit/pygrep-hooks
    rev: v1.10.0
    hooks:
      - id: rst-directive-colons
        # Detect mistake of rst directive not ending with double colon.
      - id: rst-inline-touching-normal
        # Detect mistake of inline code touching normal text in rst.
      - id: text-unicode-replacement-char
        # Forbid files which have a UTF-8 Unicode replacement character.

  - repo: https://github.com/zizmorcore/zizmor-pre-commit
    rev: v1.24.1
    hooks:
    - id: zizmor

  - repo: https://github.com/codespell-project/codespell
    rev: v2.4.2
    hooks:
      - id: codespell
        args: ["--write-changes"]
        additional_dependencies:
          - tomli

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.15.12
    hooks:
      - id: ruff-check
        args: ["--fix", "--show-fixes"]
      - id: ruff-format

  - repo: https://github.com/scientific-python/cookie
    rev: 2026.04.04
    hooks:
      - id: sp-repo-review

  - repo: local
    hooks:
      - id: changelogs-rst
        name: changelog filenames
        language: fail
        entry: >-
          changelog files must be named <sub-package>/####.(bugfix|feature|api|perf).rst
          or ####.other.rst (in the root directory only)
        exclude: >-
          ^docs/changes/[\w\.]+/(\d+\.(bugfix|feature|api|perf)(\.\d)?.rst|.gitkeep)
        files: ^docs/changes/[\w\.]+/
      - id: changelogs-rst-other
        name: changelog filenames for other category
        language: fail
        entry: >-
          only "other" changelog files must be placed in the root directory
        exclude: >-
          ^docs/changes/(\d+\.other.rst|README.rst|template.rst)
        files: ^docs/changes/\d+.\w+.rst

  # Linting hook for stylistic issues in rst doc files.
  - repo: https://github.com/sphinx-contrib/sphinx-lint
    rev: v1.0.2
    hooks:
      - id: sphinx-lint
        exclude: "(licenses/|docs/_build/|.*parsetab.py|astropy/extern/)"

  - repo: https://github.com/pre-commit/mirrors-clang-format
    rev: 'v22.1.4'
    hooks:
      - id: clang-format
        files: \.(c|h)$
