-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add consistent_relative_to_receiver to FirstParameterIndentation #5699
Add consistent_relative_to_receiver to FirstParameterIndentation #5699
Conversation
@bbatsov @jonas054 @rrosenblum @Drenmi if one of you could help me out, I need some assistance getting this over the finish line. There are two tests failing on this branch. The assertions are correct. I believe that what's happening is the I just don't know enough about some of the Rubocop helpers/internals to know what the best approach to take is here. If someone could help me out with this, between this PR and #5698 we should be able to close out around 8-10 issues. 👍 |
I'd say that's a bug in whatever style. :-) I'm overloaded with work, but I'll take a look at this when I can if someone else doesn't beat me to it. We can also ask for help @garettarrowood, @pocke and @koic. |
CHANGELOG.md
Outdated
@@ -5,6 +5,7 @@ | |||
### New features | |||
|
|||
* [#5597](https://github.com/bbatsov/rubocop/pull/5597): Add new `Rails/HttpStatus` cop. ([@anthony-robin][]) | |||
* [#5699](https://github.com/bbatsov/rubocop/pull/5699): Add `consistent_relative_to_receiver` style option to `Layout/FirstParameterIndentation` ([@jfelchner][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One failure is that this entry doesn't end with punctation. Adding a period will resolve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will see if I can give the meaningful failures a closer look this weekend. I've also been swamped and haven't been able to give rubocop
the attention I'd like to over the past couple months.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was speaking more about the test failures.
@jfelchner What's happening in the failing tests is that the auto-correction of one line changes how another line needs to be aligned. This is something that we solve in RuboCop by running cops repeatedly until no more correctable offenses are found. But we can't do it within a single run of a cop. So I recommend you change these examples to one offense only. |
@bbatsov rebased onto |
There are multiple valid issues with people complaining about how FirstParameterIndentation's chosen correction is not very readable. Examples: ```ruby MyClass.my_method(a_hash.merge( hello: :world, some: :hash, goes: :here ), other_arg) MyClass.my_method(a_hash.merge( hello: :world, some: :hash, goes: :here ), other_arg) ``` ```ruby good3 = foo.methA( :arg1, :arg2, options: :hash, ) .methB( :arg1, :arg2, ) .methC good3 = foo.methA( :arg1, :arg2, options: :hash, ) .methB( :arg1, :arg2, ) .methC ``` ```ruby price = default_price * NightsCalculator.new( start_date, end_date).nights_count price = default_price * NightsCalculator.new( start_date, end_date).nights_count ``` This pull request introduces a new style to the cop called `consistent_relative_to_receiver` which will always align the first parameter relative to the receiver/parent node instead of looking at the line's indentation. References: #5650, #4308, #3204, #2625
@bbatsov rebased to fix conflicts |
@bbatsov did you want additional changes here before merging? |
Nope. Thanks! 👍 |
Follow up of rubocop#4880 (comment) and rubocop#5699. This commit is a change of document format for `Layout/FirstParameterIndentation` cop. This PR uses `# rubocop:disable Metrics/LineLength` because line length of the following line exceeds 80. ```diff + # @example EnforcedStyle: special_for_inner_method_call_in_parentheses (default) ``` Descriptions of `EnforcedStyle` are quoted from default.yml. https://github.com/rubocop-hq/rubocop/blob/v0.57.1/config/default.yml#L365-L381
Follow up of #4880 (comment) and #5699. This commit is a change of document format for `Layout/FirstParameterIndentation` cop. This PR uses `# rubocop:disable Metrics/LineLength` because line length of the following line exceeds 80. ```diff + # @example EnforcedStyle: special_for_inner_method_call_in_parentheses (default) ``` Descriptions of `EnforcedStyle` are quoted from default.yml. https://github.com/rubocop-hq/rubocop/blob/v0.57.1/config/default.yml#L365-L381
There are multiple valid issues with people complaining about how
FirstParameterIndentation
's chosen correction is not very readable.This pull request introduces a new style to the cop called
consistent_relative_to_receiver
which will always align the first parameter relative to the receiver/parent node instead of looking at the line's indentation.Examples:
Issue #4308
Actual
vs Expected
Issue #5650
Actual
vs Expected
Issue #2625
Actual
vs Expected
References: #5650, #4308, #3204, #2625
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake default
orrake parallel
. It executes all tests and RuboCop for itself, and generates the documentation.