Skip to content

Linter: Resolve the framework from the config before choosing parser options - #2853

Open
viktorianer wants to merge 1 commit into
marcoroth:mainfrom
viktorianer:linter-framework-from-config
Open

viktorianer wants to merge 1 commit into
marcoroth:mainfrom
viktorianer:linter-framework-from-config

Conversation

@viktorianer

Copy link
Copy Markdown
Contributor

Since #2824, Linter#lint computes each rule's parser options before it merges this.config.framework into the lint context. When the framework comes only from the config, as with framework: actionview in .herb.yml and herb-lint on the command line, parserOptionsFor receives undefined. It falls back to DEFAULT_FRAMEWORK ("ruby") and turns action_view_helpers off for every rule that asks for it.

One visible effect: the body of a javascript_tag block is parsed as text instead of a <script> element, so html-no-unescaped-entities reports the JavaScript inside it.

<%= javascript_tag do %>
  if (a && b) {}
<% end %>

With framework: actionview in .herb.yml, herb-lint 0.11.0 reports nothing on this file. 0.11.1 reports two html-no-unescaped-entities warnings, and its unsafe autofix would turn the && into &amp;&amp;. Passing { framework: "actionview" } in the lint context still gives no offense, which is why the existing tests did not notice.

parserOptionsFor now gets the framework the way the lint context does: from the context, else from the config.

The new test lints that snippet once with the framework in the context and once with it only in the config, and expects no offense from either. It fails on main on the config path, with 2 offenses. The full linter suite passes with the change (250 files). A herb-lint built from this branch reports nothing on the snippet, and still reports a form_with nested inside another form_with.

🤖 Generated with Claude Code

…options

Since marcoroth#2824, `lint()` picks each rule's parser options before it merges
`this.config.framework` into the lint context. A framework set only in
`.herb.yml`, as the CLI sets it, therefore reaches `parserOptionsFor`
as `undefined`, which falls back to `DEFAULT_FRAMEWORK` ("ruby") and
turns `action_view_helpers` off for every rule that asks for it.

Without the Action View transform, the body of a `javascript_tag`
block is text instead of a `<script>` element, so
`html-no-unescaped-entities` reports the JavaScript's `&&` and its
unsafe autofix rewrites it to `&amp;&amp;`. 0.11.0 reports nothing on
the same file.

`parserOptionsFor` now gets the framework the same way the lint context
does: from the context, else from the config.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added linter @herb-tools/linter for HTML+ERB templates typescript TypeScript source across the javascript/ packages labels Oct 25, 2026
@viktorianer
viktorianer marked this pull request as ready for review October 25, 2026 19:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linter @herb-tools/linter for HTML+ERB templates typescript TypeScript source across the javascript/ packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant