Skip to content

Commit a91f28a

Browse files
committed
do not convert to shrothand syntax for hash rocket
1 parent 7bf168d commit a91f28a

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

lib/ruby/shorthand_hash_syntax.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# { a: a, b: b, c: c, d: d + 4 }
2626
# =>
2727
# { a:, b:, c:, d: d + 4 }
28-
find_node '.hash_node .assoc_node[key=.symbol_node][key.unescaped="{{value}}"]' do
28+
find_node '.hash_node .assoc_node[key=.symbol_node][key.unescaped="{{value}}"][operator=nil]' do
2929
replace_with '{{key}}'
3030
end
3131

spec/ruby/shorthand_hash_syntax_spec.rb

+29-15
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@
55
RSpec.describe 'Uses ruby 3.1 shorthand hash synax' do
66
let(:rewriter_name) { 'ruby/shorthand_hash_syntax' }
77

8-
let(:test_content) { <<~EOS }
9-
{ a: a, b: b, c: c, d: d + 4 }
10-
some_method(a: a, b: b, c: c, d: d + 4)
11-
some_method(:a => a, :b => b, :c => c, :d => d + 4)
12-
some_method a: a, b: b, c: c, d: d + 4
13-
EOS
14-
15-
let(:test_rewritten_content) { <<~EOS }
16-
{ a:, b:, c:, d: d + 4 }
17-
some_method(a:, b:, c:, d: d + 4)
18-
some_method(:a => a, :b => b, :c => c, :d => d + 4)
19-
some_method a: a, b: b, c: c, d: d + 4
20-
EOS
21-
22-
include_examples 'convertable'
8+
context 'new hash syntax' do
9+
let(:test_content) { <<~EOS }
10+
{ a: a, b: b, c: c, d: d + 4 }
11+
some_method(a: a, b: b, c: c, d: d + 4)
12+
some_method(:a => a, :b => b, :c => c, :d => d + 4)
13+
some_method a: a, b: b, c: c, d: d + 4
14+
EOS
15+
16+
let(:test_rewritten_content) { <<~EOS }
17+
{ a:, b:, c:, d: d + 4 }
18+
some_method(a:, b:, c:, d: d + 4)
19+
some_method(:a => a, :b => b, :c => c, :d => d + 4)
20+
some_method a: a, b: b, c: c, d: d + 4
21+
EOS
22+
23+
include_examples 'convertable'
24+
end
25+
26+
context 'hash rocket syntax' do
27+
let(:test_content) { <<~EOS }
28+
{ :a => a, :b => b, :c => c, :d => d + 4 }
29+
EOS
30+
31+
let(:test_rewritten_content) { <<~EOS }
32+
{ :a => a, :b => b, :c => c, :d => d + 4 }
33+
EOS
34+
35+
include_examples 'convertable'
36+
end
2337
end

0 commit comments

Comments
 (0)