Add new include_file_outside_project lint#13638
Add new include_file_outside_project lint#13638GuillaumeGomez wants to merge 3 commits intorust-lang:masterfrom
include_file_outside_project lint#13638Conversation
4bbdba4 to
a404546
Compare
|
It seems like the error is kinda legit. The file is indeed outside of the (lintcheck) project. Anyway, let's first see if you anyone has an idea on how to add a ui test for this lint. |
|
Suggestion: Make this lint check |
It would be good if this lint respected the But also, I'm a bit confused as to why the lint thinks that all packages include Is the problem with ui tests that the cargo manifest dir is set to rust-clippy and there would be no file to use in the test? We have |
|
Looking a bit more into it, seems like |
|
☔ The latest upstream changes (presumably #13376) made this pull request unmergeable. Please resolve the merge conflicts. |
Good idea!
True. However, if this is pushed on a (git) repository, I suppose the problem is the same. But I think it can be done as a follow-up. For now, let's only warn on
Thanks, gonna add a check for that. |
61eb990 to
a7a2b12
Compare
a7a2b12 to
0a0187a
Compare
0a0187a to
7dd55d4
Compare
dcb5724 to
5c70532
Compare
5c70532 to
d6dc48d
Compare
|
Found a way to add a ui test. PR should be ready now. :) |
|
r? clippy |
| match MetadataCommand::new().no_deps().exec() { | ||
| Ok(metadata) => { | ||
| for package in &metadata.packages { | ||
| // only run the lint if publish is `None` (`publish = true` or skipped entirely) | ||
| // or if the vector isn't empty (`publish = ["something"]`) | ||
| if !matches!(package.publish.as_deref(), Some([]) | None) { | ||
| can_check_crate = false; | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
This would have to be a cargo lint if it's doing this to deduplicate the cargo metadata invocation and so it doesn't happen by default
But I don't think we need to here, cargo publish already copies the project files into target/package/crate-x.y.z before checking it builds, which would catch most ../../outside-the-project includes
The case that it wouldn't catch is an include of an absolute path, but it seems reasonable to lint these unconditionally
|
☔ The latest upstream changes (possibly d28d234) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Ping @GuillaumeGomez from triage. Do you intend to return to working on this? I'm going to agree with @Alexendoo. We really don't want to run |
|
I do but likely directly inside rustc or cargo. I kept it open to have it inside my TODO list. ^^' |
So there is one issue with this lint: how to actually test it.
I wrote a test locally to check it works:
main.rs:/home/me/bar.rs:/home/me/foo.rs:Which outputs when I run
cargo dev lint main.rs:changelog: Add new
include_file_outside_projectlint