Skip to content

Commit

Permalink
Enable symmetrical braces for arrays and hashes (rubocop#3085)
Browse files Browse the repository at this point in the history
As discussed in rubocop#2914 this change enables
`Style/MultilineArrayBraceLayout` and `Style/MultilineHashBraceLayout`
with `EnforcedStyle: symmetrical` by default.

All existing RuboCop code has been auto-corrected.
  • Loading branch information
panthomakos authored and Neodelf committed Oct 15, 2016
1 parent 5612c14 commit c91b74d
Show file tree
Hide file tree
Showing 39 changed files with 313 additions and 527 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* [#3025](https://github.com/bbatsov/rubocop/pull/3025): Removed deprecation warnings for `rubocop-todo.yml`. ([@ptarjan][])
* [#3028](https://github.com/bbatsov/rubocop/pull/3028): Add `define_method` to the default list of `IgnoredMethods` of `Style/SymbolProc`. ([@jastkand][])
* [#3064](https://github.com/bbatsov/rubocop/pull/3064): `Style/SpaceAfterNot` highlights the entire expression instead of just the exlamation mark. ([@rrosenblum][])
* [#3085](https://github.com/bbatsov/rubocop/pull/3085): Enable `Style/MultilineArrayBraceLayout` and `Style/MultilineHashBraceLayout` with the `symmetrical` style by default. ([@panthomakos][])

## 0.39.0 (2016-03-27)

Expand Down
21 changes: 21 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,16 @@ Style/MethodName:
- snake_case
- camelCase

Style/MultilineArrayBraceLayout:
EnforcedStyle: symmetrical
SupportedStyles:
# symmetrical: closing brace is positioned in same way as opening brace
# new_line: closing brace is always on a new line
# same_line: closing brace is always on the same line as last element
- symmetrical
- new_line
- same_line

Style/MultilineAssignmentLayout:
# The types of assignments which are subject to this rule.
SupportedTypes:
Expand All @@ -655,6 +665,17 @@ Style/MultilineAssignmentLayout:
# for the set of supported types.
- new_line

Style/MultilineHashBraceLayout:
EnforcedStyle: symmetrical
SupportedStyles:
# symmetrical: closing brace is positioned in same way as opening brace
# new_line: closing brace is always on a new line
# same_line: closing brace is always on same line as last element
- symmetrical
- new_line
- same_line


Style/MultilineMethodCallIndentation:
EnforcedStyle: aligned
SupportedStyles:
Expand Down
30 changes: 0 additions & 30 deletions config/disabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,11 @@ Style/MissingElse:
- case
- both

Style/MultilineArrayBraceLayout:
Description: >-
Checks that the closing brace in an array literal is
either on the same line as the last array element, or
a new line.
Enabled: false
EnforcedStyle: symmetrical
SupportedStyles:
# symmetrical: closing brace is positioned in same way as opening brace
# new_line: closing brace is always on a new line
# same_line: closing brace is always on the same line as last element
- symmetrical
- new_line
- same_line

Style/MultilineAssignmentLayout:
Description: 'Check for a newline after the assignment operator in multi-line assignments.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-conditional-assignment'
Enabled: false

Style/MultilineHashBraceLayout:
Description: >-
Checks that the closing brace in a hash literal is
either on the same line as the last hash element, or
a new line.
Enabled: false
EnforcedStyle: symmetrical
SupportedStyles:
# symmetrical: closing brace is positioned in same way as opening brace
# new_line: closing brace is always on a new line
# same_line: closing brace is always on same line as last element
- symmetrical
- new_line
- same_line

Style/MultilineMethodCallBraceLayout:
Description: >-
Checks that the closing brace in a method call is
Expand Down
14 changes: 14 additions & 0 deletions config/enabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ Style/ModuleFunction:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function'
Enabled: true

Style/MultilineArrayBraceLayout:
Description: >-
Checks that the closing brace in an array literal is
either on the same line as the last array element, or
a new line.
Enabled: true

Style/MultilineBlockChain:
Description: 'Avoid multi-line chains of blocks.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
Expand All @@ -424,6 +431,13 @@ Style/MultilineBlockLayout:
Description: 'Ensures newlines after multiline block do statements.'
Enabled: true

Style/MultilineHashBraceLayout:
Description: >-
Checks that the closing brace in a hash literal is
either on the same line as the last hash element, or
a new line.
Enabled: true

Style/MultilineIfThen:
Description: 'Do not use then for multi-line if/unless.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then'
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/not.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Not < Cop
:<= => :>,
:> => :<=,
:< => :>=,
:>= => :< }.freeze
:>= => :<
}.freeze

def on_send(node)
return unless node.keyword_not?
Expand Down
3 changes: 1 addition & 2 deletions spec/rubocop/cli/cli_autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,7 @@ def abs(path)
' },',
' ]',
'end',
'end'
])
'end'])
expect(cli.run(['--auto-correct'])).to eq(1)
expect(IO.read('example.rb'))
.to eq(['# encoding: utf-8',
Expand Down
9 changes: 5 additions & 4 deletions spec/rubocop/cli/cli_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ def abs(path)
.to eq(["For #{abs('')}:" \
" configuration from #{home}/config/default.yml",
"Inheriting configuration from #{home}/config/enabled.yml",
"Inheriting configuration from #{home}/config/disabled.yml"
])
"Inheriting configuration from #{home}/config/disabled.yml"])
end

