Skip to content

Skip disable line action for self-resolving cops#3945

Merged
rafaelfranca merged 3 commits intoShopify:mainfrom
sucicfilip:fix/skip-disable-action-for-self-resolving-cops
Feb 9, 2026
Merged

Skip disable line action for self-resolving cops#3945
rafaelfranca merged 3 commits intoShopify:mainfrom
sucicfilip:fix/skip-disable-action-for-self-resolving-cops

Conversation

@sucicfilip
Copy link
Contributor

Motivation

When Layout/EmptyComment is reported, the "Disable Layout/EmptyComment for this line" code action adds a # rubocop:disable inline comment, which makes the comment no longer empty, resolving the original offense. This then triggers Lint/RedundantCopDisableDirective, so the user ends up in a loop.

Implementation

Added a SELF_RESOLVING_DISABLE_COPS constant to RuboCopDiagnostic listing cops where an inline disable would resolve the offense itself. The disable line action is skipped for these cops. Currently only includes Layout/EmptyComment but the list can be extended if other similar cases come up.

Automated Tests

Added a test in code_actions_formatting_test.rb that verifies no disable action is offered for Layout/EmptyComment.

Manual Tests

  1. Open a Ruby file with an empty comment (# with nothing after it)
  2. Hover over the Layout/EmptyComment diagnostic
  3. Verify "Disable Layout/EmptyComment for this line" is no longer offered as a code action

@sucicfilip sucicfilip requested a review from a team as a code owner February 7, 2026 17:00
@sucicfilip sucicfilip force-pushed the fix/skip-disable-action-for-self-resolving-cops branch 2 times, most recently from e0f346c to ecac555 Compare February 8, 2026 17:28
@rafaelfranca rafaelfranca added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Feb 9, 2026
@rafaelfranca rafaelfranca force-pushed the fix/skip-disable-action-for-self-resolving-cops branch 2 times, most recently from f7fda53 to 80311a5 Compare February 9, 2026 19:45
sucicfilip and others added 3 commits February 9, 2026 15:43
Since we only check for inclusion and don't care about order or duplicates,
we are use a set. This is a micro-optimization but it makes the intent
clearer and is more efficient for lookups.
@rafaelfranca rafaelfranca force-pushed the fix/skip-disable-action-for-self-resolving-cops branch from cefd9e1 to 0fd0137 Compare February 9, 2026 20:43
@sucicfilip
Copy link
Contributor Author

Thanks for the quick review :-)

@rafaelfranca rafaelfranca disabled auto-merge February 9, 2026 21:34
@rafaelfranca rafaelfranca merged commit 31ed10a into Shopify:main Feb 9, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants