Skip to content
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

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

xFrednet
Copy link
Member

@xFrednet xFrednet commented Sep 2, 2023

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 2, 2023
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
Comment on lines 23 to 26
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(...).

tests/ui/join_absolute_paths.rs Outdated Show resolved Hide resolved
tests/ui/join_absolute_paths.rs Show resolved Hide resolved
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('\\'))
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

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 ?

Copy link
Member Author

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?

clippy_lints/src/methods/join_absolute_paths.rs Outdated Show resolved Hide resolved
@Centri3
Copy link
Member

Centri3 commented Sep 3, 2023

Everything looks fine to me, minus the nits. CI seems to agree too.

@ofeeg
Copy link
Contributor

ofeeg commented Sep 4, 2023

Looks like it all got figured out. Sorry for the trouble.

@bors
Copy link
Contributor

bors commented Sep 15, 2023

☔ The latest upstream changes (presumably #11483) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Oct 26, 2023

☔ The latest upstream changes (presumably #11698) made this pull request unmergeable. Please resolve the merge conflicts.

@xFrednet
Copy link
Member Author

xFrednet commented Nov 10, 2023

I've rebased and moved the lint to suspicious, the rest should be the same as before

I say as the CI fails... And everything should be fixed now

@xFrednet
Copy link
Member Author

@Centri3 Seems to be busy lately, @blyxyas would you mind taking over the review?

r? @blyxyas

@rustbot rustbot assigned blyxyas and unassigned Centri3 Nov 13, 2023
Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meow

clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/join_absolute_paths.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/join_absolute_paths.rs Outdated Show resolved Hide resolved
Copy link
Member

@blyxyas blyxyas left a 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.

@xFrednet
Copy link
Member Author

Meow @blyxyas

  ^~^  ,
 ('Y') )
 /   \/ 
(\|||/)

/// let new = Path::new("/sh");
/// assert_eq!(new, PathBuf::from("/sh"));
/// ```
#[clippy::version = "1.75.0"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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]>
@blyxyas
Copy link
Member

blyxyas commented Nov 20, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Nov 20, 2023

📌 Commit 34d9e88 has been approved by blyxyas

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 20, 2023

⌛ Testing commit 34d9e88 with merge 11a2eb0...

@bors
Copy link
Contributor

bors commented Nov 20, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: blyxyas
Pushing 11a2eb0 to master...

@bors bors merged commit 11a2eb0 into rust-lang:master Nov 20, 2023
8 checks passed
@xFrednet xFrednet deleted the 11208-path-join-correct branch November 20, 2023 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect path join with hardcoded absolute path
7 participants