-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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 guideline about empty strings inside interpolation. #952
base: master
Are you sure you want to change the base?
Conversation
I apologise for the pluralism of opinions. It doesn’t seem that we need a rule for a case like this. It is stylistic, quite unfrequent I believe, and some may say they prefer it explicit. Not to say that it has nothing to do with interpolation specifically, it’s just hard to detect other similar cases with static analysis, eg |
I searched on github for the two forms listed in the PR: Given the scale of rubocop, I do not know if this counts as frequent, but it is at least relevant information. As to your point about the rule being stylistic, is that not the point of the ruby style guide? I'm open to discussion on whether this style is preferred, but I presumed it being a stylistic choice does not disqualify it from inclusion. |
This is a confirmation that both styles take place. |
The modifier if form is shorter, and only contains the relevant logic, while the ternary form has redundant logic for assigning an empty string. |
Is being shorter a goal?
What do you mean by “assigning”? In general, I’m not against the cop. A more generic rule could sound like:
But I still think it’s not worth adding such a guideline. |
If code can be made more concise without sacrificing readability, performance or functionality, then yes, I think making it shorter is a goal.
Assigning is probably the wrong word-- stating? creating?
I was told to open a PR, and it was my understanding that Style cops should have equivalent rules in the style guide. If that's not the case, I'm happy to close this PR and just focus on the cop itself. |
Don’t we sacrifice readability here by making it return a nil implicitly?
Returning? |
This style guide is not only about style, despite its name. I tend to agree that every cop should have a rationale behind it, but there are so many cops that putting this all into the style guide will make the style guide hard to read. Off the top of my head, I can’t tell what the rule of adding vs not adding a guideline is. As far as I know, for rubocop-rails and rails-style-guide there is always a guideline that backs the cop. Not something I know of other extensions or the main style guide. |
i see it like this: the fact that nothing happens if the condition isn't true is, to me, self-evident in the modifier form, and so it is unnecessary to state it by using the ternary form. I think its probably just personal opinion, though.
I wasn't thinking in terms of performance, just in terms of code clarity. |
🤷 I thought a PR for the style guide would be mandatory for a style cop. My bad. Some general advice for the github code search: append It's 40%/60% which is pretty close. I would say that not everyone will agree with the shorter version. Ruby has some constructs that look a bit weird when compared to other languages and I would count using
You don't need that first assignment but at least for me it looks pretty weird without it. I feel similar about this cop. |
As per rubocop/rubocop#13266.