* ci: shift-left quality gates — add mypy to pre-commit, fix CI failures - Add mypy pre-commit hook (mirrors-mypy v1.13.0) so type checks run locally - Add [tool.mypy] config to scripts/pyproject.toml with overrides for untyped libs (ebooklib, sync_translations) - Add mypy>=1.8.0 to requirements-dev.txt - Fix CI test.yml: remove continue-on-error: true from lint/security/type-check jobs (was silently swallowing failures) - Fix CI bandit -c path: pyproject.toml → scripts/pyproject.toml - Fix CI mypy command: use --config-file scripts/pyproject.toml - Fix CI build-epub: add type-check to needs, fix if: success() → !failure() && !cancelled() - Fix ruff errors in sync_translations.py (RUF013 implicit Optional, SIM102 nested if) - Fix mypy errors: add list[str] annotations to errors vars in check_cross_references.py and check_links.py * fix(ci): install mmdc in build-epub job and correct return type annotation - Add npm install step for @mermaid-js/mermaid-cli before Build EPUB to fix CI failure (mmdc not found error) - Fix check_translation_status() return type from list[dict] to tuple[list[dict], list[dict]] to match the actual return value * fix(ci): pass --no-sandbox to Puppeteer in build-epub CI job mmdc (Mermaid CLI) uses Puppeteer/Chromium which requires --no-sandbox in the GitHub Actions sandboxed environment. Add --puppeteer-config flag to build_epub.py that passes a Puppeteer JSON config file to mmdc via -p, and use it in the CI workflow to inject the no-sandbox args.
145 lines
4.1 KiB
YAML
145 lines
4.1 KiB
YAML
# Pre-commit hooks for claude-howto project
|
|
# Run `pre-commit install` to set up hooks
|
|
# Run `pre-commit run --all-files` to check all files
|
|
|
|
default_language_version:
|
|
python: python3.11
|
|
|
|
repos:
|
|
# Ruff - Fast Python linter and formatter
|
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
rev: v0.8.2
|
|
hooks:
|
|
- id: ruff
|
|
name: ruff-lint
|
|
args: [--fix, --exit-non-zero-on-fix]
|
|
types_or: [python, pyi]
|
|
files: ^scripts/
|
|
- id: ruff-format
|
|
name: ruff-format
|
|
types_or: [python, pyi]
|
|
files: ^scripts/
|
|
|
|
# Bandit - Security linter
|
|
- repo: https://github.com/PyCQA/bandit
|
|
rev: 1.7.10
|
|
hooks:
|
|
- id: bandit
|
|
name: bandit-security
|
|
args: [-c, scripts/pyproject.toml]
|
|
additional_dependencies: ["bandit[toml]"]
|
|
types: [python]
|
|
files: ^scripts/
|
|
exclude: ^scripts/tests/
|
|
|
|
# Standard pre-commit hooks
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
rev: v5.0.0
|
|
hooks:
|
|
- id: check-yaml
|
|
name: check-yaml
|
|
args: [--allow-multiple-documents]
|
|
- id: check-toml
|
|
name: check-toml
|
|
- id: end-of-file-fixer
|
|
name: fix-end-of-file
|
|
- id: trailing-whitespace
|
|
name: fix-trailing-whitespace
|
|
- id: check-added-large-files
|
|
name: check-large-files
|
|
args: [--maxkb=1000]
|
|
- id: check-merge-conflict
|
|
name: check-merge-conflict
|
|
|
|
# mypy - Type checking
|
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
rev: v1.13.0
|
|
hooks:
|
|
- id: mypy
|
|
name: mypy-type-check
|
|
args: [--config-file, scripts/pyproject.toml]
|
|
files: ^scripts/
|
|
exclude: ^scripts/tests/
|
|
|
|
# Local doc quality hooks (mirrors CI checks — CI is a 2nd pass of these)
|
|
- repo: local
|
|
hooks:
|
|
- id: markdown-lint
|
|
name: markdown-lint
|
|
language: node
|
|
entry: markdownlint
|
|
args: ['--ignore', 'node_modules', '--ignore', '.venv', '--config', '.markdownlint.json']
|
|
types: [markdown]
|
|
additional_dependencies: ['markdownlint-cli']
|
|
|
|
- id: cross-references
|
|
name: cross-references
|
|
language: system
|
|
entry: python scripts/check_cross_references.py
|
|
pass_filenames: false
|
|
types: [markdown]
|
|
|
|
- id: mermaid
|
|
name: mermaid-syntax
|
|
language: system
|
|
entry: python scripts/check_mermaid.py
|
|
pass_filenames: false
|
|
types: [markdown]
|
|
verbose: true
|
|
|
|
- id: link-check
|
|
name: link-check
|
|
language: system
|
|
entry: python scripts/check_links.py
|
|
pass_filenames: false
|
|
types: [markdown]
|
|
verbose: true
|
|
|
|
- id: build-epub
|
|
name: build-epub
|
|
language: system
|
|
entry: uv run scripts/build_epub.py
|
|
pass_filenames: false
|
|
files: ^(.*\.md|scripts/build_epub\.py)$
|
|
|
|
# Vietnamese documentation checks
|
|
- repo: local
|
|
hooks:
|
|
- id: vietnamese-markdown-lint
|
|
name: vietnamese-markdown-lint
|
|
language: node
|
|
entry: markdownlint
|
|
args: ['--ignore', 'node_modules', '--ignore', '.venv', '--config', '.markdownlint.json']
|
|
files: ^vi/.*\.md$
|
|
additional_dependencies: ['markdownlint-cli']
|
|
|
|
- id: vietnamese-cross-references
|
|
name: vietnamese-cross-references
|
|
language: system
|
|
entry: python scripts/check_cross_references.py --lang vi
|
|
pass_filenames: false
|
|
files: ^vi/.*\.md$
|
|
|
|
- id: vietnamese-mermaid
|
|
name: vietnamese-mermaid-syntax
|
|
language: system
|
|
entry: python scripts/check_mermaid.py
|
|
pass_filenames: false
|
|
files: ^vi/.*\.md$
|
|
verbose: true
|
|
|
|
- id: vietnamese-link-check
|
|
name: vietnamese-link-check
|
|
language: system
|
|
entry: python scripts/check_links.py
|
|
pass_filenames: false
|
|
files: ^vi/.*\.md$
|
|
verbose: true
|
|
|
|
- id: vietnamese-build-epub
|
|
name: vietnamese-build-epub
|
|
language: system
|
|
entry: uv run scripts/build_epub.py --lang vi
|
|
pass_filenames: false
|
|
files: ^(vi/.*\.md|scripts/build_epub\.py)$
|