Add lint print_stderr
Resolves #6348 Almost identical to print_stdout, this lint applies to the `eprintln!` and `eprint!` macros rather than `println!` and `print!`.
This commit is contained in:
@@ -2006,6 +2006,7 @@ Released 2018-09-13
|
|||||||
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
|
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
|
||||||
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
|
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
|
||||||
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
|
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
|
||||||
|
[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr
|
||||||
[`print_stdout`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout
|
[`print_stdout`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout
|
||||||
[`print_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline
|
[`print_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline
|
||||||
[`println_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#println_empty_string
|
[`println_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#println_empty_string
|
||||||
|
|||||||
@@ -934,6 +934,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
&wildcard_imports::WILDCARD_IMPORTS,
|
&wildcard_imports::WILDCARD_IMPORTS,
|
||||||
&write::PRINTLN_EMPTY_STRING,
|
&write::PRINTLN_EMPTY_STRING,
|
||||||
&write::PRINT_LITERAL,
|
&write::PRINT_LITERAL,
|
||||||
|
&write::PRINT_STDERR,
|
||||||
&write::PRINT_STDOUT,
|
&write::PRINT_STDOUT,
|
||||||
&write::PRINT_WITH_NEWLINE,
|
&write::PRINT_WITH_NEWLINE,
|
||||||
&write::USE_DEBUG,
|
&write::USE_DEBUG,
|
||||||
@@ -1247,6 +1248,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
LintId::of(&types::RC_BUFFER),
|
LintId::of(&types::RC_BUFFER),
|
||||||
LintId::of(&unwrap_in_result::UNWRAP_IN_RESULT),
|
LintId::of(&unwrap_in_result::UNWRAP_IN_RESULT),
|
||||||
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
|
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
|
||||||
|
LintId::of(&write::PRINT_STDERR),
|
||||||
LintId::of(&write::PRINT_STDOUT),
|
LintId::of(&write::PRINT_STDOUT),
|
||||||
LintId::of(&write::USE_DEBUG),
|
LintId::of(&write::USE_DEBUG),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -75,6 +75,24 @@ declare_clippy_lint! {
|
|||||||
"printing on stdout"
|
"printing on stdout"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare_clippy_lint! {
|
||||||
|
/// **What it does:** Checks for printing on *stderr*. The purpose of this lint
|
||||||
|
/// is to catch debugging remnants.
|
||||||
|
///
|
||||||
|
/// **Why is this bad?** People often print on *stderr* while debugging an
|
||||||
|
/// application and might forget to remove those prints afterward.
|
||||||
|
///
|
||||||
|
/// **Known problems:** Only catches `eprint!` and `eprintln!` calls.
|
||||||
|
///
|
||||||
|
/// **Example:**
|
||||||
|
/// ```rust
|
||||||
|
/// eprintln!("Hello world!");
|
||||||
|
/// ```
|
||||||
|
pub PRINT_STDERR,
|
||||||
|
restriction,
|
||||||
|
"printing on stderr"
|
||||||
|
}
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for use of `Debug` formatting. The purpose of this
|
/// **What it does:** Checks for use of `Debug` formatting. The purpose of this
|
||||||
/// lint is to catch debugging remnants.
|
/// lint is to catch debugging remnants.
|
||||||
@@ -201,6 +219,7 @@ impl_lint_pass!(Write => [
|
|||||||
PRINT_WITH_NEWLINE,
|
PRINT_WITH_NEWLINE,
|
||||||
PRINTLN_EMPTY_STRING,
|
PRINTLN_EMPTY_STRING,
|
||||||
PRINT_STDOUT,
|
PRINT_STDOUT,
|
||||||
|
PRINT_STDERR,
|
||||||
USE_DEBUG,
|
USE_DEBUG,
|
||||||
PRINT_LITERAL,
|
PRINT_LITERAL,
|
||||||
WRITE_WITH_NEWLINE,
|
WRITE_WITH_NEWLINE,
|
||||||
@@ -260,6 +279,10 @@ impl EarlyLintPass for Write {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if mac.path == sym!(eprintln) {
|
||||||
|
span_lint(cx, PRINT_STDERR, mac.span(), "use of `eprintln!`");
|
||||||
|
} else if mac.path == sym!(eprint) {
|
||||||
|
span_lint(cx, PRINT_STDERR, mac.span(), "use of `eprint!`");
|
||||||
} else if mac.path == sym!(print) {
|
} else if mac.path == sym!(print) {
|
||||||
if !is_build_script(cx) {
|
if !is_build_script(cx) {
|
||||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
|
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
|
||||||
|
|||||||
6
tests/ui/print_stderr.rs
Normal file
6
tests/ui/print_stderr.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#![warn(clippy::print_stderr)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
eprintln!("Hello");
|
||||||
|
eprint!("World");
|
||||||
|
}
|
||||||
16
tests/ui/print_stderr.stderr
Normal file
16
tests/ui/print_stderr.stderr
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
error: use of `eprintln!`
|
||||||
|
--> $DIR/print_stderr.rs:4:5
|
||||||
|
|
|
||||||
|
LL | eprintln!("Hello");
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::print-stderr` implied by `-D warnings`
|
||||||
|
|
||||||
|
error: use of `eprint!`
|
||||||
|
--> $DIR/print_stderr.rs:5:5
|
||||||
|
|
|
||||||
|
LL | eprint!("World");
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Reference in New Issue
Block a user