Skip to content

fix: report messages for configuration comments correctly#618

Open
andreahlert wants to merge 1 commit intoeslint:mainfrom
andreahlert:fix/report-unused-disable-directives
Open

fix: report messages for configuration comments correctly#618
andreahlert wants to merge 1 commit intoeslint:mainfrom
andreahlert:fix/report-unused-disable-directives

Conversation

@andreahlert
Copy link

Summary

Previously, ESLint messages that pointed to configuration comments (such as unused disable directive warnings) were being silently dropped because the adjustMessage function returned null for any message pointing to lines before the actual code content.

This change:

  • Tracks the original HTML comment positions when collecting configuration comments from the Markdown
  • Builds a mapping from linted code line numbers to original comment info
  • Maps messages pointing to configuration comment lines back to their original HTML comment locations in the Markdown file

This fixes the issue where --report-unused-disable-directives would not work with the markdown processor, as those warnings were being filtered out.

Before

$ eslint --report-unused-disable-directives README.md
# (no output even when there are unused disable directives)

After

$ eslint --report-unused-disable-directives README.md
README.md
  3:1  warning  Unused eslint-disable directive (no problems were reported from 'no-undef')

Test plan

  • Added new test suite reportUnusedDisableDirectives with tests for single-line and multi-line HTML comments
  • All existing 1590 tests pass
  • Lint passes

Fixes #115

@eslint-github-bot eslint-github-bot bot added the bug label Feb 5, 2026
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 5, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: andreahlert / name: André Ahlert (dcccf5a)

Previously, ESLint messages that pointed to configuration comments (such as
unused disable directive warnings) were being silently dropped because the
`adjustMessage` function returned `null` for any message pointing to lines
before the actual code content.

This change:
- Tracks the original HTML comment positions when collecting configuration
  comments from the Markdown
- Builds a mapping from linted code line numbers to original comment info
- Maps messages pointing to configuration comment lines back to their original
  HTML comment locations in the Markdown file

This fixes the issue where `--report-unused-disable-directives` would not work
with the markdown processor, as those warnings were being filtered out.

Fixes eslint#115
@andreahlert andreahlert force-pushed the fix/report-unused-disable-directives branch from 31d9362 to dcccf5a Compare February 6, 2026 12:52
@andreahlert
Copy link
Author

Hi @nzakas, this fixes a 7-year-old issue (#115) where --report-unused-disable-directives silently drops warnings from HTML comments in Markdown files. CI is green and I've added 4 test cases covering the mapping logic. Would appreciate a review when you get a chance!

@andreahlert
Copy link
Author

Thanks for the review, @Ari4ka!

@nzakas
Copy link
Member

nzakas commented Feb 9, 2026

@andreahlert thanks, I'll take a look when I'm able.

Did you use AI to generate this PR?

@andreahlert
Copy link
Author

Hey @nzakas . Everybody says that to me 😅 I write lots of docs at work so it's a habit to be super detailed. And I usually generate an AI template of PR (for headers for exemple), to keep the same looking, but its all my writing.

I'll keep PR descriptions shorter going forward. Lmk if you want me to clarify anything about the implementation!


This example enables the `alert` global variable, disables the `no-alert` rule, and configures the `quotes` rule to prefer single quotes:

<!-- eslint-skip -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rather disable reporting unused disable directives by setting linterSettings: { reportUnusedDisableDirectives: false } } (and disable @eslint-community/eslint-comments-disable-enable-pair) in the override with the name "markdown/code-blocks/js".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d keep the doc as-is for this PR. The goal here is to fix #115 so that --report-unused-disable-directives actually works with the plugin instead of dropping those warnings. Disabling the feature in the default config would avoid the bug but wouldn’t fix it. If the team prefers to turn it off by default in the markdown override, that could be a separate follow-up. WDYT?

const commentText = wrapComment(commentInfo.text);
const commentLineCount = commentText.split("\n").length;

for (let i = 0; i < commentLineCount; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to the team: Do we want to support multiline ignore directives?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added multiline support so that when a directive is split across lines in the HTML comment, the mapping still points to the right place in the Markdown. If the team prefers to only support single-line directives for now, we can simplify and drop the multiline handling.

if (commentInfo) {
return {
...message,
line: commentInfo.position.start.line,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to the team: Is it okay that the precise location is lost?
For example when a disable directive has multiple rules but only one is unused, the location spans only the name of the unused rule instead of the whole directive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a hard time parsing your question. Are you saying that previously we spanned only the unused rule name and this change loses that? If so, I'd say we don't want to lose that.

Or are you saying we didn't span only the unused rule name and this PR does? Then I'd say this is the preferred approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify for @nzakas: before this PR those messages were dropped (no report at all). With this PR we report them but the position is the whole HTML comment (start line of the comment in the Markdown), not the exact column of the unused rule name inside the comment. So we’re not losing the previous “span only the unused rule name” behavior; we’re adding reporting with a coarser location.

If the team wants column-level precision (e.g. only the unused rule name) we’d need extra mapping from the linted code columns back to the original comment;

I can explore that in a follow-up if needed.

@DMartens
Copy link
Contributor

Thank you for submitting a PR for this. It is a really good starting for fixing this.

@DMartens DMartens moved this from Needs Triage to Implementing in Triage Feb 11, 2026
@lumirlumir
Copy link
Member

Hi — there's a CI failure. If you have a moment, could you take a look?

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

Labels

Projects

Status: Implementing

Development

Successfully merging this pull request may close these issues.

eslint --report-unused-disable-directives does not work with this plugin

5 participants

Comments