Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style/AlignParameters: Clarify the message for with_fixed_indentation style. #2983

Merged
merged 1 commit into from
Mar 29, 2016

Conversation

dylanahsmith
Copy link
Contributor

Problem

When using the following in .rubocop.yml

Style/AlignParameters:
  EnforcedStyle: with_fixed_indentation

code like

method_call(arg1,
            arg2)

results in the offense message

tmp/style.rb:2:13: C: Align the parameters of a method call if they span more than one line.
            arg2)
            ^^^^

which is confusing, since the parameters of the method call are aligned.

Solution

I changed the error message when using the with_fixed_indentation AlignParameters style to be the following for the above case to make it clearer what is wrong

tmp/style.rb:2:13: C: Use one level of indentation for parameters following the first line of a multi-line method call
            arg2)
            ^^^^

@@ -504,7 +504,9 @@
' b)',
'end'])
expect(cop.offenses.size).to eq 1
expect(cop.offenses.first.to_s).to match(/method definition/)
expect(cop.offenses.map(&:to_s))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offense.map... -> cop.messages

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure why you decided to place the check in this particular example. Seems it should have been done closer to the beginning of the fixed-indent context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beginning of the fixed-indent context tests are autocorrections. The only previous fixed indent test that expected offenses was a double indentation test that expected 3 offenses. This was also the first fixed indent test to have an assertion on the error message. It was also a very relevant example to the problem this pull request addresses.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 25, 2016

Good catch. I've added some small remarks inline. Also - please, update the commit message to follow our conventions.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 26, 2016

You'll also have to rebase on top of the current master.

@dylanahsmith
Copy link
Contributor Author

Rebased and updated the commit message, so hopefully it matches you conventions now.

@@ -25,6 +25,7 @@
* [#2967](https://github.com/bbatsov/rubocop/pull/2967): Fix auto-correcting of `===`, `<=`, and `>=` in `Style/ConditionalAssignment`. ([@rrosenblum][])
* [#2977](https://github.com/bbatsov/rubocop/issues/2977): Fix auto-correcting of `"#{$!}"` in `Style/SpecialGlobalVars`. ([@lumeet][])
* [#2935](https://github.com/bbatsov/rubocop/issues/2935): Make configuration loading work if `SafeYAML.load` is private. ([@jonas054][])
* [#2983](https://github.com/bbatsov/rubocop/pull/2983): `Style/AlignParameters` message was clarified for `with_fixed_indentation` style. ([@dylanahsmith][])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should move this to the master section as 0.39 was recently released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to a new Bug fixes section under master

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 28, 2016

Apart from my remark about the changelog and the failing build, everything looks good.

@dylanahsmith dylanahsmith force-pushed the fixed-indent-params-message branch 2 times, most recently from ab73c04 to b4ff9e7 Compare March 28, 2016 23:09
Change the error message so it is clear that the alignment isn't with the
first parameter but with the line containing the first parameter with one
extra level of indentation.
@dylanahsmith
Copy link
Contributor Author

CI is passing again

@bbatsov bbatsov merged commit 5c6f9de into rubocop:master Mar 29, 2016
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 29, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants