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 #5979] Introduce cops with special status #7567

Merged
merged 8 commits into from Dec 24, 2019
Merged

[Fix #5979] Introduce cops with special status #7567

merged 8 commits into from Dec 24, 2019

Conversation

pirj
Copy link
Member

@pirj pirj commented Dec 12, 2019

New cops, introduced or significantly changed between major versions, are introduced with pending status. This is done to avoid frustration over numerous offences during updates between minor versions. RuboCop will emit a warning that new cops were introduced, and suggest to explicitly enable or disable them in the user configuration file.

Based on #7184

Fixes #5979


Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 183
Max: 197
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, but it feels that I might get into a refactoring spiral if I touch ConfigLoader.

@@ -91,7 +91,9 @@ def configuration_from_file(config_file)
else
add_excludes_from_files(config, config_file)
end
merge_with_default(config, config_file)
merge_with_default(config, config_file).tap do |merged_config|
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge_with_default does not mutate first argument, but rather returns merged config, so I was between tap and using a temporary local variable.

@pirj pirj marked this pull request as ready for review December 12, 2019 17:13
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 13, 2019

What I was not 100% certain of the desired effect of EnabledByDefault/DisabledByDefault on new pending status, so I kept it aside. I've added pending spec examples for those cases though.

I guess they should override the new pending status, as that'd be consistent with the previous behaviour.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 13, 2019

A couple of more things:

  • We should mention the new status in the manual (and the policy that new cops will be using it, until a major release when they'll be enabled/disabled by default)
  • We should update the template for new cops to use the pending status

CHANGELOG.md Outdated Show resolved Hide resolved
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 18, 2019

@pirj Any chance you'll be wrapping this one soon? I'm wondering whether to cut a new release now or wait for this PR.

@pirj
Copy link
Member Author

pirj commented Dec 18, 2019

@bbatsov Current status and a couple of questions:

  1. I'm a bit confused with the default behaviour of Enabled/DisabledByDefault, since it seems to only affect RuboCop's own default config, and ignores extensions' configs. So e.g. if rubocop-rspec's config has a pending cop (or, enabled, or, disabled, doesn't matter), those settings don't seem to override extension's cop enabled status.
    Is there a distinction between gem's default configs, and user's configs, e.g. if we require .rubocop_base.yml that enables e.g. Lint/A, and also rubocop-rspec/config/default.yml that enables RSpec/B, and the main config has DisabledByDefault: true, shouldn't we disable RSpec/B but keep Lint/A enabled?

  2. docs - Intend to extend manual/configuration.md mentioning default pending status.
    Not sure, if a dedicated section mentioning how we are going to introduce cops, and how users are supposed to update RuboCop should be added?

I have some time this week to address this, but if something else pops up, this might take longer, so it's better to postpone to the next release.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 20, 2019

I'm a bit confused with the default behaviour of Enabled/DisabledByDefault, since it seems to only affect RuboCop's own default config, and ignores extensions' configs. So e.g. if rubocop-rspec's config has a pending cop (or, enabled, or, disabled, doesn't matter), those settings don't seem to override extension's cop enabled status.

Well, I think that's an orthogonal problem that has to be fixed separately. This setting dates back from a time where there were almost no extensions.

Is there a distinction between gem's default configs, and user's configs, e.g. if we require .rubocop_base.yml that enables e.g. Lint/A, and also rubocop-rspec/config/default.yml that enables RSpec/B, and the main config has DisabledByDefault: true, shouldn't we disable RSpec/B but keep Lint/A enabled?

Yeah, I agree.

docs - Intend to extend manual/configuration.md mentioning default pending status.

👍

Not sure, if a dedicated section mentioning how we are going to introduce cops, and how users are supposed to update RuboCop should be added?

Some small section on the subject would be useful indeed.

Maxim Krizhanovski and others added 7 commits December 20, 2019 23:10
Previously, new cops were introduced as either enabled or disabled. The
ones enabled were bothering users with new offences, while disabled cops
were often left out and remained under radars, while still being useful.

By introducing this special status, users have to decide how to handle
new cops, by explicitly enabling or disabling them.

Cops are to be introduced with pending status between major releases of
RuboCop and its extensions, and they eventually become enabled or
disabled on major releases.

Co-authored-by: Phil Pirozhkov <hello@fili.pp.ru>
@pirj
Copy link
Member Author

pirj commented Dec 20, 2019

@bbatsov All green. Please take a look if something needs to be added.

@pirj
Copy link
Member Author

pirj commented Dec 20, 2019

There's one very nasty thing that I've noticed about :isolated_environment. In cases there's something horribly wrong with the example, it interrupts normal RSpec cycle and reports no error. All specs appear to be green, and the only way to figure out that something is wrong is to make sure the number of examples in a spec matches those reported by RSpec.

@pirj pirj changed the title Introduce cops with special status [Fix #5979] Introduce cops with special status Dec 20, 2019
@bbatsov bbatsov merged commit 5fb9db3 into rubocop:master Dec 24, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 24, 2019

Looks good to me. Thanks for bringing this across the finish line!

@pirj pirj deleted the introduce-new-cops branch December 24, 2019 09:49
@pirj
Copy link
Member Author

pirj commented Dec 24, 2019

Happy to move this forward 👍

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.

Introduce new cops with a special status (instead of enabled/disabled)
3 participants