Skip to content

Commit

Permalink
Merge pull request #7871 from knu/fix_boolean_symbol_autocorrection
Browse files Browse the repository at this point in the history
Fix an auto-correction bug in Lint/BooleanSymbol
  • Loading branch information
koic committed Apr 13, 2020
2 parents c65a232 + 851784b commit ba598be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@

### Bug fixes

* [#7871](https://github.com/rubocop-hq/rubocop/pull/7871): Fix an auto-correction bug in `Lint/BooleanSymbol`. ([@knu][])
* [#7842](https://github.com/rubocop-hq/rubocop/issues/7842): Fix a false positive for `Lint/RaiseException` when raising Exception with explicit namespace. ([@koic][])
* [#7834](https://github.com/rubocop-hq/rubocop/issues/7834): Fix `Lint/UriRegexp` to register offense with array arguments. ([@tejasbubane][])
* [#7841](https://github.com/rubocop-hq/rubocop/issues/7841): Fix an error for `Style/TrailingCommaInBlockArgs` when lambda literal (`->`) has multiple arguments. ([@koic][])
Expand Down Expand Up @@ -4447,3 +4448,4 @@
[@yuritomanek]: https://github.com/yuritomanek
[@egze]: https://github.com/egze
[@rafaelfranca]: https://github.com/rafaelfranca
[@knu]: https://github.com/knu
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/boolean_symbol.rb
Expand Up @@ -37,7 +37,7 @@ def autocorrect(node)
lambda do |corrector|
boolean_literal = node.source.delete(':')
parent = node.parent
if parent&.pair_type?
if parent&.pair_type? && node.equal?(parent.children[0])
corrector.remove(parent.loc.operator)
boolean_literal = "#{node.source} =>"
end
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/lint/boolean_symbol_spec.rb
Expand Up @@ -47,6 +47,18 @@
{ false => :bar }
RUBY
end

it 'registers an offense when using `key: :false`' do
expect_offense(<<~RUBY)
{ false: :false }
^^^^^^ Symbol with a boolean name - you probably meant to use `false`.
^^^^^ Symbol with a boolean name - you probably meant to use `false`.
RUBY

expect_correction(<<~RUBY)
{ false => false }
RUBY
end
end

it 'does not register an offense when using regular symbol' do
Expand Down

0 comments on commit ba598be

Please sign in to comment.