Skip to content

Skip disable line action for self-resolving cops#3945

Open
sucicfilip wants to merge 1 commit intoShopify:mainfrom
sucicfilip:fix/skip-disable-action-for-self-resolving-cops
Open

Skip disable line action for self-resolving cops#3945
sucicfilip wants to merge 1 commit 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 from 98716c2 to e0f346c Compare February 7, 2026 17:01
@sucicfilip sucicfilip force-pushed the fix/skip-disable-action-for-self-resolving-cops branch from e0f346c to ecac555 Compare February 8, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant