Front-end Linting#1165
Conversation
WalkthroughThis PR establishes JavaScript and Django template linting infrastructure by introducing ESLint and djLint tools. A new Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.pre-commit-config.yaml (1)
27-31: 💤 Low valuedjlint hooks use the old Riverside-Healthcare organisation URL.
The djLint documentation shows the canonical pre-commit repo as
https://github.com/djlint/djLint, reflecting the project's GitHub organisation rename. GitHub currently redirects the old URL, but updating to the canonical form avoids any future broken-redirect surprises.🔧 Proposed fix
- - repo: https://github.com/Riverside-Healthcare/djLint + - repo: https://github.com/djlint/djLint rev: v1.36.4🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.pre-commit-config.yaml around lines 27 - 31, Update the pre-commit hook repo URL in .pre-commit-config.yaml: replace the old organization URL string "https://github.com/Riverside-Healthcare/djLint" with the canonical repository "https://github.com/djlint/djLint" so the djlint hooks (ids djlint-reformat-django and djlint-django) point to the upstream source and avoid relying on GitHub redirects.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.eslintrc.js:
- Line 1: Add an ignorePatterns entry to the exported ESLint config object so
the config file itself is skipped by linting; update the object exported via
module.exports to include ignorePatterns (e.g., include ".eslintrc.js") to
prevent the no-undef false positive on module, or alternatively enable env.node
at the top of the exported config if you prefer to allow CommonJS in the config
file.
In `@package.json`:
- Line 18: package.json declares "eslint": "^8.57.1" but your pre-commit hook
lists additional_dependencies: eslint@8.56.0, causing a version mismatch; update
the .pre-commit-config.yaml additional_dependencies entry for eslint to match
the package.json minimum (e.g., change eslint@8.56.0 to eslint@8.57.1) so both
npm and pre-commit run the same ESLint version.
---
Nitpick comments:
In @.pre-commit-config.yaml:
- Around line 27-31: Update the pre-commit hook repo URL in
.pre-commit-config.yaml: replace the old organization URL string
"https://github.com/Riverside-Healthcare/djLint" with the canonical repository
"https://github.com/djlint/djLint" so the djlint hooks (ids
djlint-reformat-django and djlint-django) point to the upstream source and avoid
relying on GitHub redirects.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8c4e9820-9b34-44b2-9bdf-33301c706668
⛔ Files ignored due to path filters (2)
package-lock.jsonis excluded by!**/package-lock.jsonuv.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
.eslintrc.js.pre-commit-config.yamlpackage.jsonpyproject.toml
c74858b to
0d42702
Compare
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
6b3ec61 to
acef025
Compare
41a568d to
32da122
Compare
mkangia
left a comment
There was a problem hiding this comment.
I don't have enough knowledge to review this but if you can share what each setting/file is specifically for, that would be helpful.
There was a problem hiding this comment.
Can you help understand the different settings added in this file, what they mean?
There was a problem hiding this comment.
I have updated the PR description to give a breakdown summary of what each of the settings in eslintrc.js mean.
Product Description
This PR adds automated linting for JavaScript and Django HTML templates to the pre-commit pipeline. There are no user-facing changes.
Technical Summary
CCCT-2388
Adds two linters as pre-commit hooks alongside the existing Python linting:
eslint:recommended) — lintscommcare_connect/static/js/**/*.js. JS-in-HTML templates is intentionally excluded: Django template tags ({% %},{{ }}) interpolated into<script>blocks cause parse errors. Existing JS files are grandfathered via anoverridesblock (rules downgraded towarn); new files geterror-level rules, blocking commits.commcare_connect/templates/. Runs as two hooks:djlint-reformat-django(auto-fixes indentation) thendjlint-django(blocks on lint violations). A number of rules are suppressed — see[tool.djlint]inpyproject.tomlfor the full list. Notable suppressions: Two deferred cleanup items (H026: empty class attributes, H029: uppercase method="POST") that will be addressed in a bulk reformat PR.As mentioned a separate PR here has been opened to do a bulk reformat of all our HTML code to bring it in line with the new linters.
For
.eslintrc.jshere is a summary breakdown of what each of the settings do:env: Declares global variables that are pre-defined in those environments.browser: true: Makes browser globals likewindow,document, andfetchavailable. Would otherwise flag these asno-undeferrors.es2020: true: Makes ES2020 globals likePromiseandBigIntavailable. Would otherwise flag these asno-undeferrors.parserOptions: Controls how ESLint parses the JS.ecmaVersion: 2020: Allows modern syntax like optional chaining and nullish coalescing.sourceType: 'module': Enables ES module syntax (import/export).extends: ['eslint:recommended']: Enables a curated set of rules that catch common bugs (e.g. no duplicate keys, no unreachable code).rules: Project-wide overrides on top ofrecommended.no-console: 'error': Disallowsconsole.logetc.no-unused-vars: Disallows declared but unused variablesoverrides: Applies different rules to specific files. The grandfathered existing JS files all get rules set towarninstead oferror, so that existing files won't break CI but will still surface issues as warnings.ignorePatterns: Files ESLint skips entirely.Safety Assurance
Safety story
Config-only change. No application code, models, views, or migrations are modified. The hooks only run at commit time and have no effect on the running application. The ESLint grandfathering strategy ensures existing code produces warnings only, so no commits are blocked on legacy violations.
This change was also tested locally by creating an HTML and JS file with linting errors and ensuring that commits were blocked for those files.
Automated test coverage
No automated tests — this change adds developer tooling with no runtime behaviour to test.
QA Plan
QA will not be performed for this change. Below is the testing plan for reference:
pre-commit run --all-filesand confirm all hooks passcommcare_connect/static/js/with aconsole.logand an unused variable, stage it, and confirm ESLint blocks the commit with errorsdashboard.js) produces warnings but does not block the commitaltattribute on an<img>, stage it, and confirm djlint blocks the commitLabels & Review