-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 #3981] Allow NumericLiterals to be less strict #4045
Conversation
9ca6c33
to
7bdaa75
Compare
@@ -12,8 +12,8 @@ class NumericLiterals < Cop | |||
include ConfigurableMax | |||
include IntegerNode | |||
|
|||
MSG = 'Separate every 3 digits in the integer portion of a number ' \ | |||
'with underscores(_).'.freeze | |||
MSG = 'Use underscores(_) as decimal mark, separate every 3 digits '\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… as decimal mark, separate …
"… as decimal mark and separate …"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed locally, will push it later with the rest. 👍
Probably yes.
That's odd - running the rake task is all that needs to be done. Btw, you should also update the cop's class description with examples illustrating the usage of this option. I don't like the name of this option, as it's a bit confusing IMO. Maybe it should be "AllowMonetaryFormat" or something like this as this is clearly the only usecase that warrants special handling. |
+1 🙂 |
That's probably what I've missed.
Fine with me, but if we make it the default, is should maybe be inversed, for example something like |
I'm fine either way. |
This introduces a new configuration option for `Style/NumericLiteral` called `Strict`, which requires numbers to have a group of 3 digits at end. The cop was changed in 0.47.0 for this behavior, but it's a common practise to specify monetary amounts in cents and then it's useful to group the cents separately (e.g. $123,456.78 as `Money.new(123_456_78)` instead of `Money.new(12_345_678)`). So this commit makes the behavior configurable and reverts the default to the behavior before the 0.47.0 release.
7bdaa75
to
219b481
Compare
@bbatsov Thanks, updated. |
👍 |
`Strict` parameter was added in rubocop#4045, but `default.yml` has not changed. I saw the following warnings if set `Strict` to my `.rubocop.yml`. ``` Warning: unrecognized parameter Style/NumericLiterals:Strict found in /Users/onaka/src/github.com/onk/onkcop/.rubocop.yml ```
`Strict` parameter was added in #4045, but `default.yml` has not changed. I saw the following warnings if set `Strict` to my `.rubocop.yml`. ``` Warning: unrecognized parameter Style/NumericLiterals:Strict found in /Users/onaka/src/github.com/onk/onkcop/.rubocop.yml ```
This introduces a new configuration option for Style/NumericLiteral called
AllowLessPlacesAtEnd
, which allows numbers which don't have 3 places in the last group separated with underscores. This is useful when specifying monetary values in cents (e.g. $123,456.78 asMoney.new(123_456_78)
instead ofMoney.new(12_345_678)
).I also updated the message to make clearer, that the underscores should be used as a decimal mark.
This was the behavior of RuboCop until the 0.47.0 release, see #3749 for the change and #3981 for the issue discussing that change.
Questions:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).