# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

# Baseline hooks and config updated 2024-09-25
# Web hooks and config updated 2024-09-25
# Docs hooks and config updated 2024-09-25
# Python hooks and config updated 2024-09-25

minimum_pre_commit_version: '2.10.0'

default_language_version:
  python: python3

default_stages: [commit]

exclude: '\.(min\.(js|css)|pot?)$'


repos:
# Meta checks
- repo: meta
  hooks:
  - id: check-useless-excludes

# General fixers
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
  - id: trailing-whitespace
    name: Trim trailing whitespace
    exclude_types: [svg]
  - id: mixed-line-ending
    name: Normalize mixed line endings
    args: [--fix=lf]
    exclude_types: [batch]
  - id: end-of-file-fixer
    name: Fix end of files
    exclude_types: [svg]
  - id: fix-byte-order-marker
    name: Remove Unicode BOM

# More general fixers
- repo: https://github.com/Lucas-C/pre-commit-hooks
  rev: v1.5.1  # Pinned for now to avoid requiring pre-commit >=3.2.0
  hooks:
  - id: remove-tabs
    name: Replace tabs with spaces
    types: [text]
    exclude_types: [svg, batch]
    args: [--whitespaces-count, '2']

# Check and fix spelling
- repo: https://github.com/codespell-project/codespell
  rev: v2.3.0
  hooks:
  # Define separate hooks for checking and correcting spelling errors
  # since codespell doesn't print verbose output when writing changes
  - id: codespell
    name: Check spelling
    exclude: '\.gitattributes|\bworkshops\b'
  - id: codespell
    name: Fix spelling
    exclude: '\.gitattributes|\bworkshops\b'
    args: [--write-changes]

# Lint and fix CSS with stylelint
- repo: https://github.com/thibaudcolas/pre-commit-stylelint
  rev: v16.9.0
  hooks:
  - id: stylelint
    name: Lint and fix CSS (stylelint)
    args: [--fix, --color, --maxWarnings, '0']
    additional_dependencies:
    - 'stylelint@16.9.0'
    - 'stylelint-config-standard@36.0.1'
    - 'stylelint-declaration-block-no-ignored-properties@2.8.0'
    - 'stylelint-no-unsupported-browser-features@8.0.1'
    - 'stylelint-order@6.0.4'
    # Use fork of csstree-validator that supports Stylelint 16 for now
    - '@carlosjeurissen/stylelint-csstree-validator@3.1.0'
    # Pin to avoid no-unsupported-browser-features error breaking stylelint
    # Should be fixed soon; see
    # https://github.com/RJWadley/stylelint-no-unsupported-browser-features/issues/299
    - 'caniuse-lite@1.0.30001653'

# Format CSS with Prettier
- repo: https://github.com/rbubley/mirrors-prettier
  rev: v3.3.3
  hooks:
  - id: prettier
    name: Format CSS (Prettier)
    types: [css]

# Pretty-format INI
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
  rev: v2.14.0
  hooks:
  - id: pretty-format-ini
    name: Format INI
    types: [ini]
    args: [--autofix]

# Lint and fix JavaScript
- repo: https://github.com/eslint/eslint
  rev: v9.9.0  # Pin to fix dep conflict on install; see eslint/eslint#18956
  hooks:
  - id: eslint
    name: Lint and fix JavaScript (ESLint)
    args: [--fix, --color, --max-warnings, '0']
    additional_dependencies:
    - 'eslint-plugin-import@2.30.0'
    - 'eslint-plugin-n@17.10.3'
    - 'eslint-plugin-promise@7.1.0'
    - 'neostandard@0.11.6'
    exclude: 'doc/_static/js/language-switcher.js'

# Format JavaScript with Prettier
- repo: https://github.com/rbubley/mirrors-prettier
  rev: v3.3.3
  hooks:
  - id: prettier
    name: Format JavaScript (Prettier)
    types: [javascript]
    exclude: 'doc/_static/js/language-switcher.js'

# Check JSON
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
  - id: check-json
    name: Check JSON

