Files
cs249r_book/.pre-commit-config.yaml
Vijay Janapa Reddi e05403460e Add comprehensive external image validation for pre-commit hooks
- Add validate_image_references.py to check all image references exist on disk
- Fix download_external_images.py to update markdown even when images already exist
- Add two pre-commit hooks: external image validation and missing image detection
- Download external images and update references to local paths
- Add documentation for pre-commit external image validation workflow
- Ensure build reliability by preventing external dependencies and missing images
2025-07-31 16:22:35 -04:00

175 lines
5.7 KiB
YAML

ci:
skip: true
repos:
# --- Spellchecking and Linting ---
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
name: "Check for common misspellings"
args: ["--ignore-words", "config/linting/.codespell-ignore"]
files: \.qmd$
exclude: ".venv|_book|_site|node_modules|images"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
name: "Validate _quarto.yml"
files: ^_quarto\.yml$
- id: trailing-whitespace
name: "Trim trailing whitespace"
files: ^book/contents/.*\.qmd$
verbose: false
- id: end-of-file-fixer
name: "Fix end of file newlines"
files: ^book/contents/.*\.qmd$
verbose: false
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.45.0
hooks:
- id: markdownlint
name: "Lint quarto markdown"
types: [text]
files: ^book/contents/.*\.qmd$
args: ["--quiet", "-c", "config/linting/.mdlintconfig.yml"]
entry: bash -c 'markdownlint "$@" || true'
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.9
hooks:
- id: mdformat
name: "Format quarto markdown"
additional_dependencies: [mdformat-frontmatter]
files: ^book/contents/.*\.qmd$
pass_filenames: true
# --- Bibliography ---
- repo: https://github.com/FlamingTempura/bibtex-tidy
rev: v1.14.0
hooks:
- id: bibtex-tidy
name: "Tidy bibtex files"
args: [
'--align=space',
'--curly',
'--sort=key',
'--sort-fields',
'--duplicates=key',
'--remove-empty-fields',
'--space=2',
'--trailing-commas',
'--escape',
'--wrap=100',
'--blank-lines'
]
files: ^book/contents/.*\.bib$
# --- Local Custom Hooks ---
- repo: local
hooks:
# --- Structural & Reference Validation ---
- id: check-unreferenced-labels
name: "Check for unreferenced labels"
entry: python ./tools/scripts/content/find_unreferenced_labels.py ./book/contents/core
language: python
additional_dependencies: []
pass_filenames: false
files: ''
# - id: check-section-ids
# name: "Check section IDs"
# entry: python tools/scripts/content/manage_section_ids.py -d book/contents/ --verify --yes
# language: python
# additional_dependencies: [nltk>=3.8]
# pass_filenames: false
# files: ^book/contents/.*\.qmd$
- id: header-inline-check
name: "Detect inline-style Markdown headers"
entry: bash -c 'find . -name "*.qmd" -exec grep -nE "^[^#\n]*\\.[#]{1,6} " {} + && exit 1 || exit 0'
language: system
pass_filenames: false
files: ^book/contents/.*\.qmd$
- id: grep-forbidden-phrases
name: "Check for forbidden words"
entry: bash -c 'grep --color=always -n -E "Retry" "$@" && exit 1 || exit 0'
language: system
pass_filenames: true
files: ^book/contents/.*\.qmd$
# --- Formatting and Cleanup ---
- id: collapse-extra-blank-lines
name: "Collapse extra blank lines"
entry: python tools/scripts/content/collapse_blank_lines.py
language: python
pass_filenames: true
files: ^book/contents/.*\.qmd$
# --- Image Validation ---
- id: validate-images
name: "Validate image files"
entry: python tools/scripts/utilities/check_images.py
language: python
additional_dependencies:
- pillow
- rich
pass_filenames: true
files: ^book/contents/.*\.(png|jpg|jpeg|gif)$
- id: validate-external-images
name: "Check for external images in Quarto files"
entry: python3 tools/scripts/download_external_images.py --validate book/contents/
language: system
pass_filenames: false
files: ^book/contents/.*\.qmd$
description: "Ensure all images are local for build reliability"
- id: validate-image-references
name: "Check that all image references exist on disk"
entry: python3 tools/scripts/validate_image_references.py -d book/contents/ --quiet
language: system
pass_filenames: false
files: ^book/contents/.*\.qmd$
description: "Ensure all referenced images exist on disk"
# --- Build Artifact Detection with Book Binder ---
- id: check-build-artifacts
name: "Check for build artifacts (Book Binder)"
entry: ./binder check
language: system
pass_filenames: false
files: ''
# --- Optional: Auto-cleanup with Book Binder ---
# Uncomment the following hook to automatically clean artifacts before commit
# - id: auto-cleanup-artifacts
# name: "Auto-cleanup build artifacts (Book Binder)"
# entry: ./binder clean
# language: system
# pass_filenames: false
# files: ''
# stages: [pre-commit]
# --- Part Key Validation ---
- id: validate-part-keys
name: "Validate part keys in .qmd files"
entry: python tools/scripts/validate_part_keys.py
language: python
additional_dependencies:
- pyyaml
pass_filenames: false
files: ''
# --- Locked File Check (macOS specific) ---
- id: check-locked-files
name: "Detect locked files (uchg flag on macOS)"
entry: bash -c 'find book/contents/ -type f -exec ls -lO {} + | grep -q " uchg " && { echo "❌ Locked files detected (uchg). Please unlock them before commit."; exit 1; } || exit 0'
language: system
pass_filenames: false