Skip to content

Commit

Permalink
Merge pull request rubocop#2983 from dylanahsmith/fixed-indent-params…
Browse files Browse the repository at this point in the history
…-message

Style/AlignParameters: Clarify the message for with_fixed_indentation style
  • Loading branch information
bbatsov committed Mar 29, 2016
2 parents 1473da4 + a7654e0 commit 5c6f9de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#2983](https://github.com/bbatsov/rubocop/pull/2983): `Style/AlignParameters` message was clarified for `with_fixed_indentation` style. ([@dylanahsmith][])

## 0.39.0 (27/03/2016)

### New features
Expand Down Expand Up @@ -2082,3 +2086,4 @@
[@necojackarc]: https://github.com/necojackarc
[@laurelfan]: https://github.com/laurelfan
[@amuino]: https://github.com/amuino
[@dylanahsmith]: https://github.com/dylanahsmith
10 changes: 8 additions & 2 deletions lib/rubocop/cop/style/align_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class AlignParameters < Cop
include AutocorrectAlignment
include OnMethodDef

ALIGN_PARAMS_MSG = 'Align the parameters of a method %s if they span ' \
'more than one line.'.freeze

FIXED_INDENT_MSG = 'Use one level of indentation for parameters ' \
'following the first line of a multi-line method %s.'.freeze

def on_send(node)
_receiver, method, *args = *node

Expand All @@ -27,8 +33,8 @@ def on_method_def(node, _method_name, args, _body)

def message(node)
type = node && node.parent.send_type? ? 'call' : 'definition'
"Align the parameters of a method #{type} if they span " \
'more than one line.'
msg = fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
format(msg, type)
end

private
Expand Down
5 changes: 4 additions & 1 deletion spec/rubocop/cop/style/align_parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@
' b)',
'end'])
expect(cop.offenses.size).to eq 1
expect(cop.offenses.first.to_s).to match(/method definition/)
expect(cop.messages)
.to eq(['Use one level of indentation for parameters ' \
'following the first line of a multi-line method ' \
'definition.'])
end

it 'registers an offense for parameters with double indent' do
Expand Down

0 comments on commit 5c6f9de

Please sign in to comment.