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

Detect degenerated workarounds for Style/NumericLiterals #3749

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [#3775](https://github.com/bbatsov/rubocop/pull/3775): Avoid crash in `Style/HashSyntax` cop with an empty hash. ([@pocke][])
* [#3783](https://github.com/bbatsov/rubocop/pull/3783): Maintain parentheses in `Rails/HttpPositionalArguments` when methods are defined with them. ([@kevindew][])
* [#3786](https://github.com/bbatsov/rubocop/pull/3786): Avoid crash `Style/ConditionalAssignment` cop with mass assign method. ([@pocke][])
* [#3749](https://github.com/bbatsov/rubocop/pull/3749): Detect corner case of `Style/NumericLitterals`. ([@kamaradclimber][])

## 0.46.0 (2016-11-30)

Expand Down Expand Up @@ -2524,6 +2525,7 @@
[@bronson]: https://github.com/bronson
[@albus522]: https://github.com/albus522
[@sihu]: https://github.com/sihu
[@kamaradclimber]: https://github.com/kamaradclimber
[@swcraig]: https://github.com/swcraig
[@jessieay]: https://github.com/jessieay
[@tiagocasanovapt]: https://github.com/tiagocasanovapt
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/numeric_literals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check(node)
case int
when /^\d+$/
add_offense(node, :expression) { self.max = int.size + 1 }
when /\d{4}/, /_\d{1,2}_/
when /\d{4}/, /_\d{1,2}(_|$)/
add_offense(node, :expression) do
self.config_to_allow_offenses = { 'Enabled' => false }
end
Expand Down
5 changes: 3 additions & 2 deletions spec/rubocop/cop/style/numeric_literals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
end

it 'registers an offense for an integer with misplaced underscore' do
inspect_source(cop, 'a = 123_456_78_90_00')
expect(cop.offenses.size).to eq(1)
inspect_source(cop, ['a = 123_456_78_90_00',
'b = 819_2'])
expect(cop.offenses.size).to eq(2)
expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
end

Expand Down