# Add doctoc to Markdown
- repo: https://github.com/thlorenz/doctoc
  rev: v2.2.0
  hooks:
  - id: doctoc
    name: Generate Markdown ToCs
    args: [--maxlevel, '3', --update-only]

# Lint Markdown
- repo: https://github.com/DavidAnson/markdownlint-cli2
  rev: v0.14.0
  hooks:
  - id: markdownlint-cli2
    name: Lint Markdown
    args: [--fix]

# Format Python
- repo: https://github.com/psf/black-pre-commit-mirror
  rev: '24.8.0'
  hooks:
  - id: black
    name: Format Python with Black
    args: ['--config', '.black.toml']
    exclude: '\bworkshops\b'

# Check Python
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
  - id: check-ast
    name: Check Python AST

# Lint Python
- repo: https://github.com/pycqa/flake8
  rev: '7.1.1'
  hooks:
  - id: flake8
    name: Lint Python with Flake8
    exclude: '\bworkshops\b'

- repo: https://github.com/pycqa/pylint
  rev: v3.3.1
  hooks:
  - id: pylint
    name: Lint Python with Pylint
    exclude: '\bworkshops\b'

# Check Python dependencies
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
  rev: v1.3.3
  hooks:
  - id: python-safety-dependencies-check
    name: Check Python dependencies (Safety)
    args: [--disable-optional-telemetry]
    files: '.*requirements.*.txt'
    types: [text]

# Check RST
- repo: https://github.com/pre-commit/pygrep-hooks
  rev: v1.10.0
  hooks:
  - id: rst-backticks
    name: Check RST backticks
  - id: rst-directive-colons
    name: Check RST directive colons
  - id: rst-inline-touching-normal
    name: Check RST inline touching normal

# Lint RST
- repo: https://github.com/sphinx-contrib/sphinx-lint
  rev: v1.0.0
  hooks:
  - id: sphinx-lint
    name: Lint RST
    args: [--enable, all, --disable, line-too-long]

# Check TOML and XML
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
  - id: check-toml
    name: Check TOML
  - id: check-xml
    name: Check XML

# Pretty-format YAML
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
  rev: v2.14.0
  hooks:
  - id: pretty-format-yaml
    name: Format YAML
    exclude: '\bworkshops\b|crowdin.ya?ml'
    args: [--autofix, --indent, '2', --preserve-quotes]

# Check YAML
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
  - id: check-yaml
    name: Check YAML

# Lint YAML
- repo: https://github.com/adrienverge/yamllint.git
  rev: v1.35.1
  hooks:
  - id: yamllint
    name: Lint YAML
    types: [yaml]
    args: [--strict, --format, colored]

# Replace CRLF with LF post-prettify
- repo: https://github.com/Lucas-C/pre-commit-hooks
  rev: v1.5.1  # Pinned for now to avoid requiring pre-commit >=3.2.0
  hooks:
  - id: remove-crlf
    name: Replace CRLFs with LF
    types: [text]
    exclude_types: [batch, svg]


# General checkers

- repo: https://github.com/pre-commit/pygrep-hooks
  rev: v1.10.0
  hooks:
  - id: text-unicode-replacement-char
    name: Check for Unicode replacement chars

- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
  - id: check-added-large-files
    name: Check for added large files
    args: [--maxkb=1025]
  - id: check-case-conflict
    name: Check for case conflicts
  - id: check-executables-have-shebangs
    name: Check that executables have shebangs
    exclude: 'pre\-commit\-config\.yaml'
  - id: check-shebang-scripts-are-executable
    name: Check that shebangs are executable
    exclude: 'pre\-commit\-config\.yaml'
  - id: check-merge-conflict
    name: Check for merge conflicts


# Commit message hooks #

# Check that commit message follows basic rules
- repo: https://github.com/jorisroovers/gitlint
  rev: v0.19.1
  hooks:
  - id: gitlint
    name: Check commit message

# Check commit message spelling
- repo: https://github.com/codespell-project/codespell
  rev: v2.3.0
  hooks:
  - id: codespell
    name: Check commit message spelling
    stages: [commit-msg]
