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
Style/StringConcatenation: flexibility settings #8470
Comments
Are you suggesting to not raise offense for your second example, or to raise but not auto-correct that? Because there's an argument for # bad
"http://" + fetch_domain(some, params, with: COMPLEX[calculation]) + "/endpoint"
# good
domain = fetch_domain(some, params, with: COMPLEX[calculation])
"http://#{domain}/endpoint" We can't autocorrect this way, of course, but I feel an offense is still justified. |
Probably "provide (some) method of limiting the offenses only to atomic (?) clauses, or to clauses of some Probably, "do not autocorrect when there is complex expressions, but still raise" might be a sutiable compromise. |
@marcandre I'd love the 2nd example to raise but not autocorrect, because I've run into some weird autocorrections, such as if Rails.env.production?
"/#{id}"
else
"dev/#{id}"
end + '/video' becoming "#{if Rails.env.production?
"/#{id}"
else
"dev/#{id}"
end}/video" Which is wrong for a number of reasons. I'd rather just fix it by extracting a variable, as you suggested. |
I'm 👍 in keeping offenses but adding some criteria so auto-correction does not happen. I'm thinking these should imply no correction:
(PR for this welcome) I'm personally less enthusiastic about adding config options in general / judgement about length / other complexity of code, or not raising offenses, but the right examples may be persuade me or other people |
@marcandre sure! I'll try to put together a PR. |
…n if any of the parts are too complex. Complex includes multiline statements, heredocs, nested interpolations and expressions with blocks.
…y of the parts are too complex. Complex includes multiline statements, heredocs, nested interpolations and expressions with blocks.
New
Style/StringConcatenation
is obviously useful, but it seems it needs more flexibility to not harm code readability.For example,
"http://" + domain
→"http://#{domain}"
is a good suggestion, but
"http://" + fetch_domain(some, params, with: COMPLEX[calculation]) + "/endpoint"
is more vague.
Maybe it would make sense to limit the suggestion by either concatenated expression character count, or by its complexity (number of sub-expressions or something)?..
The text was updated successfully, but these errors were encountered: