-
-
Notifications
You must be signed in to change notification settings - Fork 724
fix(language_server): append rule to existing disable comment instead of creating duplicate #16081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… of creating duplicate When using the 'Disable rule for this line' quick fix, if there's already a disable-next-line comment on the line above, append the new rule to the existing comment using comma separation instead of creating a new duplicate comment. Fixes #16060
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #16081 will not alter performanceComparing Summary
Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the language server's "Disable rule for this line" quick fix to append rules to existing disable-next-line comments instead of creating duplicate comments. The implementation adds a new is_next_line field to the DisableRuleComment struct to distinguish between different directive types, and introduces logic to find and modify existing comments.
Key Changes:
- Added
is_next_lineboolean field toDisableRuleCommentto track directive types - Implemented
find_disable_next_line_comment_for_positionmethod to locate existingdisable-next-linecomments - Created
append_rule_to_existing_commentfunction to modify existing comments instead of creating duplicates
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
crates/oxc_linter/src/disable_directives.rs |
Added is_next_line field to DisableRuleComment struct and new method to find disable-next-line comments at a given position |
crates/oxc_language_server/src/linter/error_with_position.rs |
Implemented logic to append rules to existing disable-next-line comments and refactored disable comment creation into separate functions |
crates/oxc_language_server/src/linter/isolated_lint_handler.rs |
Updated to pass directives information to diagnostic conversion for quick fix generation |
crates/oxc_language_server/src/linter/snapshots/[email protected] |
Updated snapshot to reflect new behavior of appending to existing comments instead of creating duplicates |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| self.disable_rule_comments.push(DisableRuleComment { | ||
| span: comment_span, | ||
| r#type: RuleCommentType::All, | ||
| is_next_line: true, |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is_next_line field should be false for disable-line directives. While DisabledRule.is_next_line uses true for both -next-line and -line directives (to distinguish line-specific from file-wide directives), DisableRuleComment.is_next_line should distinguish -next-line (true) from -line (false) directives.
This is because find_disable_next_line_comment_for_position should only match -next-line comments when looking for an existing comment to append to, not -line comments.
| self.disable_rule_comments.push(DisableRuleComment { | ||
| span: comment_span, | ||
| r#type: RuleCommentType::Single(rules), | ||
| is_next_line: true, |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is_next_line field should be false for disable-line directives. While DisabledRule.is_next_line uses true for both -next-line and -line directives (to distinguish line-specific from file-wide directives), DisableRuleComment.is_next_line should distinguish -next-line (true) from -line (false) directives.
This is because find_disable_next_line_comment_for_position should only match -next-line comments when looking for an existing comment to append to, not -line comments.
| pub span: Span, | ||
| /// Rules disabled by the comment | ||
| pub r#type: RuleCommentType, | ||
| /// Whether this is a `disable-next-line` or `disable-line` directive |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comment is ambiguous. It should clarify that true means this is a disable-next-line directive, and false means it's either a disable-line or regular disable directive.
Suggested wording: "Whether this is a disable-next-line directive (as opposed to disable-line or disable)"
| /// Whether this is a `disable-next-line` or `disable-line` directive | |
| /// Whether this is a `disable-next-line` directive (as opposed to `disable-line` or `disable`) |
| return None; | ||
| } | ||
|
|
||
| let is_next_line = group_vec.first().is_some_and(|i| i.val.is_next_line()); |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is_next_line value is incorrectly computed from interval.val.is_next_line(), which returns true for both -next-line and -line directives.
For DisableRuleComment, is_next_line should be true only for -next-line directives, and false for -line and regular disable directives.
To fix this, you need to determine the actual directive type from the interval. One approach is to check if the interval starts at comment_span.end (which indicates -next-line) or at an earlier position (which indicates -line or disable).
| let is_next_line = group_vec.first().is_some_and(|i| i.val.is_next_line()); | |
| let is_next_line = group_vec.first().is_some_and(|i| i.start == comment_span.end); |
| }; | ||
|
|
||
| // Check if the rule is already in the comment | ||
| if existing_rules.contains(&rule_name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never happen. The fix/diagnostic is only shown when the rule is not in the comment.
Adding a (debug_)assert! would be helpful :)
| section_offset, | ||
| rope, | ||
| source_text, | ||
| directives, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes only for the "fix on this line" and not "on the whole file" (section for partial loaders).
Probably need to update the PR title
| } | ||
|
|
||
| #[test] | ||
| fn disable_for_this_line_single_line() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some tests please? Specially with partial source text (section offset > 0).
I am afraid that this will be skipped by the internal linter.

When using the 'Disable rule for this line' quick fix, if there's already a disable-next-line comment on the line above, append the new rule to the existing comment using comma separation instead of creating a new duplicate comment.
Fixes #16060