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

auto-gen-config generates incorrect config for Layout/SpaceBeforeBlockBraces #12646

Closed
ikaronen-relex opened this issue Jan 23, 2024 · 0 comments
Labels

Comments

@ikaronen-relex
Copy link

When running rubocop --auto-gen-config with default settings on a large legacy project, the generated .rubocop-todo.yml does not correctly suppress all found offenses, so that a subsequent RuboCop inspection using the generated config does not pass.

The problem seems to be with the Layout/SpaceBeforeBlockBraces cop, for which the following unexpected config entry is generated:

# Offense count: 210
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
  EnforcedStyleForEmptyBraces: no_space

This generated config is particularly strange since our recommended (and mostly followed) Ruby code style in fact mandates spaces before both empty and non-empty block braces, although we do have a few dozen Ruby code files (out of more than 2000) that currently violate this rule.

Manually editing .rubocop-todo.yml to replace EnforcedStyleForEmptyBraces: no_space with Enabled: false does make a subsequent rubocop inspection pass, but rubocop --regenerate-todo still undoes this manual change.

RuboCop version

I am using RuboCop 1.60.1 on JRuby 9.4.5.0. Running rubocop -V prints:

1.60.1 (using Parser 3.3.0.4, rubocop-ast 1.30.0, running on jruby 3.1.4) [java]
jonas054 added a commit to jonas054/rubocop that referenced this issue Feb 25, 2024
…kBraces

The `Layout/SpaceBeforeBlockBraces` cop has two separate style parameters,
`EnforcedStyle` and `EnforcedStyleForEmptyBraces`. The logic for generating
`Enabled: false` when opposite styles are detected during `--auto-gen-config`
was implemented for `EnforcedStyle`, but it was missing for
`EnforcedStyleForEmptyBraces`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant