-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New rule to prevent implicit string concatenation in collections #21972
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
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ISC004 | 342 | 342 | 0 | 0 | 0 |
|
FWIW This was one of the more impactful lint rules in Fixit that prevented several serious outages at Instagram/Meta |
MichaReiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. This rule makes sense to me
crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs
Outdated
Show resolved
Hide resolved
ntBre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this looks great!
I only had one comment with a couple of small ideas, but I'm also happy with the current state of the diagnostic.
I do agree with Micha that we should make this an unsafe fix, if we keep the fix, though.
I think we should also touch base upstream. They expressed interest in adding this rule as well (flake8-implicit-str-concat/flake8-implicit-str-concat#55), so we should double check the error code to stay in sync, if we make it an ISC rule, which I think makes sense otherwise.
Have you had a chance to go through the ecosystem results? Cases like this feel a bit unfortunate to me:
assert not np.isclose(val, expected, rtol=1e-16, atol=0.0), (
f"Permittivity value test gives {val} and should not be "
f"equal to {expected}.",
)Maybe we should exclude cases with a single element?
crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs
Outdated
Show resolved
Hide resolved
|
I think I'm fine with assert not np.isclose(val, expected, rtol=1e-16, atol=0.0), (
f"Permittivity value test gives {val} and should not be "
f"equal to {expected}.",
)because the trailing |
|
Thank you both!
Like Micha says, this should be a string not a tuple. There were several accidental tuples in my work codebase, so this would be good to keep. (Most of these were asserts, we could consider a separate rule that complains about single element str tuples as assert message)
Moved it to a note, thanks!
Made it an unsafe fix, thanks!
I prefer "unparenthesized" because it makes it clearer what the lint rule wants you to do
Commented upstream
Yeah, I looked at them, felt mostly positive / expected hits to me. In a large internal codebase this has caught dozens and dozens and dozens of bugs, and is a readability improvement in most of the other cases. |
ntBre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs
Outdated
Show resolved
Hide resolved
|
Fixed, and all is green! |
|
Thanks again! I might give upstream at least until tomorrow to make sure there are no objections on the rule code (I take the 🚀 react on your comment as a positive sign), but this is otherwise good to go and should land before our release on Thursday. |
This is a common footgun, see the example in #13014 (comment)
Fixes #13014 , fixes #13031