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

Add MaxLength parameter to IfUnlessModifier and WhileUntilModifier #795

Merged
merged 1 commit into from
Feb 17, 2014

Conversation

agrimm
Copy link
Contributor

@agrimm agrimm commented Feb 4, 2014

Currently, if you have a high value for Max in LineLength, then the IfUnlessModifier and WhileUntilModifier cops will suggest a modifier style, even if it results in a very long line.

This change means you can specify a maximum length for these specific cops.

@yujinakayama
Copy link
Collaborator

👍 Actually I've been thinking same thing. :)

@yujinakayama
Copy link
Collaborator

I think the parameter name MaxLength is a bit ambiguous.

IfUnlessModifier:
  MaxLength: 80 # Length of what?

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 4, 2014

Yep, MaxConditionLineLength (or something similar) makes more sense.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 4, 2014

I also wonder if it makes sense to add some config regarding the complexity of the condition - this could make the cop accept conditions with && and || regardless of other factors.

# this would normally be an offence, but it has an `&&` in it
if something && something_else
  do_something
end

This is based on an observation of mine that some people like to use the modifier forms only for conditions that consist of a single expression.

@jonas054
Copy link
Collaborator

jonas054 commented Feb 4, 2014

MaxLineLength would be enough in my opinion. The cop wants the conditional statement to be rewritten as one line, so it's pretty clear what length the parameter refers to. Especially if we write a comment about it. Which leads me to my additional concern.

This is the first parameter we introduce that doesn't have a default value. This means that

  • it's not visible in default.yml
  • it's not included in the output from rubocop --show-cops

I'm thinking about where to describe it. The parameter is a bit hidden. One solution would be to set a default value of 79 in config/default.yml. Or a special value such as "LineLength/Max" or null to indicate that it gets its value from another cop.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 4, 2014

I think that a default value of 79 is a good enough (and pretty simple) solution.

@agrimm
Copy link
Contributor Author

agrimm commented Feb 5, 2014

I'm happy with a more verbose parameter name, such as MaxLineLength.

I agree that 79 as a default value is a good enough solution.

I won't be able to implement && or || - I'll leave that to someone more familiar with the code.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 5, 2014

@agrimm OK. Let me you know when you've updated the PR.

@yujinakayama
Copy link
Collaborator

👍 for MaxLineLength.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 12, 2014

@agrimm Ping :-)

@agrimm
Copy link
Contributor Author

agrimm commented Feb 12, 2014

Been a bit busy, but my Ukrainian revolution is finished now. :)

An updated PR should be ready by the end of this weekend.

@mockdeep
Copy link
Contributor

Ha, I was just going to open an issue for this. I usually do single line, but wrap it into a block if it's over 80 characters.

…r, so that their own maximum line length can be set
@agrimm
Copy link
Contributor Author

agrimm commented Feb 16, 2014

@bbatsov Pong :-)

bbatsov added a commit that referenced this pull request Feb 17, 2014
Add MaxLength parameter to IfUnlessModifier and WhileUntilModifier
@bbatsov bbatsov merged commit cff52c6 into rubocop:master Feb 17, 2014
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 17, 2014

Thanks!

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.

5 participants