-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Suggest handling case insensitivity on .ends_with(".ext") #6425
Comments
If we should lint this, we should only lint the case, where |
So like, the lint should trigger only on this kind of thing? // filename: Path
filename.ends_with(".ext") Probably nobody is going to write this code, because The reason for this is that If it would produce too many false positive's to have the lint trigger on strings, I don't think there's any purpose left for this lint suggestion. |
Oh, yeah you're right. Don't know what I was thinking here 😅 Anyway, I would classify this lint as |
You mean, keep the original proposed behavior of triggering on |
Yes. And if on nightly suggest to convert the string to a path and suggest the path method. |
Closes rust-lang#6425 Looks for ends_with methods calls with case sensitive extensions.
Closes rust-lang#6425 Looks for ends_with methods calls with case sensitive extensions.
Closes rust-lang#6425 Looks for ends_with methods calls with case sensitive extensions.
Closes rust-lang#6425 Looks for ends_with methods calls with case sensitive extensions.
…llogiq Case sensitive file extensions Closes #6425 Looks for ends_with methods calls with case sensitive extension comparisons. changelog: Add new lint that warns about case-sensitive file extension comparisons.
That usage of |
What it does
When
.ends_with()
is called on a String or &str, and the parameter looks like a file extension (regex\.([a-z0-9]{1,5})|([A-Z0-9]{1,5})
), inform the programmer that this code will not handle differently-cased filenames well - potentially a bug. Additionally, a correct replacement is suggested (see below).Categories
clippy::pedantic
or perhapsclippy::correctness
What is the advantage of the recommended code over the original code
It handles file extensions correctly regardless of case. In Windows, this behavior is very much expected since the entire operating system has case-insensitive filenames. In Linux, filenames are usually case-sensitive, but I think even on Linux, it's standard behavior to recognize file extensions regardless of case.
Drawbacks
.ends_with(".ext")
might not be a file extension check at all. It could mean something else for which case-sensitivity makes senseExample
Could be written as:
Or like this (nightly-only because of
Path::eq_ignore_ascii_case
):The text was updated successfully, but these errors were encountered: