Skip to content

fix: resolve DisableManager line mismatch for nodes with leading trivia#551

Merged
fansenze merged 1 commit intomainfrom
fix/disable-manager-trivia-and-description-20260319
Mar 20, 2026
Merged

fix: resolve DisableManager line mismatch for nodes with leading trivia#551
fansenze merged 1 commit intomainfrom
fix/disable-manager-trivia-and-description-20260319

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

Summary

Fixes two bugs in the eslint-disable comment system:

  1. Leading trivia causes wrong line number: ReportNode/ReportNodeWithFixes/ReportNodeWithSuggestions used node.Pos() for the disable check, which includes leading trivia (comments/whitespace). When the reported node is the first token after a disable comment (e.g., {} as Foo inside function arguments or array literals), node.Pos() resolves to the comment line instead of the code line, causing eslint-disable-next-line to silently fail. Fixed by using utils.TrimNodeTextRange().Pos().

  2. -- description not stripped from rule names: parseRuleNames did not strip ESLint inline descriptions after --, so "rule-name -- reason" was treated as a single rule name and never matched. Fixed by stripping -- ... before parsing.

Example that was broken:

const result = [1, 2, 3].reduce(
  (acc, item) => acc,
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
  {} as Foo,  // disable comment was ignored
);

Related Links

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers crucial bug fixes to the ESLint disable comment system, enhancing its reliability. It corrects the logic for determining the effective line number for disable comments, particularly when code is preceded by comments or whitespace, and ensures that inline descriptions within disable comments are properly handled during rule parsing. These changes prevent silent failures and improve the accuracy of linting directives.

Highlights

  • Fix for eslint-disable-next-line with leading trivia: Resolved an issue where eslint-disable-next-line silently failed when the reported node had leading trivia (comments/whitespace), causing node.Pos() to incorrectly resolve to the comment line instead of the code line. This was fixed by using utils.TrimNodeTextRange().Pos() to get the actual code position.
  • Fix for rule names with inline descriptions: Addressed a bug where parseRuleNames did not correctly strip inline descriptions (e.g., -- reason) from rule names, leading to rule names like "rule-name -- reason" being treated as a single, unmatched rule. The fix involves stripping the description before parsing the rule names.
  • Improved test coverage: New test cases were added to cover scenarios involving eslint-disable-next-line with inline descriptions and cases where leading trivia previously caused disable comments to be ignored, ensuring the robustness of the fixes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves two bugs related to eslint-disable comments. The first fix correctly determines the line number for nodes with leading trivia by using a trimmed text range, which prevents eslint-disable-next-line from failing silently. The second fix ensures that ESLint inline descriptions are properly stripped from rule names, allowing correct rule matching. The changes are well-supported by new unit and integration tests. I have one minor suggestion to improve code maintainability by reducing a duplicated function call.

Two bugs in the disable comment system:

1. ReportNode/ReportNodeWithFixes/ReportNodeWithSuggestions used
   node.Pos() for the disable check, which includes leading trivia
   (comments/whitespace). When the reported node is the first token
   after a disable comment (e.g., inside function args or array
   literals), node.Pos() resolves to the comment line instead of
   the code line, causing eslint-disable-next-line to silently fail.
   Fix: use utils.TrimNodeTextRange().Pos() to get the real code
   position.

2. parseRuleNames did not strip ESLint inline descriptions after
   " -- ", so "rule-name -- reason" was treated as a single rule
   name and never matched. Fix: strip " -- ..." before parsing.
@fansenze fansenze force-pushed the fix/disable-manager-trivia-and-description-20260319 branch from 58dd246 to 94264ec Compare March 19, 2026 11:50
@fansenze fansenze requested a review from hardfist March 20, 2026 02:30
@fansenze fansenze merged commit ba55774 into main Mar 20, 2026
14 checks passed
@fansenze fansenze deleted the fix/disable-manager-trivia-and-description-20260319 branch March 20, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants