-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
New lint clippy::join_absolute_paths
#11453
Conversation
diag | ||
.note("joining a path starting with separator will replace the path instead") | ||
.help("if this is unintentional, try removing the starting separator") | ||
.help("if this is intentional, try creating a new Path instead"); |
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.
diag | |
.note("joining a path starting with separator will replace the path instead") | |
.help("if this is unintentional, try removing the starting separator") | |
.help("if this is intentional, try creating a new Path instead"); | |
diag.note("joining a path starting with separator will replace the path instead") | |
.help("if this is unintentional, try removing the starting separator") | |
.help("if this is intentional, try creating a new Path instead"); |
Still a bit weird in terms of formatting. I also think we should also add suggestions here instead of just .help(...)
.
if is_type_diagnostic_item(cx, ty, Path) | ||
&& let ExprKind::Lit(spanned) = &join_arg.kind | ||
&& let LitKind::Str(symbol, _) = spanned.node | ||
&& (symbol.as_str().starts_with('/') || symbol.as_str().starts_with('\\')) |
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.
Does \\
do this on unix as well? Or is it normalized to /
immediately? If it doesn't, we could say this behavior would only be present on windows to remove any potential confusion.
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.
On unix it just accepts it as a file name
let path = Path::new("C:\\Users");
let path2 = path.join("\\Ducks");
println!("{path2:#?}"); -> "C:\\Users/\\Ducks"
This behavior actually makes sense to me. I'll add a note to the lint description. I wouldn't add it to the lint emission, as it's already quite verbose.
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.
Can we use [has_root](https://github.com/rust-lang/rust-clippy/pull/11453#method.has_root)
to check ?
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.
@lengyijun I assume you mean Path::has_root()
?
I don't think that it would be good to be platform specific here. I can imagine that several projects just run Clippy on linux without specifying --all-targets
. This assumption comes from the fact that I often forget to specify that flag in the CI. There might also be users, who only run Clippy locally. However, this can lead to false positives, even if I don't believe that anybody wants to start their folder name with \\
on linux. So, I think we should keep the current behavior, but move the lint to suspicious
, to have the lint warn by default and not deny. Does that sound good to everyone?
Everything looks fine to me, minus the nits. CI seems to agree too. |
Looks like it all got figured out. Sorry for the trouble. |
☔ The latest upstream changes (presumably #11483) made this pull request unmergeable. Please resolve the merge conflicts. |
e129b5d
to
1a024eb
Compare
☔ The latest upstream changes (presumably #11698) made this pull request unmergeable. Please resolve the merge conflicts. |
1a024eb
to
7d69ac6
Compare
I've rebased and moved the lint to I say as the CI fails... And everything should be fixed now |
7d69ac6
to
b9433a6
Compare
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.
Meow
f79f6ae
to
952934b
Compare
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.
LGTM, thanks! ❤️
Could you squash these and add a Co-Authored-By: ofeeg <[email protected]>
to the commit message, in honor of those who are no longer listed as authors.
952934b
to
148d200
Compare
Meow @blyxyas
|
clippy_lints/src/methods/mod.rs
Outdated
/// let new = Path::new("/sh"); | ||
/// assert_eq!(new, PathBuf::from("/sh")); | ||
/// ``` | ||
#[clippy::version = "1.75.0"] |
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.
#[clippy::version = "1.75.0"] | |
#[clippy::version = "1.76.0"] |
* `join_absolute_paths` Address PR review * Move `clippy::join_absolute_paths` to `clippy::suspicious` * `join_absolute_paths`: Address PR review Co-Authored-By: ofeeg <[email protected]>
148d200
to
34d9e88
Compare
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Hey @ofeeg, this PR is a copy of all the changes you did in 47171d3 from PR #11208. I wasn't sure how to fix the git history. Hope you're okay with me figuring this out in this separate PR
changelog: New lint [
join_absolute_paths
]#11453
Closes: #10655
r? @Centri3 Since you also gave feedback on the other PR. I hope that I copied everything correctly, but a third pair of eyes would be appreciated :D