it 'shows cop names' do
Expand Down Expand Up @@ -1052,7 +1051,8 @@ def finished(processed_files)
"stdlib 'English' module over $/.",
'',
'1 file inspected, 1 offense detected',
''].join("\n"))
''
].join("\n"))
ensure
$stdin = STDIN
end
Expand Down Expand Up @@ -1104,7 +1104,8 @@ def finished(processed_files)
'',
'1 file inspected, 1 offense detected, 1 offense corrected',
'====================',
'p $INPUT_RECORD_SEPARATOR'].join("\n"))
'p $INPUT_RECORD_SEPARATOR'
].join("\n"))
ensure
$stdin = STDIN
end
Expand Down
72 changes: 24 additions & 48 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ def interrupt

it 'can disable all cops on a single line' do
create_file('example.rb', ['# encoding: utf-8',
'y("123", 123456) # rubocop:disable all'
])
'y("123", 123456) # rubocop:disable all'])
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
expect($stdout.string).to be_empty
end
Expand All @@ -314,8 +313,7 @@ def interrupt
'a' * 90 + ' # rubocop:disable Metrics/LineLength',
'#' * 95,
'y("123", 123456) # rubocop:disable Style/StringLiterals,' \
'Style/NumericLiterals'
])
'Style/NumericLiterals'])
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
expect($stdout.string)
.to eq(["#{abs('example.rb')}:3:81: C: Line is too long. [95/80]",
Expand All @@ -328,8 +326,7 @@ def interrupt
['# encoding: utf-8',
'a' * 90 + ' # rubocop:disable LineLength',
'#' * 95,
'y("123") # rubocop:disable StringLiterals'
])
'y("123") # rubocop:disable StringLiterals'])
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
expect($stdout.string)
.to eq(["#{abs('example.rb')}:3:81: C: Line is too long. [95/80]",
Expand Down Expand Up @@ -403,8 +400,7 @@ def interrupt
create_file('example', ['#!/usr/bin/env ruby',
'# encoding: utf-8',
'x = 0',
'puts x'
])
'puts x'])
expect(cli.run(%w(--format simple))).to eq(0)
expect($stdout.string)
.to eq(['', '1 file inspected, no offenses detected', ''].join("\n"))
Expand Down Expand Up @@ -794,8 +790,7 @@ def interrupt
it 'allows the default configuration file as the -c argument' do
create_file('example.rb', ['# encoding: utf-8',
'x = 0',
'puts x'
])
'puts x'])
create_file('.rubocop.yml', [])

