From a7a6c0461da71ac838708d2b34a629443f860b60 Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 5 Jun 2016 21:05:28 +0200 Subject: [PATCH] Add environment variable to deactivate wiki links --- CHANGELOG.md | 4 ++++ README.md | 3 +++ clippy_lints/src/utils/mod.rs | 7 +++++-- tests/compile-fail/booleans.rs | 21 ++++++++------------- tests/compile-fail/non_expressive_names.rs | 11 ----------- tests/compile-test.rs | 8 +++++++- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 166990b3d3b..51bf4ad2c15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.74 — TBR +* Add the `CLIPPY_DISABLE_WIKI_LINKS` environment variable to deactivate the + “for further information visit *wiki-link*” message. + ## 0.0.73 — 2016-06-05 * Fix false positives in [`useless_let_if_seq`] diff --git a/README.md b/README.md index 3b5b6768c23..8f699d2f741 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,9 @@ You can also specify the path to the configuration file with: #![plugin(clippy(conf_file="path/to/clippy's/configuration"))] ``` +To deactivate the “for further information visit *wiki-link*” message you can +define the `CLIPPY_DISABLE_WIKI_LINKS` environment variable. + ## Link with clippy service `clippy-service` is a rust web initiative providing `rust-clippy` as a web service. diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 986462b3723..beec30b32de 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -10,6 +10,7 @@ use rustc::traits; use rustc::ty::subst::Subst; use rustc::ty; use std::borrow::Cow; +use std::env; use std::mem; use std::ops::{Deref, DerefMut}; use std::str::FromStr; @@ -473,8 +474,10 @@ impl<'a> Deref for DiagnosticWrapper<'a> { impl<'a> DiagnosticWrapper<'a> { fn wiki_link(&mut self, lint: &'static Lint) { - self.help(&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}", - lint.name_lower())); + if env::var("CLIPPY_DISABLE_WIKI_LINKS").is_err() { + self.help(&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}", + lint.name_lower())); + } } } diff --git a/tests/compile-fail/booleans.rs b/tests/compile-fail/booleans.rs index aba55f0b8b4..fc220d1ac22 100644 --- a/tests/compile-fail/booleans.rs +++ b/tests/compile-fail/booleans.rs @@ -10,29 +10,27 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug - //~| HELP for further information visit //~| HELP this expression can be optimized out //~| HELP it would look like the following //~| SUGGESTION let _ = a; let _ = !(a && b); let _ = !true; //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = false; let _ = !false; //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = true; let _ = !!a; //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = a; let _ = false && a; //~ ERROR this boolean expression contains a logic bug - //~| HELP for further information visit //~| HELP this expression can be optimized out //~| HELP it would look like the following //~| SUGGESTION let _ = false; let _ = false || a; //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = a; // don't lint on cfgs @@ -43,7 +41,7 @@ fn main() { let _ = !(a && b || c); let _ = !(!a && b); //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = !b || a; } @@ -55,32 +53,29 @@ fn equality_stuff() { let d: i32 = unimplemented!(); let e: i32 = unimplemented!(); let _ = a == b && a != b; //~ ERROR this boolean expression contains a logic bug - //~| HELP for further information visit //~| HELP this expression can be optimized out //~| HELP it would look like the following //~| SUGGESTION let _ = false; let _ = a == b && c == 5 && a == b; //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = a == b && c == 5; let _ = a == b && c == 5 && b == a; //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = a == b && c == 5; //~| HELP try //~| SUGGESTION let _ = !(c != 5 || a != b); let _ = a < b && a >= b; //~ ERROR this boolean expression contains a logic bug - //~| HELP for further information visit //~| HELP this expression can be optimized out //~| HELP it would look like the following //~| SUGGESTION let _ = false; let _ = a > b && a <= b; //~ ERROR this boolean expression contains a logic bug - //~| HELP for further information visit //~| HELP this expression can be optimized out //~| HELP it would look like the following //~| SUGGESTION let _ = false; let _ = a > b && a == b; let _ = a != b || !(a != b || c == d); //~ ERROR this boolean expression can be simplified - //~| HELP for further information visit + //~| HELP try //~| SUGGESTION let _ = c != d || a != b; //~| HELP try //~| SUGGESTION let _ = !(a == b && c == d); diff --git a/tests/compile-fail/non_expressive_names.rs b/tests/compile-fail/non_expressive_names.rs index d959507bcb2..212dc2a96d5 100644 --- a/tests/compile-fail/non_expressive_names.rs +++ b/tests/compile-fail/non_expressive_names.rs @@ -28,10 +28,8 @@ fn main() { //~^ NOTE: existing binding defined here let bpple: i32; //~ ERROR: name is too similar //~| HELP: separate the discriminating character by an underscore like: `b_pple` - //~| HELP: for further information visit let cpple: i32; //~ ERROR: name is too similar //~| HELP: separate the discriminating character by an underscore like: `c_pple` - //~| HELP: for further information visit let a_bar: i32; let b_bar: i32; @@ -56,13 +54,11 @@ fn main() { let blubx: i32; //~ NOTE: existing binding defined here let bluby: i32; //~ ERROR: name is too similar - //~| HELP: for further information visit //~| HELP: separate the discriminating character by an underscore like: `blub_y` let cake: i32; //~ NOTE: existing binding defined here let cakes: i32; let coke: i32; //~ ERROR: name is too similar - //~| HELP: for further information visit match 5 { cheese @ 1 => {}, @@ -81,12 +77,10 @@ fn main() { let xyz1abc: i32; //~ NOTE: existing binding defined here let xyz2abc: i32; let xyzeabc: i32; //~ ERROR: name is too similar - //~| HELP: for further information visit let parser: i32; //~ NOTE: existing binding defined here let parsed: i32; let parsee: i32; //~ ERROR: name is too similar - //~| HELP: for further information visit //~| HELP: separate the discriminating character by an underscore like: `parse_e` let setter: i32; @@ -101,7 +95,6 @@ fn foo() { let Foo { apple, bpple } = unimplemented!(); let Foo { apple: spring, //~NOTE existing binding defined here bpple: sprang } = unimplemented!(); //~ ERROR: name is too similar - //~^HELP for further information } #[derive(Clone, Debug)] @@ -136,18 +129,14 @@ fn bla() { } { let e: i32; //~ ERROR: 5th binding whose name is just one char - //~| HELP: for further information visit } { let e: i32; //~ ERROR: 5th binding whose name is just one char - //~| HELP: for further information visit let f: i32; //~ ERROR: 6th binding whose name is just one char - //~| HELP: for further information visit } match 5 { 1 => println!(""), e => panic!(), //~ ERROR: 5th binding whose name is just one char - //~| HELP: for further information visit } match 5 { 1 => println!(""), diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 66c5734cc11..42a7dd96ae2 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -1,7 +1,7 @@ extern crate compiletest_rs as compiletest; use std::path::PathBuf; -use std::env::{var, temp_dir}; +use std::env::{set_var, var, temp_dir}; fn run_mode(dir: &'static str, mode: &'static str) { let mut config = compiletest::default_config(); @@ -23,9 +23,14 @@ fn run_mode(dir: &'static str, mode: &'static str) { compiletest::run_tests(&config); } +fn prepare_env() { + set_var("CLIPPY_DISABLE_WIKI_LINKS", "true"); +} + #[test] #[cfg(not(feature = "test-regex_macros"))] fn compile_test() { + prepare_env(); run_mode("run-pass", "run-pass"); run_mode("compile-fail", "compile-fail"); } @@ -33,6 +38,7 @@ fn compile_test() { #[test] #[cfg(feature = "test-regex_macros")] fn compile_test() { + prepare_env(); run_mode("run-pass-regex_macros", "run-pass"); run_mode("compile-fail-regex_macros", "compile-fail"); }