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

Lint/Syntax is able to be disabled by directive comments #12663

Closed
Earlopain opened this issue Jan 30, 2024 · 0 comments · Fixed by #12760
Closed

Lint/Syntax is able to be disabled by directive comments #12663

Earlopain opened this issue Jan 30, 2024 · 0 comments · Fixed by #12760

Comments

@Earlopain
Copy link
Contributor

Earlopain commented Jan 30, 2024

Consider this very simple example file:

foo*

This isn't valid syntax and RuboCop complains. If I change this snippet to the following no offense is detected anymore:

# rubocop:disable Lint/Syntax
foo*

My understanding is that Lint/Syntax should not be able to be disabled under any circumstance. https://docs.rubocop.org/rubocop/1.60/configuration.html

The cop enabling process can be altered by setting DisabledByDefault or EnabledByDefault (but not both) to true. These settings override the default for all cops to disabled or enabled, except Lint/Syntax which is always enabled, regardless of the cops' default values (whether enabled, disabled or pending).

There is one exception from the general rule above and that is Lint/Syntax, a special cop that checks for syntax errors before the other cops are invoked. It cannot be disabled and its severity (fatal) cannot be changed in configuration.

If this is considered a bug then RedundantCopDisableDirective and RedundantCopEnableDirective should probably detect this as an offense. (actually, probably not? It's not valid syntax after all, don't think that would work)

RuboCop version

$ [bundle exec] rubocop -V
1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.2.2) [x86_64-linux]
  - rubocop-performance 1.20.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.26.1
Earlopain added a commit to Earlopain/rubocop that referenced this issue Mar 7, 2024
… comments

This would swallow the syntax error, making it look like the file is all good.
In reality all other cops are not being run.
koic added a commit that referenced this issue Mar 9, 2024
[Fix #12663] Prevent `Lint/Syntax` being disabled by directive comments
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.

1 participant