Skip to content

Commit 7dea554

Browse files
committed
[Fix #14123] Fix an error for Lint/BooleanSymbol
This PR fixes an infinite loop error for `Lint/BooleanSymbol` when using the rocket hash syntax with a boolean symbol key. Fixes #14123.
1 parent 4a61156 commit 7dea554

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#14123](https://github.com/rubocop/rubocop/issues/14123): Fix an infinite loop error for `Lint/BooleanSymbol` when using the rocket hash syntax with a boolean symbol key. ([@koic][])

lib/rubocop/cop/lint/boolean_symbol.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def on_sym(node)
4848
def autocorrect(corrector, node)
4949
boolean_literal = node.source.delete(':')
5050
parent = node.parent
51-
if parent&.pair_type? && node.equal?(parent.children[0])
51+
if parent&.pair_type? && parent.colon? && node.equal?(parent.children[0])
5252
corrector.remove(parent.loc.operator)
5353
boolean_literal = "#{node.source} =>"
5454
end

spec/rubocop/cop/lint/boolean_symbol_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
RUBY
2424
end
2525

26+
context 'when using the rocket hash syntax' do
27+
it 'registers an offense when using a boolean symbol key' do
28+
expect_offense(<<~RUBY)
29+
{ :false => 42 }
30+
^^^^^^ Symbol with a boolean name - you probably meant to use `false`.
31+
RUBY
32+
33+
expect_correction(<<~RUBY)
34+
{ false => 42 }
35+
RUBY
36+
end
37+
end
38+
2639
context 'when using the new hash syntax' do
2740
it 'registers an offense when using `true:`' do
2841
expect_offense(<<~RUBY)

0 commit comments

Comments
 (0)