Repository navigation
Read Jinja Template Comments in the Prose Gate - #4325
Conversation
A `.j2`, `.jinja`, or `.jinja2` template now reads through a Jinja lexer, so its
`{# ... #}` comments meet the comment rules. Pygments names the lexer for a template
whose inner suffix it knows, and the data file names one for a bare template suffix.
A comment block is matched by its closer as well as its opener, so a whitespace-control
`-` stays out of the comment text.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pygments names a Jinja lexer for a CSS, JavaScript, or SQL template too, so the language declares each, and a test reads Pygments' own list. A shebang now outranks the template suffix, so a script template keeps its shell comments checked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eeps Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 51 minutes. View limit details
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. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified in the Jinja template lexer dispatch, comment extraction, or CLI integration changes.
No open issues 🎉
What changed in this PR
This PR extends the prose gate to inspect comments in bare and suffix-qualified Jinja templates while preserving embedded-language boundaries.
Changes:
- Add Jinja template suffix mappings and lexer dispatch support.
- Handle Jinja block comments with whitespace-control markers.
- Add lexer, comment extraction, and CLI integration tests.
| File | Description |
|---|---|
| tests/test_prose_lint.py | Adds Jinja behavior, lexer-dispatch, comment-extraction, and CLI integration coverage. |
| .github/actions/prose-gate/prose-gate.json | Defines Jinja template suffix mappings, lexer configurations, and comment syntaxes. |
| .github/actions/prose-gate/prose_lint.py | Dispatches template files to the appropriate lexer and matches Jinja block-comment closers. |
Review effort: Lite
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4325 +/- ##
========================================
Coverage 79.25% 79.25%
========================================
Files 44 44
Lines 15887 15887
========================================
Hits 12592 12592
Misses 3295 3295
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
|
/review |
Action not completed
|
…udit, Co-Author (#4330) ## Summary Promotes `develop` to `main`. It carries four changes: - [#4325](#4325) reads Jinja template comments in the prose gate. - [#4323](#4323) names the registration grace refusal and routes a missing shared hook to the maintainer. - [#4326](#4326) audits that a merge-bot caller stub subscribes to `auto_merge_disabled`. - [#4324](#4324) allows a co-author line by default and never a session link. Closes #4308 Closes #3869 Closes #1264 Closes #4307 Closes #4313 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * The installer now sets `attribution.sessionUrl` to `false` when the setting is absent, while preserving existing host values. Reports identify missing settings and note host-owned values. * Prose checks now recognize Jinja templates and handle their comments more accurately. * Workflow specifications can require tokens across entire workflows, with validation for the new requirement. * **Documentation** * Updated guidance clarifies hook reporting, check-registration timing, and commit and pull request attribution rules. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
The prose gate read a Jinja template as plain text, so a
{# ... #}comment never met the comment rules. A wrapped or over-long comment sentence in a template passed the commit hook and CI.prose-gate.jsondeclares ajinjalanguage over every Jinja lexer Pygments has:django, and the HTML, XML, YAML, CSS, JavaScript, and SQL template lexers. Its comments are{# ... #}blocks, plus the HTML comments an HTML template holds and the#comments a YAML template holds. A CSS, JavaScript, or SQL template's own comments stay unread, as an embedded language's are in an HTML file..html.j2. A bare.j2,.jinja, or.jinja2has none, so a newfiles.templatemap namesdjangofor it.lexer_namereads that map last, after Pygments and the shebang. So a.html.j2keeps its HTML comments, and arun.sh.j2opening on a bash shebang keeps its shell comments checked.comment_linespicks a block comment by its closer as well as its opener. So a whitespace-control-on either end, as in{#- ... #}, stays out of the comment text. A block with no matching closer still falls back to its opener, as before.Markup and expressions stay out of scope, as with every other lexer. A Salt
.slsfile, which Pygments reads as a YAML template, now has its#and{# ... #}comments checked too.Tests
tests/test_prose_lint.pygainsTestJinjaLanguage. It shows that two sentences on one comment line, a wrapped sentence, and a sentence over the word cap are each violations in a bare.j2or.jinja2file and in each kind of template Pygments names. It shows that markup and expressions holding the same text raise nothing. It also runs the gate's CLI on a staged template with--diff-commit, as the commit hook does, and against a base with--diff, as CI does.TestLexerDispatchcovers the new mappings and the shebang outranking the template suffix. It also reads Pygments' own lexer list, so a Jinja lexer a later Pygments release adds fails until the data declares it. Each new case fails on the base branch's gate. A module-levelrun_gatehelper replaces the in-process gate runTestDiffCommitChoosesTheBaseACommitAddsToheld inline.Local review
A finding declined on evidence: Pygments splits a host comment around a
{{ }}or{% %}tag inside it, such as# Set by {{ tool }}. Two.in a YAML template, so the text after the tag goes unread. That is a missed lint finding in a rare shape, neither silent-destructive nor something an outsider triggers, so it earns no fix under the hardening-effort rule. These files were read as plain text before this change, so nothing that was checked stops being checked.Closes on promotion: #4307
🤖 Generated with Claude Code