expect(cli.run(%w(--format simple -c .rubocop.yml))).to eq(0)
Expand Down Expand Up @@ -883,8 +878,7 @@ def interrupt
' - example',
' - "**/*.rake"',
' - !ruby/regexp /regexp$/',
' - .dot1/**/*'
])
' - .dot1/**/*'])
expect(cli.run(%w(--format files))).to eq(1)
expect($stderr.string).to eq('')
expect($stdout.string.split($RS).sort).to eq([abs('.dot1/file.rb'),
Expand All @@ -896,23 +890,19 @@ def interrupt
it 'ignores excluded files' do
create_file('example.rb', ['# encoding: utf-8',
'x = 0',
'puts x'
])
'puts x'])
create_file('regexp.rb', ['# encoding: utf-8',
'x = 0',
'puts x'
])
'puts x'])
create_file('exclude_glob.rb', ['#!/usr/bin/env ruby',
'# encoding: utf-8',
'x = 0',
'puts x'
])
'puts x'])
create_file('.rubocop.yml', ['AllCops:',
' Exclude:',
' - example.rb',
' - !ruby/regexp /regexp.rb$/',
' - "exclude_*"'
])
' - "exclude_*"'])
expect(cli.run(%w(--format simple))).to eq(0)
expect($stdout.string)
.to eq(['', '0 files inspected, no offenses detected',
Expand Down Expand Up @@ -964,14 +954,12 @@ def interrupt
it 'matches included/excluded files correctly when . argument is given' do
create_file('example.rb', 'x = 0')
create_file('special.dsl', ['# encoding: utf-8',
'setup { "stuff" }'
])
'setup { "stuff" }'])
create_file('.rubocop.yml', ['AllCops:',
' Include:',
' - "*.dsl"',
' Exclude:',
' - example.rb'
])
' - example.rb'])
expect(cli.run(%w(--format simple .))).to eq(1)
expect($stdout.string)
.to eq(['== special.dsl ==',
Expand All @@ -987,8 +975,7 @@ def interrupt
it 'does not read files in excluded list', broken: :rbx do
%w(rb.rb non-rb.ext without-ext).each do |filename|
create_file("example/ignored/#{filename}", ['# encoding: utf-8',
'#' * 90
])
'#' * 90])
end

create_file('example/.rubocop.yml', ['AllCops:',
Expand Down Expand Up @@ -1045,8 +1032,7 @@ def interrupt
' Enabled: false',
'',
'Lint/AmbiguousOperator:',
' Enabled: false'
])
' Enabled: false'])
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
end

Expand All @@ -1056,8 +1042,7 @@ def interrupt
' Enabled: false',
'',
'Syntax:',
' Enabled: false'
])
' Enabled: false'])
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(2)
expect($stderr.string).to include(
'Error: configuration for Syntax cop found')
Expand Down Expand Up @@ -1125,8 +1110,7 @@ def interrupt
' Enabled: false',
'',
'Metrics/LineLength:',
' Enabled: false'
])
' Enabled: false'])
result = cli.run(['--format', 'simple',
'-c', 'rubocop.yml', 'example1.rb'])
expect($stdout.string)
Expand All @@ -1146,8 +1130,7 @@ def interrupt
' Enabled: false',
'',
'Style/CaseIndentation:',
' Enabled: false'
])
' Enabled: false'])
expect(cli.run(['--format', 'simple',
'example_src/example1.rb'])).to eq(1)
expect($stdout.string)
Expand All @@ -1160,12 +1143,10 @@ def interrupt

it 'can use an alternative max line length from a config file' do
create_file('example_src/example1.rb', ['# encoding: utf-8',
'#' * 90
])
'#' * 90])
create_file('example_src/.rubocop.yml', ['Metrics/LineLength:',
' Enabled: true',
' Max: 100'
])
' Max: 100'])
expect(cli.run(['--format', 'simple',
'example_src/example1.rb'])).to eq(0)
expect($stdout.string)
Expand All @@ -1175,13 +1156,11 @@ def interrupt
it 'can have different config files in different directories' do
%w(src lib).each do |dir|
create_file("example/#{dir}/example1.rb", ['# encoding: utf-8',
'#' * 90
])
'#' * 90])
end
create_file('example/src/.rubocop.yml', ['Metrics/LineLength:',
' Enabled: true',
' Max: 100'
])
' Max: 100'])
expect(cli.run(%w(--format simple example))).to eq(1)
expect($stdout.string).to eq(['== example/lib/example1.rb ==',
'C: 2: 81: Line is too long. [90/80]',
Expand All @@ -1192,16 +1171,13 @@ def interrupt

it 'prefers a config file in ancestor directory to another in home' do
create_file('example_src/example1.rb', ['# encoding: utf-8',
'#' * 90
])
'#' * 90])
create_file('example_src/.rubocop.yml', ['Metrics/LineLength:',
' Enabled: true',
' Max: 100'
])
' Max: 100'])
create_file("#{Dir.home}/.rubocop.yml", ['Metrics/LineLength:',
' Enabled: true',
' Max: 80'
])
' Max: 80'])
expect(cli.run(['--format', 'simple',
'example_src/example1.rb'])).to eq(0)
expect($stdout.string)
Expand Down
Loading

0 comments on commit c91b74d

Please sign in to comment.