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

Add non_octal_unix_permissions lint #7001

Merged
merged 1 commit into from
Mar 30, 2021

Conversation

ebobrow
Copy link
Contributor

@ebobrow ebobrow commented Mar 29, 2021

fixes #6934

changelog: add new lint that checks for non-octal values used to set unix file permissions

@rust-highfive
Copy link

r? @Manishearth

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 29, 2021
if let ExprKind::Path(ref path) = func.kind;
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::PERMISSIONS_FROM_MODE);

Copy link
Member

Choose a reason for hiding this comment

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

We should only be linting if its parameter is a literal

_ => return,
};

if !snip.starts_with("0o") {
Copy link
Member

Choose a reason for hiding this comment

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

show_error should not be doing additional checks relevant to the lint IMO, these should be in the main lint

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 29, 2021

@Manishearth Thanks for the review! I've applied the changes. Should I also be checking for a case where the parameter is a variable holding a non-octal value, like:

let permissions = 440;
let mut options = OpenOptions::new();
options.mode(permissions);

It seems to me like a pretty rare use case, but I could be wrong. Thoughts?

@Manishearth
Copy link
Member

I would rather not try to lint for that

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 29, 2021

Okay, I won't do that then. Can you re-review my changes?

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

📌 Commit 724ac87 has been approved by Manishearth

bors added a commit that referenced this pull request Mar 30, 2021
Add non_octal_unix_permissions lint

fixes #6934

changelog: add new lint that checks for non-octal values used to set unix file permissions
@bors
Copy link
Collaborator

bors commented Mar 30, 2021

⌛ Testing commit 724ac87 with merge 945d831...

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

💔 Test failed - checks-action_test

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 30, 2021

Hopefully this fixes the error.

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

📌 Commit 01b89aa has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

⌛ Testing commit 01b89aa with merge 17a6be6...

bors added a commit that referenced this pull request Mar 30, 2021
Add non_octal_unix_permissions lint

fixes #6934

changelog: add new lint that checks for non-octal values used to set unix file permissions
@bors
Copy link
Collaborator

bors commented Mar 30, 2021

💔 Test failed - checks-action_test

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 30, 2021

@Manishearth I might need some help with this. It looks like the test is failing on windows because of the unix-specific features. I thought that adding #[cfg(target_family = "unix")] would fix it, but that didn't work. Do you have any ideas?

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Use // ignore-windows at the top of the test

@@ -1057,6 +1059,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
store.register_late_pass(|| box default_numeric_fallback::DefaultNumericFallback);
store.register_late_pass(|| box inconsistent_struct_constructor::InconsistentStructConstructor);
#[cfg(target_family = "unix")]
Copy link
Member

Choose a reason for hiding this comment

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

Don't do this

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 30, 2021

Thank you!

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

📌 Commit 9f8cb2d has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

⌛ Testing commit 9f8cb2d with merge 7130bd3...

bors added a commit that referenced this pull request Mar 30, 2021
Add non_octal_unix_permissions lint

fixes #6934

changelog: add new lint that checks for non-octal values used to set unix file permissions
@bors
Copy link
Collaborator

bors commented Mar 30, 2021

💔 Test failed - checks-action_test

@Manishearth
Copy link
Member

Unsure why ignore-windows isn't working. @oli-obk any idea?

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 30, 2021

It looks like it did work. This time the error is coming from the example in declare_clippy_lint. Should I just add ignore so it doesn't run the test?

@Manishearth
Copy link
Member

I think we want to run the test on Linux at least

@Manishearth
Copy link
Member

@bors try

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

⌛ Trying commit 81598f3 with merge a3d8d65...

bors added a commit that referenced this pull request Mar 30, 2021
Add non_octal_unix_permissions lint

fixes #6934

changelog: add new lint that checks for non-octal values used to set unix file permissions
@bors
Copy link
Collaborator

bors commented Mar 30, 2021

💔 Test failed - checks-action_test

@ebobrow
Copy link
Contributor Author

ebobrow commented Mar 30, 2021

ignore-windows should work in doc tests too, right? Could it be because I added # to hide it?

@Manishearth
Copy link
Member

Oh! that's a doctest! no, it won't work; I think you should just rust,ignore it.

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

📌 Commit 7fcd155 has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

⌛ Testing commit 7fcd155 with merge 4be72b0...

@bors
Copy link
Collaborator

bors commented Mar 30, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing 4be72b0 to master...

@bors bors merged commit 4be72b0 into rust-lang:master Mar 30, 2021
@ebobrow ebobrow deleted the non-octal-file-permissions branch March 30, 2021 23:41
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.

New lint: Unix permissions set to a non-octal value
4 participants