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

Show warning message if passed string to 'Enabled' key in .rubocop.yml #7272

Merged
merged 1 commit into from Aug 19, 2019

Conversation

@unasuke
Copy link
Contributor

commented Aug 8, 2019

feature

It causes unexpected cop warnings because treats as truthy value if passed neither true nor false in 'Enabled' key's value like "Enabled: disable".

motivation

Our team occurred a problem that, unexpected cop was in effect.
The cause was the wrong config value like an "Enabled: disabled".


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.

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch from f38d9cb to 6241927 Aug 8, 2019

@unasuke

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2019

hmm, How do I fix the Metrics/ClassLength: Class has too many lines. [179/174] ...?

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch 2 times, most recently from 5492f85 to d7863b9 Aug 8, 2019

@@ -17,7 +17,7 @@ Metrics/AbcSize:
# Offense count: 47
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 174
Max: 179

This comment has been minimized.

Copy link
@unasuke

unasuke Aug 8, 2019

Author Contributor

I can't write this code for more short. So I changed max value in Metrics/ClassLength in .rubocop_todo.yml

lib/rubocop/config_loader.rb Outdated Show resolved Hide resolved

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch from d7863b9 to cd1403d Aug 9, 2019

lib/rubocop/config_loader.rb Outdated Show resolved Hide resolved

warn Rainbow(
"Cop `#{parent}` is enabled by value '#{value}' specified. " \
'It may unexpected behavior unless set true or false.'

This comment has been minimized.

Copy link
@bbatsov

bbatsov Aug 10, 2019

Collaborator

I think we should probably raise an error instead and just say that property X of cop Y is supposed to be a boolean and it's not.

This comment has been minimized.

Copy link
@unasuke

unasuke Aug 10, 2019

Author Contributor

OK. I change to raise an exception.

This comment has been minimized.

Copy link
@unasuke

unasuke Aug 10, 2019

Author Contributor

Like this?

Screenshot from 2019-08-10 20-05-44

This comment has been minimized.

Copy link
@bbatsov

bbatsov Aug 10, 2019

Collaborator

Actually instead of exception this can just be an error message with some error code. I guess the stack trace will just confuse most users.

It will also be a good idea to colour the names of the cop and the property in the error message and to mention its current value that's causing the error.

This comment has been minimized.

Copy link
@unasuke

unasuke Aug 10, 2019

Author Contributor

How is this?

Screenshot from 2019-08-10 21-51-25

This comment has been minimized.

Copy link
@bbatsov

bbatsov Aug 10, 2019

Collaborator

It's good.

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch from cd1403d to 99c15f4 Aug 10, 2019

lib/rubocop/config_loader.rb Outdated Show resolved Hide resolved
@bbatsov

This comment has been minimized.

Copy link
Collaborator

commented Aug 13, 2019

You'll also have to rebase on top of the current master.

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch from 99c15f4 to 7df13d0 Aug 14, 2019

@unasuke

This comment has been minimized.

Copy link
Contributor Author

commented Aug 14, 2019

I rebased this. 🙆‍♂

lib/rubocop/config_loader.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch from 7df13d0 to 529aaab Aug 14, 2019

CHANGELOG.md Outdated Show resolved Hide resolved
Show warning message if passed string to 'Enabled' key in .rubocop.yml
It causes unexpected cop warnings because treats as truthy value if
passed neither true nor false in 'Enabled' key's value like
"Enabled: disable".  #7056

@unasuke unasuke force-pushed the unasuke:warn_in_not_boolean_to_enabled branch from 529aaab to b1e0911 Aug 14, 2019

@koic

koic approved these changes Aug 14, 2019

@@ -5,6 +5,7 @@
### New features

* [#7274](https://github.com/rubocop-hq/rubocop/issues/7274): Add new `Lint/SendWithMixinArgument` cop. ([@koic][])
* [#7272](https://github.com/rubocop-hq/rubocop/pull/7272): Show warning message if passed string to `Enabled`, `Safe`, `SafeAutocorrect`, and `AutoCorrect` keys in .rubocop.yml. ([@unasuke][])

This comment has been minimized.

Copy link
@koic

koic Aug 16, 2019

Member

Ah, This URL seems to be #7056.

This comment has been minimized.

Copy link
@unasuke

unasuke Aug 19, 2019

Author Contributor

Oh...

This comment has been minimized.

Copy link
@unasuke

unasuke Aug 19, 2019

Author Contributor

Shoud I have to change the url to #7056 ? (But already merged it... Sorry too late.)

@bbatsov bbatsov merged commit 8cfdc57 into rubocop-hq:master Aug 19, 2019

22 checks passed

ci/circleci: cc-setup Your tests passed on CircleCI!
Details
ci/circleci: cc-upload-coverage Your tests passed on CircleCI!
Details
ci/circleci: documentation-checks Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-rubocop Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.3-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-spec Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@bbatsov

This comment has been minimized.

Copy link
Collaborator

commented Aug 19, 2019

Thanks!

@unasuke unasuke deleted the unasuke:warn_in_not_boolean_to_enabled branch Aug 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.