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

Fix IfUnlessModifier's co-operation with LineLength in edge cases #7507

Conversation

jonas054
Copy link
Collaborator

There's a lot of complexity in how Metrics/LineLength handles various exceptions regarding long lines. The best way for Style/IfUnlessModifier to avoid false positives on long lines is to share code with Metrics/LineLength and thus always have the same idea about which lines are too long.

@jonas054 jonas054 force-pushed the fix_IfUnlessModifier_vs_LineLength_edge_cases branch from db69f25 to b75b608 Compare November 16, 2019 07:54
@jonas054 jonas054 force-pushed the fix_IfUnlessModifier_vs_LineLength_edge_cases branch from b75b608 to 1b39d3e Compare November 24, 2019 08:44
@jonas054
Copy link
Collaborator Author

Rebased and resolved conflicts. I would love some reviews. :)
Cc: @jfelchner @maxim

@jonas054 jonas054 requested a review from koic November 24, 2019 08:56
module RuboCop
module Cop
# Help methods for determining if a line is too long.
class LineLengthHelp
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd use a different name here, as we haven't used the SomethingHelp pattern anywhere else. I also noticed you haven't used this class as a mixin, even though it's in the mixin dir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are actually a couple of mixin modules with names ending in Help: RangeHelp, StringHelp, and StringLiteralsHelp. Only the last one is in the mixin directory, but I think that's because it's the only one used from multiple departments. So since I can't think of a better name than Help, and since there is some precedent, I propose to keep the name.

The placement of a class in mixin is not ideal, I can see that. There is a utils namespace where we could put it, but I'm not sure if that's better. Maybe I can just discard the commit that changes the module into a class? Using composition instead of inheritance doesn't make a huge difference in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are actually a couple of mixin modules with names ending in Help: RangeHelp, StringHelp, and StringLiteralsHelp. Only the last one is in the mixin directory, but I think that's because it's the only one used from multiple departments. So since I can't think of a better name than Help, and since there is some precedent, I propose to keep the name.

Ah, I totally forgot about those. Fair enough.

The placement of a class in mixin is not ideal, I can see that. There is a utils namespace where we could put it, but I'm not sure if that's better. Maybe I can just discard the commit that changes the module into a class? Using composition instead of inheritance doesn't make a huge difference in this case.

I'll leave this up to you. I don't have any strong preferences here. If it weren't for the delegation I'd say this was an util, but now it's hard to decide. OOP is way too complex. :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I just took a look and it looks great. And for what it's worth I generally prefer composition over inheritance. ;)

…odifier

Extract some code that can detect lines that are too long with all the special
cases that are controlled through configuration parameters of the
Metrics/LineLength cop.

The code that is moved to the LineLengthHelp mixin can then be used in
IfUnlessModifier so that it only reports lines on modifier form that are too
long when the LineLength cop would report them.
@jonas054 jonas054 force-pushed the fix_IfUnlessModifier_vs_LineLength_edge_cases branch from 1b39d3e to bfdda17 Compare November 27, 2019 20:44
@jfelchner
Copy link
Contributor

@jonas054 thank you for this. ❤

@jonas054 jonas054 removed the request for review from koic December 5, 2019 17:15
@jonas054
Copy link
Collaborator Author

jonas054 commented Dec 5, 2019

@bbatsov I removed @koic as reviewer now that you and @jfelchner have both looked at it. I addressed your concerns about the class placed under mixin by making it a module. Then I forgot about this PR. 🙂 Should be OK to merge now, I think.

@bbatsov bbatsov merged commit e524404 into rubocop:master Dec 5, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 5, 2019

Agreed. Thanks!

@jonas054 jonas054 deleted the fix_IfUnlessModifier_vs_LineLength_edge_cases branch December 8, 2019 09:56
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.

None yet

3 participants