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

unwrap_used lint fires for #[test]ing code #5805

Open
jplatte opened this issue Jul 16, 2020 · 4 comments
Open

unwrap_used lint fires for #[test]ing code #5805

jplatte opened this issue Jul 16, 2020 · 4 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jplatte
Copy link
Contributor

jplatte commented Jul 16, 2020

It would be nice if there was a lint that fired on unwraps inside regular code, but not in #[test] (or #[cfg(test)]?) code, potentially just the existing unwrap_used lint.

  • Do you think this is desireable as the default behaviour of unwrap_used or should it likely be a separate lint?
  • Would this be hard to implement (i.e. how hard is it for clippy to tell whether some code is under #[test] / #[cfg(test)]?
@flip1995
Copy link
Member

how hard is it for clippy to tell whether some code is under #[test] / #[cfg(test)]

We can only approximate this. We already doing this in the wildcard_imports lint. We approximate this by checking if we're currently inside a module called *test* (has the string test in its name).

The reason, we cannot check this is because when Clippy runs its lints the #[cfg(test)] attributes are already resolved by rustc and the code is either erased from the AST or it exists (without any attributes).

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Jul 16, 2020
@flip1995
Copy link
Member

We could make it configurable, so that it can be disabled in tests completely (with the heuristic described above)

@chansuke
Copy link
Contributor

I'd like to work on this but my idea is that configure the method on top of fn check_fn() in clippy_lints/src/unwrap.rs.

@Firionus
Copy link

Firionus commented Oct 8, 2022

I think this can be closed since there now is #8802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants