Skip to content

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Nov 24, 2025

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

… 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
@github-actions github-actions bot added A-linter Area - Linter A-editor Area - Editor and Language Server labels Nov 24, 2025
Copy link
Contributor Author

camc314 commented Nov 24, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added the C-bug Category - Bug label Nov 24, 2025
@camc314 camc314 marked this pull request as ready for review November 24, 2025 23:14
@camc314 camc314 requested a review from Sysix as a code owner November 24, 2025 23:14
Copilot AI review requested due to automatic review settings November 24, 2025 23:14
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 24, 2025

CodSpeed Performance Report

Merging #16081 will not alter performance

Comparing c/11-24-fix_language_server_append_rule_to_existing_disable_comment_instead_of_creating_duplicate (b05be94) with main (e1c21ca)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (bab4bc8) during the generation of this report, so e1c21ca was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copilot finished reviewing on behalf of camc314 November 24, 2025 23:20
Copy link
Contributor

Copilot AI left a 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_line boolean field to DisableRuleComment to track directive types
  • Implemented find_disable_next_line_comment_for_position method to locate existing disable-next-line comments
  • Created append_rule_to_existing_comment function 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,
Copy link

Copilot AI Nov 24, 2025

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.

Copilot uses AI. Check for mistakes.
self.disable_rule_comments.push(DisableRuleComment {
span: comment_span,
r#type: RuleCommentType::Single(rules),
is_next_line: true,
Copy link

Copilot AI Nov 24, 2025

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.

Copilot uses AI. Check for mistakes.
pub span: Span,
/// Rules disabled by the comment
pub r#type: RuleCommentType,
/// Whether this is a `disable-next-line` or `disable-line` directive
Copy link

Copilot AI Nov 24, 2025

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)"

Suggested change
/// 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`)

Copilot uses AI. Check for mistakes.
return None;
}

let is_next_line = group_vec.first().is_some_and(|i| i.val.is_next_line());
Copy link

Copilot AI Nov 24, 2025

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).

Suggested change
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);

Copilot uses AI. Check for mistakes.
};

// Check if the rule is already in the comment
if existing_rules.contains(&rule_name) {
Copy link
Member

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,
Copy link
Member

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() {
Copy link
Member

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.

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

Labels

A-editor Area - Editor and Language Server A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extension: quick fix disable rule doesn't edit existing comment and creates duplicate disable comments instead

3 participants