Skip to content

Commit 987259e

Browse files
authored
Layout/Space inside Hash Literal Braces: no space (#116)
* Layout/Space inside Hash Literal Braces: no space This differentiates from block syntax where there should be space inside the delimiters, and mirrors other collection literals, where no space is placed inside their delimiters, keeping a consistent communication. * Uses the changed opinion from Rubocop for Hash Effectively executed `rubocop --except Metrics -c .rubocop.yml` to update files according to the opinion change. Closes: #114
1 parent 48be539 commit 987259e

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

.rubocop.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ Layout/LineLength:
3131
- "test/exercises/*"
3232
- "lib/analyzers/*/analyze.rb"
3333

34+
Layout/SpaceInsideHashLiteralBraces:
35+
Description: "Use spaces inside hash literal braces - or don't."
36+
StyleGuide: '#spaces-braces'
37+
Enabled: true
38+
VersionAdded: '0.49'
39+
EnforcedStyle: no_space
40+
SupportedStyles:
41+
- space
42+
- no_space
43+
# 'compact' normally requires a space inside hash braces, with the exception
44+
# that successive left braces or right braces are collapsed together
45+
- compact
46+
EnforcedStyleForEmptyBraces: no_space
47+
SupportedStylesForEmptyBraces:
48+
- space
49+
- no_space
50+
3451
Lint/SuppressedException:
3552
Exclude:
3653
- "test/**/*"

lib/analyzers/acronym/representation.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def uses_method_chain?
1111
},
1212
{
1313
method_name: :map,
14-
arguments: [{ to_ast: s(:block_pass, s(:sym, :chr)) }],
14+
arguments: [{to_ast: s(:block_pass, s(:sym, :chr))}],
1515
chained?: true
1616
},
1717
{
@@ -22,7 +22,7 @@ def uses_method_chain?
2222
method_name: :tr,
2323
receiver: ArbitraryLvar.new,
2424
chained?: true,
25-
arguments: [{ to_ast: s(:str, "-") }, { to_ast: s(:str, " ") }]
25+
arguments: [{to_ast: s(:str, "-")}, {to_ast: s(:str, " ")}]
2626
}
2727
]
2828

@@ -56,7 +56,7 @@ def uses_method_chain_with_block?
5656
method_name: :tr,
5757
receiver: ArbitraryLvar.new,
5858
chained?: true,
59-
arguments: [{ to_ast: s(:str, "-") }, { to_ast: s(:str, " ") }]
59+
arguments: [{to_ast: s(:str, "-")}, {to_ast: s(:str, " ")}]
6060
},
6161
{
6262
method_name: :chr,
@@ -80,7 +80,7 @@ def uses_scan?
8080
method_name: :scan,
8181
receiver: ArbitraryLvar.new,
8282
chained?: true,
83-
arguments: [{ type: :regexp }]
83+
arguments: [{type: :regexp}]
8484
}
8585
]
8686

@@ -99,12 +99,12 @@ def uses_split?
9999
{
100100
method_name: :map,
101101
chained?: true,
102-
arguments: [{ to_ast: s(:block_pass, s(:sym, :chr)) }]
102+
arguments: [{to_ast: s(:block_pass, s(:sym, :chr))}]
103103
},
104104
{
105105
method_name: :split,
106106
receiver: ArbitraryLvar.new,
107-
arguments: [{ type: :regexp }]
107+
arguments: [{type: :regexp}]
108108
}
109109
]
110110

lib/analyzers/two_fer/analyze.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def check_structure!
5151
# is sane and that it has valid arguments
5252
def check_method_signature!
5353
disapprove!(:missing_default_param) unless solution.has_one_parameter?
54-
disapprove!(:splat_args, { name_variable: solution.first_parameter_name }) if solution.uses_splat_args?
54+
disapprove!(:splat_args, {name_variable: solution.first_parameter_name}) if solution.uses_splat_args?
5555
disapprove!(:missing_default_param) unless solution.first_paramater_has_default_value?
5656
end
5757

@@ -77,25 +77,25 @@ def check_for_single_line_solution!
7777

7878
if solution.uses_string_interpolation?
7979
if solution.string_interpolation_is_correct?
80-
approve_if_implicit_return!(:string_interpolation, { name_variable: solution.first_parameter_name })
80+
approve_if_implicit_return!(:string_interpolation, {name_variable: solution.first_parameter_name})
8181
else
8282
refer_to_mentor!
8383
end
8484
end
8585

