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

Allow use super::*; glob imports #5564

Merged
merged 10 commits into from
May 9, 2020
Merged

Allow use super::*; glob imports #5564

merged 10 commits into from
May 9, 2020

Conversation

MrAwesome
Copy link
Contributor

@MrAwesome MrAwesome commented May 3, 2020

changelog: Allow super::* glob imports

fixes #5554
fixes #5569

A first pass at #5554 - this allows all use super::* to pass, which may or may not be desirable. The original issue was around allowing test modules to import their entire parent modules - I'm happy to modify this to do that instead, may just need some guidance on how to implement that (I played around a bit with #[cfg(test)] but from what I can gather, clippy itself isn't in test mode when running, even if the code in question is being checked for the test target).

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

A good heuristic would be to check if the name of module we're currently in, contains the string "test". You can do this by setting a flag self.in_test_module = true in a check_item function and reset it in check_item_post. Documentation: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.BuiltinCombinedLateLintPass.html#method.check_item_post

clippy_lints/src/wildcard_imports.rs Outdated Show resolved Hide resolved
@flip1995
Copy link
Member

flip1995 commented May 3, 2020

You cannot check for the cfg(test) attribute, since cfg/cfg_attrs don't exist anymore in the HIR.

@flip1995 flip1995 added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label May 3, 2020
@dylni
Copy link

dylni commented May 3, 2020

Since wildcard_imports is starting to warn in less cases, should it have a configuration variable to always warn? That would also help make the documentation clearer about it not warning in all cases by default.

@flip1995
Copy link
Member

flip1995 commented May 3, 2020

We could add this, yes

@MrAwesome
Copy link
Contributor Author

Updated to check for "test" in the parent module name. I ended up doing this inline for simplicity's sake, happy to set a field on WildcardImports if that seems better.

@MrAwesome MrAwesome requested a review from flip1995 May 7, 2020 15:04
@flip1995
Copy link
Member

flip1995 commented May 7, 2020

I ended up doing this inline for simplicity's sake, happy to set a field on WildcardImports if that seems better.

That was my first idea when I reviewed this PR too. But that doesn't work, if the super import isn't directly in the main module. And allowing use super::* in test functions seems reasonable too. Playground for test case.

@flip1995
Copy link
Member

flip1995 commented May 7, 2020

Better than a bool would be to add a counter how many test modules deep the lint check is, so it doesn't start linting in test modules again, just because a submodule is also called *test*.

@MrAwesome
Copy link
Contributor Author

Updated to check for "test" in parent module/function names.

@dylni I also went ahead and added the flag for #5569 since I'm already warmed up on the code.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Thanks for also implementing #5569!

clippy_lints/src/wildcard_imports.rs Outdated Show resolved Hide resolved
clippy_lints/src/wildcard_imports.rs Outdated Show resolved Hide resolved
clippy_lints/src/wildcard_imports.rs Outdated Show resolved Hide resolved
@MrAwesome
Copy link
Contributor Author

Okay, updated to remove that field and check the itemkind. I checked for either fn or mod, should I do just mod?

Also - are there docs I should update as well?

@dylni
Copy link

dylni commented May 9, 2020

@MrAwesome Thanks! It's great to see it will be available immediately with this PR.

@MrAwesome MrAwesome requested a review from flip1995 May 9, 2020 06:09
@flip1995
Copy link
Member

flip1995 commented May 9, 2020

Yes please exclude Fn here, since test is a pretty common string in a method name, like test_for_xyz, IMO.

@MrAwesome
Copy link
Contributor Author

Updated to use Mod only, reflected that in the tests, and updated the docs to reflect all the new functionality.

clippy_lints/src/wildcard_imports.rs Outdated Show resolved Hide resolved
clippy_lints/src/wildcard_imports.rs Outdated Show resolved Hide resolved
@MrAwesome MrAwesome requested a review from flip1995 May 9, 2020 17:11
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Please rebase on top of master to get rid of the merge commits.

@MrAwesome
Copy link
Contributor Author

This look correct? Most of my experience is with Mercurial so I want to make extra sure I don't cause some weird repo state.

@flip1995
Copy link
Member

flip1995 commented May 9, 2020

Perfect, thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented May 9, 2020

📌 Commit b69200b has been approved by flip1995

@bors
Copy link
Collaborator

bors commented May 9, 2020

⌛ Testing commit b69200b with merge 43a1777...

@bors
Copy link
Collaborator

bors commented May 9, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 43a1777 to master...

@bors bors merged commit 43a1777 into rust-lang:master May 9, 2020
@bors bors mentioned this pull request May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration variable for wildcard_imports to always warn Allow use super::*; in test modules
4 participants