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

Fix Lint/Syntax behavior when Enabled: false of Lint department #11689

Merged
merged 1 commit into from
Mar 11, 2023

Conversation

koic
Copy link
Member

@koic koic commented Mar 10, 2023

Here's another fix I found in work on #11688.

Ruby code has a syntax error and .rubocop.yml with Lint department is disabled:

def foobar
  t = {
    a: "foo"  # missing "," syntax error
    b: 'bar'
  }
  return t
end
# .rubocop.yml
Lint:
  Enabled: false

But Lint/Syntax must not be disabled:

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.

https://docs.rubocop.org/rubocop/1.46/configuration.html#severity

Before

The syntax is invalid but an offense is not registerd:

$ bundle exec rubocop
(snip)

Inspecting 1 file
.

1 file inspected, no offenses detected

After

Lint/Syntax detects invalid syntax as expected:

$ bundle exec rubocop
(snip)

Offenses:

example.rb:4:5: F: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 3.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    b: 'bar'
    ^

1 file inspected, 1 offense detected

The Lint/Syntax behavior for DisabledByDefault: true configuration is also fixed.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

Here's another fix I found in work on rubocop#11688.

Ruby code has a syntax error and .rubocop.yml with `Lint` department is disabled:

```ruby
def foobar
  t = {
    a: "foo"  # missing "," syntax error
    b: 'bar'
  }
  return t
end
```

```yaml
# .rubocop.yml
Lint:
  Enabled: false
```

But `Lint/Syntax` must not be disabled:

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

https://docs.rubocop.org/rubocop/1.46/configuration.html#severity

## Before

The syntax is invalid but an offense is not registerd:

```console
$ bundle exec rubocop
(snip)

Inspecting 1 file
.

1 file inspected, no offenses detected
```

## After

`Lint/Syntax` detects invalid syntax as expected:

```console
$ bundle exec rubocop
(snip)

Offenses:

example.rb:4:5: F: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 3.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    b: 'bar'
    ^

1 file inspected, 1 offense detected
```

The `Lint/Syntax` behavior for `DisabledByDefault: true` configuration is also fixed.
@koic koic force-pushed the fix_lint_syntax_when_enabled_false branch from 4f8f2dd to e73f1bb Compare March 11, 2023 06:53
@bbatsov bbatsov merged commit f035637 into rubocop:master Mar 11, 2023
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 11, 2023

Nice catch!

@koic koic deleted the fix_lint_syntax_when_enabled_false branch March 11, 2023 10:25
koic added a commit to koic/rubocop that referenced this pull request Mar 13, 2023
Follow up rubocop#11689.

I read back through the configuration doc and noticed that the description of
`DisabledByDefault` behavior was not strict.
This PR updates the doc to consider `Lint/Syntax` which is always enabled.

This makes the description consistent with:

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

https://docs.rubocop.org/rubocop/1.46/configuration.html#severity
bbatsov pushed a commit that referenced this pull request Mar 13, 2023
Follow up #11689.

I read back through the configuration doc and noticed that the description of
`DisabledByDefault` behavior was not strict.
This PR updates the doc to consider `Lint/Syntax` which is always enabled.

This makes the description consistent with:

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

https://docs.rubocop.org/rubocop/1.46/configuration.html#severity
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.

None yet

2 participants