mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Merge pull request #2712 from rust-lang-nursery/oli-obk-patch-1
Deprecate plugin-clippy
This commit is contained in:
commit
18a5b90242
43 changed files with 39 additions and 213 deletions
|
@ -152,13 +152,7 @@ Therefore you should use `tests/ui/update-all-references.sh` (after running
|
|||
Manually testing against an example file is useful if you have added some
|
||||
`println!`s and test suite output becomes unreadable. To try clippy with your
|
||||
local modifications, run `cargo run --bin clippy-driver -- -L ./target/debug input.rs` from the
|
||||
working copy root. Your test file, here `input.rs`, needs to have clippy
|
||||
enabled as a plugin:
|
||||
|
||||
```rust
|
||||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
```
|
||||
working copy root.
|
||||
|
||||
### How Clippy works
|
||||
|
||||
|
|
93
README.md
93
README.md
|
@ -71,47 +71,9 @@ similar crates.
|
|||
SYSROOT=/path/to/rustc/sysroot cargo install clippy
|
||||
```
|
||||
|
||||
### Optional dependency
|
||||
|
||||
In some cases you might want to include clippy in your project directly, as an
|
||||
optional dependency. To do this, just modify `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
clippy = { version = "*", optional = true }
|
||||
```
|
||||
|
||||
And, in your `main.rs` or `lib.rs`, add these lines:
|
||||
|
||||
```rust
|
||||
#![cfg_attr(feature="clippy", feature(plugin))]
|
||||
#![cfg_attr(feature="clippy", plugin(clippy))]
|
||||
```
|
||||
|
||||
Then build by enabling the feature: `cargo +nightly build --features "clippy"`.
|
||||
|
||||
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
|
||||
`cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy`
|
||||
(the `-Z no trans`, while not necessary, will stop the compilation process after
|
||||
typechecking (and lints) have completed, which can significantly reduce the runtime).
|
||||
|
||||
Alternatively, to only run clippy when testing:
|
||||
|
||||
```toml
|
||||
[dev-dependencies]
|
||||
clippy = { version = "*" }
|
||||
```
|
||||
|
||||
and add to `main.rs` or `lib.rs`:
|
||||
|
||||
```
|
||||
#![cfg_attr(test, feature(plugin))]
|
||||
#![cfg_attr(test, plugin(clippy))]
|
||||
```
|
||||
|
||||
### Running clippy from the command line without installing it
|
||||
|
||||
To have cargo compile your crate with clippy without clippy installation and without needing `#![plugin(clippy)]`
|
||||
To have cargo compile your crate with clippy without clippy installation
|
||||
in your code, you can use:
|
||||
|
||||
```terminal
|
||||
|
@ -121,53 +83,6 @@ cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml
|
|||
*[Note](https://github.com/rust-lang-nursery/rust-clippy/wiki#a-word-of-warning):*
|
||||
Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
|
||||
|
||||
### As a Compiler Plugin
|
||||
|
||||
*Note:* This is not a recommended installation method.
|
||||
|
||||
Since stable Rust is backwards compatible, you should be able to
|
||||
compile your stable programs with nightly Rust with clippy plugged in to
|
||||
circumvent this.
|
||||
|
||||
Add in your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
clippy = "*"
|
||||
```
|
||||
|
||||
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top
|
||||
of your crate entry point (`main.rs` or `lib.rs`).
|
||||
|
||||
Sample `main.rs`:
|
||||
|
||||
```rust
|
||||
#![feature(plugin)]
|
||||
|
||||
#![plugin(clippy)]
|
||||
|
||||
|
||||
fn main(){
|
||||
let x = Some(1u8);
|
||||
match x {
|
||||
Some(y) => println!("{:?}", y),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Produces this warning:
|
||||
|
||||
```terminal
|
||||
src/main.rs:8:5: 11:6 warning: you seem to be trying to use match for destructuring a single type. Consider using `if let`, #[warn(single_match)] on by default
|
||||
src/main.rs:8 match x {
|
||||
src/main.rs:9 Some(y) => println!("{:?}", y),
|
||||
src/main.rs:10 _ => ()
|
||||
src/main.rs:11 }
|
||||
src/main.rs:8:5: 11:6 help: Try
|
||||
if let Some(y) = x { println!("{:?}", y) }
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Some lints can be configured in a TOML file named with `clippy.toml` or `.clippy.toml`. It contains basic `variable = value` mapping eg.
|
||||
|
@ -180,12 +95,6 @@ cyclomatic-complexity-threshold = 30
|
|||
See the [list of lints](https://rust-lang-nursery.github.io/rust-clippy/master/index.html) for more information about which lints can be configured and the
|
||||
meaning of the variables.
|
||||
|
||||
You can also specify the path to the configuration file with:
|
||||
|
||||
```rust
|
||||
#![plugin(clippy(conf_file="path/to/clippy's/configuration"))]
|
||||
```
|
||||
|
||||
To deactivate the “for further information visit *lint-link*” message you can
|
||||
define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable.
|
||||
|
||||
|
|
|
@ -14,10 +14,11 @@ extern crate clippy_lints;
|
|||
pub fn plugin_registrar(reg: &mut Registry) {
|
||||
reg.sess.lint_store.with_read_lock(|lint_store| {
|
||||
for (lint, _, _) in lint_store.get_lint_groups() {
|
||||
reg.sess
|
||||
.struct_warn("the clippy plugin is being deprecated, please use cargo clippy or rls with the clippy feature")
|
||||
.emit();
|
||||
if lint == "clippy" {
|
||||
reg.sess
|
||||
.struct_warn("running cargo clippy on a crate that also imports the clippy plugin")
|
||||
.emit();
|
||||
// cargo clippy run on a crate that also uses the plugin
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy(conf_file = "./auxiliary/conf_whitelisted.toml"))]
|
|
@ -1,6 +1,3 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum Baz {
|
||||
One,
|
||||
|
@ -12,7 +9,9 @@ struct Test {
|
|||
b: Baz,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() { }
|
||||
|
||||
pub fn foo() {
|
||||
use Baz::*;
|
||||
let x = Test { t: Some(0), b: One };
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
#![deny(clippy)]
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -15,3 +13,5 @@ impl Iterator for Foo {
|
|||
}
|
||||
|
||||
impl ExactSizeIterator for Foo {}
|
||||
|
||||
fn main() {}
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
#![allow(warnings)]
|
||||
|
||||
// this should compile in a reasonable amount of time
|
|
@ -1,12 +1,11 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
#![deny(mut_mut, zero_ptr, cmp_nan)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
// compiletest + extern crates doesn't work together
|
||||
//#[macro_use]
|
||||
//extern crate lazy_static;
|
||||
|
||||
use std::collections::HashMap;
|
||||
//use std::collections::HashMap;
|
||||
|
||||
// ensure that we don't suggest `is_nan` and `is_null` inside constants
|
||||
// FIXME: once const fn is stable, suggest these functions again in constants
|
||||
|
@ -17,6 +16,7 @@ static mut BUH: bool = 42.0 < std::f32::NAN;
|
|||
|
||||
#[allow(unused_variables, unused_mut)]
|
||||
fn main() {
|
||||
/*
|
||||
lazy_static! {
|
||||
static ref MUT_MAP : HashMap<usize, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
|
@ -26,6 +26,7 @@ fn main() {
|
|||
static ref MUT_COUNT : usize = MUT_MAP.len();
|
||||
}
|
||||
assert_eq!(*MUT_COUNT, 1);
|
||||
*/
|
||||
// FIXME: don't lint in array length, requires `check_body`
|
||||
//let _ = [""; (42.0 < std::f32::NAN) as usize];
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
|
||||
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
@ -16,3 +16,5 @@ struct MacroAttributesTest {
|
|||
fn macro_attributes_test() {
|
||||
let _ = MacroAttributesTest { _foo: 0 };
|
||||
}
|
||||
|
||||
fn main() {}
|
1
tests/run-pass/whitelist/conf_whitelisted.rs
Normal file
1
tests/run-pass/whitelist/conf_whitelisted.rs
Normal file
|
@ -0,0 +1 @@
|
|||
fn main() {}
|
|
@ -1,6 +1,6 @@
|
|||
// error-pattern: error reading Clippy's configuration file
|
||||
|
||||
|
||||
#![plugin(clippy(conf_file="../ui/conf_bad_toml.toml"))]
|
||||
|
||||
|
||||
fn main() {}
|
0
tests/ui/bad_toml/conf_bad_toml.stderr
Normal file
0
tests/ui/bad_toml/conf_bad_toml.stderr
Normal file
|
@ -1,6 +1,6 @@
|
|||
// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer`
|
||||
|
||||
|
||||
#![plugin(clippy(conf_file="../ui/conf_bad_type.toml"))]
|
||||
|
||||
|
||||
fn main() {}
|
0
tests/ui/bad_toml_type/conf_bad_type.stderr
Normal file
0
tests/ui/bad_toml_type/conf_bad_type.stderr
Normal file
|
@ -1,6 +0,0 @@
|
|||
// error-pattern: `conf_file` must be a named value
|
||||
|
||||
|
||||
#![plugin(clippy(conf_file))]
|
||||
|
||||
fn main() {}
|
|
@ -1,11 +0,0 @@
|
|||
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
|
||||
--> $DIR/conf_bad_arg.rs:4:1
|
||||
|
|
||||
4 | #![plugin(clippy(conf_file))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,11 +0,0 @@
|
|||
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
|
||||
--> $DIR/conf_bad_toml.rs:4:1
|
||||
|
|
||||
4 | #![plugin(clippy(conf_file="../ui/conf_bad_toml.toml"))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,11 +0,0 @@
|
|||
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
|
||||
--> $DIR/conf_bad_type.rs:4:1
|
||||
|
|
||||
4 | #![plugin(clippy(conf_file="../ui/conf_bad_type.toml"))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,11 +0,0 @@
|
|||
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
|
||||
--> $DIR/conf_french_blacklisted_name.rs:2:1
|
||||
|
|
||||
2 | #![plugin(clippy(conf_file="../auxiliary/conf_french_blacklisted_name.toml"))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,5 +0,0 @@
|
|||
#![feature(attr_literals)]
|
||||
|
||||
#![plugin(clippy(conf_file=42))]
|
||||
|
||||
fn main() {}
|
|
@ -1,11 +0,0 @@
|
|||
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
|
||||
--> $DIR/conf_path_non_string.rs:3:1
|
||||
|
|
||||
3 | #![plugin(clippy(conf_file=42))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,11 +0,0 @@
|
|||
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
|
||||
--> $DIR/conf_unknown_key.rs:4:1
|
||||
|
|
||||
4 | #![plugin(clippy(conf_file="../auxiliary/conf_unknown_key.toml"))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(plugin)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, custom_attribute)]
|
||||
#![feature(custom_attribute)]
|
||||
|
||||
#![allow(clippy)]
|
||||
#![warn(cyclomatic_complexity)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, custom_attribute)]
|
||||
#![feature(custom_attribute)]
|
||||
|
||||
#![warn(cyclomatic_complexity)]
|
||||
#![warn(unused)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, never_type)]
|
||||
#![feature(never_type)]
|
||||
|
||||
#![warn(diverging_sub_expression)]
|
||||
#![allow(match_same_arms, logic_bug)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, alloc)]
|
||||
#![feature(alloc)]
|
||||
#![feature(associated_type_defaults)]
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, non_ascii_idents)]
|
||||
#![feature(non_ascii_idents)]
|
||||
|
||||
#![warn(clippy, pub_enum_variant_names)]
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, box_syntax)]
|
||||
#![feature(box_syntax)]
|
||||
|
||||
#![allow(warnings, clippy)]
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, custom_attribute)]
|
||||
#![feature(custom_attribute)]
|
||||
#![warn(excessive_precision)]
|
||||
#![allow(print_literal)]
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, custom_attribute)]
|
||||
#![feature(custom_attribute)]
|
||||
|
||||
|
||||
use std::collections::*;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#![allow(unused, no_effect, unnecessary_operation)]
|
||||
#![warn(mut_mut)]
|
||||
|
||||
//#![plugin(regex_macros)]
|
||||
//extern crate regex;
|
||||
|
||||
|
||||
|
||||
fn fun(x : &mut &mut u32) -> bool {
|
||||
**x > 0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, const_fn)]
|
||||
#![feature(const_fn)]
|
||||
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, box_syntax)]
|
||||
#![feature(box_syntax)]
|
||||
|
||||
|
||||
#![warn(no_effect, unnecessary_operation)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#![plugin(clippy(conf_file="../auxiliary/conf_french_blacklisted_name.toml"))]
|
||||
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![allow(single_match)]
|
|
@ -1,6 +1,6 @@
|
|||
// error-pattern: error reading Clippy's configuration file: unknown key `foobar`
|
||||
|
||||
|
||||
#![plugin(clippy(conf_file="../auxiliary/conf_unknown_key.toml"))]
|
||||
|
||||
|
||||
fn main() {}
|
0
tests/ui/toml_unknown_key/conf_unknown_key.stderr
Normal file
0
tests/ui/toml_unknown_key/conf_unknown_key.stderr
Normal file
|
@ -1,4 +1,4 @@
|
|||
#![feature(plugin, custom_attribute, stmt_expr_attributes)]
|
||||
#![feature(custom_attribute, stmt_expr_attributes)]
|
||||
|
||||
#![allow(unused_parens)]
|
||||
|
||||
|
|
Loading…
Reference in a new issue