Skip to content

Commit 68d89ff

Browse files
committed
feat(ci): add strict HTML, CSS, and JS pre-commit checkers
Three new pre-commit hooks (all PyPI-installable, language: python): djlint-check — HTML formatter consistency Runs djlint --check so any future hand-edits that deviate from djlint's canonical HTML formatting are caught before commit. Configuration additions in pyproject.toml: profile = "html" — enables the full HTML5 rule set indent = 2 — enforces 2-space indentation max_line_length = 120 — matches the Python project limit format_js = false — prevents djlint from mangling JS regex tokens format_css = false — CSS is intentionally minified; keep it verbatim check-embedded-css (scripts/check_css.py + tinycss2==1.5.1) Extracts every <style> block from HTML files and parses each with tinycss2. Reports parse errors at the tokeniser level (malformed tokens, unexpected characters) and declaration-level errors (missing ':' separator, empty value lists). Accepts modern CSS (custom properties, var(), clamp(), vendor prefixes) without false positives. check-embedded-js (scripts/check_js.py + py-mini-racer==0.6.0) Extracts every inline <script> block (skipping src= external scripts) and passes each through V8's Function constructor via py-mini-racer. This catches all ES2020+ syntax errors (including optional chaining, async/await, nullish coalescing) without executing the code. Supporting changes: • esc() refactored from 5 sequential .replace() calls to a single-pass lookup-table approach (avoids djlint misreading the bare />/g regex token; also slightly faster at runtime). • index.html reformatted by djlint --reformat (HTML structure only; CSS/JS content preserved verbatim). • tinycss2==1.5.1 and py-mini-racer==0.6.0 added to [project.optional- dependencies].development in pyproject.toml. https://claude.ai/code/session_01LmU2X5jmgRZ1LHXc9S7bW1
1 parent 4c52262 commit 68d89ff

5 files changed

Lines changed: 690 additions & 213 deletions

File tree

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ repos:
6262
entry: djlint --lint
6363
language: python
6464
files: \.(html|jinja|j2)$
65+
- id: djlint-check
66+
name: HTML formatter check
67+
entry: djlint --check
68+
language: python
69+
files: \.(html|jinja|j2)$
70+
- id: check-embedded-css
71+
name: CSS linter (embedded styles)
72+
entry: python scripts/check_css.py
73+
language: python
74+
files: \.(html|jinja|j2)$
75+
additional_dependencies: [tinycss2==1.5.1]
76+
- id: check-embedded-js
77+
name: JS syntax checker (embedded scripts)
78+
entry: python scripts/check_js.py
79+
language: python
80+
files: \.(html|jinja|j2)$
81+
additional_dependencies: [py-mini-racer==0.6.0]
6582
- id: pydocstyle
6683
name: docstring style
6784
entry: pydocstyle --convention=google

0 commit comments

Comments
 (0)