Rust-clippy: consider passing `--cfg test` by default

Created on 11 Jan 2017  路  6Comments  路  Source: rust-lang/rust-clippy

Posted by @durka in https://github.com/arcnmx/cargo-clippy/issues/12

Regular cargo clippy doesn't check #[test] functions because it can't (the code is gone by the time the lints run). But if you do cargo clippy -- --cfg test it works. I wonder if there are any downsides to making this the default behavior.

I guess this breaks people who have #[cfg(not(test))] on things. But perhaps cargo-clippy can support a --test flag which would be a bit shorter than -- --cfg test.

C-needs-discussion

Most helpful comment

Try invoking clippy as cargo clippy --tests.

All 6 comments

I think test code needs not by necessity follow the same strict guidelines that clippy requires of other code. On the other hand there is certainly value in having clippy check tests, too, so I wouldn't rule it out.

The best way would be to somehow run both with and without --cfg test, collect the reports and quell duplicates before output. This would also reduce duplicates due to the library/binary divide.

Note that -- --cfg test fails if there are dev-dependencies since they aren't available with just the flag.

It seems there is no good way to run clippy on tests anymore? Compiler plugin is deprecated and --cfg test won't work with dev-dependencies.

Are there any news about this?
I don't think it should be enabled by default but I do thing that --cfg test should use dev-dependencies

Try invoking clippy as cargo clippy --tests.

@oli-obk This can be closed now I think.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pickfire picture pickfire  路  3Comments

vitorenesduarte picture vitorenesduarte  路  3Comments

spease picture spease  路  3Comments

f-fr picture f-fr  路  3Comments

0e4ef622 picture 0e4ef622  路  3Comments