Skip to content
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

custom rule derived from FileName rule can no longer be disabled in 1.63 #12835

Closed
mscrivo opened this issue Apr 11, 2024 · 2 comments · Fixed by #12838
Closed

custom rule derived from FileName rule can no longer be disabled in 1.63 #12835

mscrivo opened this issue Apr 11, 2024 · 2 comments · Fixed by #12838

Comments

@mscrivo
Copy link

mscrivo commented Apr 11, 2024

If you have a custom FileName rule defined, say Acme/FileName that is derived from the FileName rule, you are now unable to disable it with # rubocop:disable Acme/FileName at the top of the file in version 1.63+. Rubocop is insisting that the violation must be fixed.


Expected behavior

# rubocop:disable Acme/FileName should continue to disable the custom rule on a per file basis as it did in 1.62 and prior.

Actual behavior

It does not disable the rule and insists we fix the violation.

Steps to reproduce the problem

Create a custom rule based on FileName:

module Acme
  class FileName < RuboCop::Cop::Naming::FileName
  # it's enough just to define the class and not actually override or add any behaviour  
  end
end

require the rule in your rubocop.yml, then create a file that violates the naming rule and try adding:

# rubocop:disable Acme/FileName
# code here
# rubocop enable Acme/FileName

run: bundle exec rubocop --only Acme/FileName <filename>

Notice the disable does not work.

RuboCop version

1.63.1 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.3.0) +server [arm64-darwin23]
  - rubocop-factory_bot 2.25.1
  - rubocop-minitest 0.35.0
  - rubocop-performance 1.21.0
  - rubocop-rake 0.6.0
  - rubocop-sequel 0.3.4
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 12, 2024

See #12802, which I'm guessing resulted in this change for you. I think global offenses can be disabled only in the cop configuration (you can exclude the file from being checked by the cop), but I may be mistaken about this.

@Earlopain
Copy link
Contributor

There are quite a few places that do disable Naming/FileName via comment on the first line, see this GH code search: https://github.com/search?q=%22rubocop%3Adisable+Naming%2FFileName%22&type=code

I didn't anticipate this behaviour change, I will open a PR to continue supporting these cases, though I think the config would be a more appropriate place for this.

Earlopain added a commit to Earlopain/rubocop that referenced this issue Apr 12, 2024
… comments

`Naming/FileName` now returns global offenses but there are quite a few projects that
disable the cop with a comment. The change to global offenses broke that behaviour.
Earlopain added a commit to Earlopain/rubocop that referenced this issue Apr 12, 2024
… comments

`Naming/FileName` now returns global offenses but there are quite a few projects that
disable the cop with a comment. The change to global offenses broke that behaviour.
bbatsov pushed a commit that referenced this issue Apr 15, 2024
`Naming/FileName` now returns global offenses but there are quite a few projects that
disable the cop with a comment. The change to global offenses broke that behaviour.
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 a pull request may close this issue.

3 participants