8686
# "One for " + name + ", one for me."
8787
if solution.uses_string_concatenation?
88-
approve_if_implicit_return!(:string_concatenation, { name_variable: solution.first_parameter_name })
88+
approve_if_implicit_return!(:string_concatenation, {name_variable: solution.first_parameter_name})
8989
end
9090

9191
# format("One for %s, one for me.", name)
9292
if solution.uses_kernel_format?
93-
approve_if_implicit_return!(:kernel_format, { name_variable: solution.first_parameter_name })
93+
approve_if_implicit_return!(:kernel_format, {name_variable: solution.first_parameter_name})
9494
end
9595

9696
# "One for %s, one for me." % name
9797
if solution.uses_string_format?
98-
approve_if_implicit_return!(:string_format, { name_variable: solution.first_parameter_name })
98+
approve_if_implicit_return!(:string_format, {name_variable: solution.first_parameter_name})
9999
end
100100

101101
# If we have a one-line method that passes the tests, then it's not
@@ -161,7 +161,7 @@ def approve_if_implicit_return!(msg = nil, params = {})
161161

162162
def approve_if_whitespace_is_sensible!(msg = nil, params = {})
163163
if solution.indentation_is_sensible?
164-
self.comments << { comment: MESSAGES[msg], params: } if msg
164+
self.comments << {comment: MESSAGES[msg], params:} if msg
165165
self.status = :approve
166166

167167
raise FinishedFlowControlException
@@ -180,7 +180,7 @@ def refer_to_mentor!
180180
def disapprove!(msg, params = {})
181181
self.status = :disapprove
182182
self.comments << if params.length > 0
183-
{ comment: MESSAGES[msg], params: }
183+
{comment: MESSAGES[msg], params:}
184184
else
185185
MESSAGES[msg]
186186
end

test/exercises/two_fer_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def self.two_fer(*foos)
139139
}
140140
results = TwoFer::Analyze.(source)
141141
assert_equal :disapprove, results[:status]
142-
assert_equal [{ comment: "ruby.two-fer.splat_args", params: { name_variable: :foos } }], results[:comments]
142+
assert_equal [{comment: "ruby.two-fer.splat_args", params: {name_variable: :foos}}], results[:comments]
143143
end
144144

145145
# ###
@@ -156,7 +156,7 @@ def self.two_fer(name="you")
156156
'
157157
results = TwoFer::Analyze.(source)
158158
assert_equal :approve, results[:status]
159-
assert_equal [{ comment: "ruby.two-fer.string_concatenation", params: { name_variable: :name } }], results[:comments]
159+
assert_equal [{comment: "ruby.two-fer.string_concatenation", params: {name_variable: :name}}], results[:comments]
160160
end
161161

162162
def test_string_interpolation_passes
@@ -169,7 +169,7 @@ def self.two_fer(name="you")
169169
}
170170
results = TwoFer::Analyze.(source)
171171
assert_equal :approve, results[:status]
172-
assert_equal [{ comment: "ruby.two-fer.string_interpolation", params: { name_variable: :name } }], results[:comments]
172+
assert_equal [{comment: "ruby.two-fer.string_interpolation", params: {name_variable: :name}}], results[:comments]
173173
end
174174

175175
def test_for_kernel_format
@@ -183,7 +183,7 @@ def self.two_fer(name="you")
183183
'
184184
results = TwoFer::Analyze.(source)
185185
assert_equal :approve, results[:status]
186-
assert_equal [{ comment: "ruby.two-fer.kernel_format", params: { name_variable: :name } }], results[:comments]
186+
assert_equal [{comment: "ruby.two-fer.kernel_format", params: {name_variable: :name}}], results[:comments]
187187
end
188188

189189
def test_for_string_format
@@ -197,7 +197,7 @@ def self.two_fer(name="you")
197197
'
198198
results = TwoFer::Analyze.(source)
199199
assert_equal :approve, results[:status]
200-
assert_equal [{ comment: "ruby.two-fer.string_format", params: { name_variable: :name } }], results[:comments]
200+
assert_equal [{comment: "ruby.two-fer.string_format", params: {name_variable: :name}}], results[:comments]
201201
end
202202

203203
def test_conditional_as_boolean

0 commit comments

Comments
 (0)