-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
CodeLength incorrectly calculated when there are kwargs that should be counted as one #10469
Comments
[Fix #10469] Fix code length calculation when kwargs written in single line
#10520 fixes just a specific case. If the node is multiline, but still starts at the line of the parent node, it still gives the wrong result
The actual of the above is -1 |
I'm sorry for I didn't enough consider about coverage of cases 🙏 Do the following examples cover all cases for this issue? # pattern 1
def test
foo(
foo: :bar,
baz: :quux
)
end
# pattern 2
def test
foo(foo: :bar, baz: :quux)
end
# pattern 3
def test
foo(foo: :bar,
baz: :quux)
end
# pattern 4
def test
foo(
foo: :bar, baz: :quux
)
end |
That's alright - you have improved the calculation nevertheless. Just haven't fully resolved the issue
Thank you 🙇
Seems exhaustive enough. Well, if you want to go to extremes:
Though it's not clear whether we should count the comment as part of the hash or not 🤷♂️ |
I created PR (#10543) for this. I'd be happy if you take a look at it :) |
Fixed in #10543 |
When there are keyword arguments, and the configuration says that hashes should be counted as one line, the code length module calculates the length incorrectly, by always subtracting 2.
I tracked the issue down to the
Metrics::Utils::CodeLengthCalculator
which includes this lineThis is valid in this example:
But not this one:
As a reproduction spec:
This gives a result of -1
RuboCop version
Tested on master
The text was updated successfully, but these errors were encountered: