Skip to content

Commit

Permalink
Merge pull request #273 from jonas054/fix_multiline_hash_literal_bug
Browse files Browse the repository at this point in the history
Always allow line breaks inside hash literal braces.
  • Loading branch information
bbatsov committed Jun 13, 2013
2 parents 8b6363a + 6dfca00 commit ed2932b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* [#246](https://github.com/bbatsov/rubocop/issues/246) - correct handling of unicode escapes within double quotes
* Fix crashes in Blocks, CaseEquality, CaseIndentation, ClassAndModuleCamelCase, ClassMethods, CollectionMethods, and ColonMethodCall.
* [#263](https://github.com/bbatsov/rubocop/issues/263) - do not check for space around operators called with method syntax
* [#271](https://github.com/bbatsov/rubocop/issues/271) - always allow line breaks inside hash literal braces

## 0.8.2 (06/05/2013)

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/surrounding_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def check(t1, t2)
types = [t1, t2].map(&:type)
braces = [:tLBRACE, :tRCURLY]
return if types == braces || (braces - types).size == 2
return if t1.pos.line < t2.pos.line # No offence if line break inside.
has_space = space_between?(t1, t2)
is_offence, word = if self.class.config['EnforcedStyleIsWithSpaces']
[!has_space, 'missing']
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ module Cop
expect(sihlb.offences.map(&:message)).to be_empty
end

it 'accepts multiline hashes even if configured for no space' do
SpaceInsideHashLiteralBraces.config['EnforcedStyleIsWithSpaces'] =
false
inspect_source(sihlb,
['h = {',
' a: 1,',
' b: 2,',
'}'])
expect(sihlb.offences).to be_empty
end

it 'accepts empty hashes without spaces by default' do
inspect_source(sihlb, ['h = {}'])
expect(sihlb.offences).to be_empty
Expand Down

0 comments on commit ed2932b

Please sign in to comment.