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

Move away form blacklist terminology #5896

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Current beta, release 2020-08-27
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
* [`if_same_then_else`]: Don't assume multiplication is always commutative
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
* [`blacklisted_name`]: Remove `bar` from the default configuration
* [`disallowed_name`]: Remove `bar` from the default configuration
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)
Expand Down Expand Up @@ -1413,7 +1413,6 @@ Released 2018-09-13
[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
[`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
Expand Down Expand Up @@ -1455,6 +1454,7 @@ Released 2018-09-13
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
[`disallowed_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_name
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml
value` mapping eg.

```toml
blacklisted-names = ["toto", "tata", "titi"]
disallowed-names = ["toto", "tata", "titi"]
cognitive-complexity-threshold = 30
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};

declare_clippy_lint! {
/// **What it does:** Checks for usage of blacklisted names for variables, such
/// **What it does:** Checks for usage of disallowed names for variables, such
/// as `foo`.
///
/// **Why is this bad?** These names are usually placeholder names and should be
Expand All @@ -17,33 +17,33 @@ declare_clippy_lint! {
/// ```rust
/// let foo = 3.14;
/// ```
pub BLACKLISTED_NAME,
pub DISALLOWED_NAME,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename it properly:

Suggested change
pub DISALLOWED_NAME,
pub DISALLOWED_NAMES,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's the lint definition which is in singular:

#![warn(clippy::blacklisted_name)]

not the toml entry:

blacklisted-names = ["toto", "tata", "titi"]

which is in plural.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it should be in plural, as per our lint naming conventions (point 3)

style,
"usage of a blacklisted/placeholder name"
"usage of a disallowed/placeholder name"
}

#[derive(Clone, Debug)]
pub struct BlacklistedName {
blacklist: FxHashSet<String>,
pub struct DisallowedName {
disallowlist: FxHashSet<String>,
}

impl BlacklistedName {
pub fn new(blacklist: FxHashSet<String>) -> Self {
Self { blacklist }
impl DisallowedName {
pub fn new(disallowlist: FxHashSet<String>) -> Self {
Self { disallowlist }
}
}

impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
impl_lint_pass!(DisallowedName => [DISALLOWED_NAME]);

impl<'tcx> LateLintPass<'tcx> for BlacklistedName {
impl<'tcx> LateLintPass<'tcx> for DisallowedName {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
if let PatKind::Binding(.., ident, _) = pat.kind {
if self.blacklist.contains(&ident.name.to_string()) {
if self.disallowlist.contains(&ident.name.to_string()) {
span_lint(
cx,
BLACKLISTED_NAME,
DISALLOWED_NAME,
ident.span,
&format!("use of a blacklisted/placeholder name `{}`", ident.name),
&format!("use of a disallowed/placeholder name `{}`", ident.name),
);
}
}
Expand Down
13 changes: 7 additions & 6 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ mod atomic_ordering;
mod attrs;
mod await_holding_lock;
mod bit_mask;
mod blacklisted_name;
mod blocks_in_if_conditions;
mod booleans;
mod bytecount;
Expand All @@ -173,6 +172,7 @@ mod dbg_macro;
mod default_trait_access;
mod dereference;
mod derive;
mod disallowed_name;
mod doc;
mod double_comparison;
mod double_parens;
Expand Down Expand Up @@ -494,7 +494,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&bit_mask::BAD_BIT_MASK,
&bit_mask::INEFFECTIVE_BIT_MASK,
&bit_mask::VERBOSE_BIT_MASK,
&blacklisted_name::BLACKLISTED_NAME,
&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS,
&booleans::LOGIC_BUG,
&booleans::NONMINIMAL_BOOL,
Expand All @@ -516,6 +515,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&derive::DERIVE_ORD_XOR_PARTIAL_ORD,
&derive::EXPL_IMPL_CLONE_ON_COPY,
&derive::UNSAFE_DERIVE_DESERIALIZE,
&disallowed_name::DISALLOWED_NAME,
&doc::DOC_MARKDOWN,
&doc::MISSING_ERRORS_DOC,
&doc::MISSING_SAFETY_DOC,
Expand Down Expand Up @@ -954,8 +954,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box swap::Swap);
store.register_late_pass(|| box overflow_check_conditional::OverflowCheckConditional);
store.register_late_pass(|| box new_without_default::NewWithoutDefault::default());
let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move || box blacklisted_name::BlacklistedName::new(blacklisted_names.clone()));
let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move || box disallowed_name::DisallowedName::new(disallowed_names.clone()));
let too_many_arguments_threshold1 = conf.too_many_arguments_threshold;
let too_many_lines_threshold2 = conf.too_many_lines_threshold;
store.register_late_pass(move || box functions::Functions::new(too_many_arguments_threshold1, too_many_lines_threshold2));
Expand Down Expand Up @@ -1235,7 +1235,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&bit_mask::BAD_BIT_MASK),
LintId::of(&bit_mask::INEFFECTIVE_BIT_MASK),
LintId::of(&bit_mask::VERBOSE_BIT_MASK),
LintId::of(&blacklisted_name::BLACKLISTED_NAME),
LintId::of(&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
LintId::of(&booleans::LOGIC_BUG),
LintId::of(&booleans::NONMINIMAL_BOOL),
Expand All @@ -1246,6 +1245,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&copies::IF_SAME_THEN_ELSE),
LintId::of(&derive::DERIVE_HASH_XOR_EQ),
LintId::of(&derive::DERIVE_ORD_XOR_PARTIAL_ORD),
LintId::of(&disallowed_name::DISALLOWED_NAME),
LintId::of(&doc::MISSING_SAFETY_DOC),
LintId::of(&doc::NEEDLESS_DOCTEST_MAIN),
LintId::of(&double_comparison::DOUBLE_COMPARISONS),
Expand Down Expand Up @@ -1492,10 +1492,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS),
LintId::of(&bit_mask::VERBOSE_BIT_MASK),
LintId::of(&blacklisted_name::BLACKLISTED_NAME),
LintId::of(&blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
LintId::of(&collapsible_if::COLLAPSIBLE_IF),
LintId::of(&comparison_chain::COMPARISON_CHAIN),
LintId::of(&disallowed_name::DISALLOWED_NAME),
LintId::of(&doc::MISSING_SAFETY_DOC),
LintId::of(&doc::NEEDLESS_DOCTEST_MAIN),
LintId::of(&enum_variants::ENUM_VARIANT_NAMES),
Expand Down Expand Up @@ -1859,6 +1859,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
ls.register_renamed("clippy::for_loop_over_option", "clippy::for_loops_over_fallibles");
ls.register_renamed("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles");
ls.register_renamed("clippy::identity_conversion", "clippy::useless_conversion");
ls.register_renamed("clippy::blacklisted_name", "clippy::disallowed_name");
}

// only exists to let the dogfood integration test works.
Expand Down
13 changes: 11 additions & 2 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ macro_rules! define_Conf {

pub use self::helpers::Conf;
define_Conf! {
/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
(blacklisted_names, "blacklisted_names": Vec<String>, ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),
/// DEPRECATED LINT: BLACKLISTED_NAME. Use the Disallowed Names lint instead.
(blacklisted_names, "blacklisted_names": Vec<String>, vec![]),
/// Lint: DISALLOWED_NAME. The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses
(disallowed_names, "disallowed_names": Vec<String>, ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),
/// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have
(cognitive_complexity_threshold, "cognitive_complexity_threshold": u64, 25),
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
Expand Down Expand Up @@ -234,6 +236,13 @@ pub fn read(path: &Path) -> (Conf, Vec<Error>) {
errors.push(Error::Toml(cyc_err));
}

let block_ls_field = &toml_ref.blacklisted_names;
if !block_ls_field.is_empty() {
let block_err =
"found deprecated field `blacklisted-names`. Please use `disallowed-names` instead.".to_string();
errors.push(Error::Toml(block_err));
}

(toml, errors)
},
Err(e) => {
Expand Down
14 changes: 7 additions & 7 deletions src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
deprecation: None,
module: "methods",
},
Lint {
name: "blacklisted_name",
group: "style",
desc: "usage of a blacklisted/placeholder name",
deprecation: None,
module: "blacklisted_name",
},
Lint {
name: "blanket_clippy_restriction_lints",
group: "style",
Expand Down Expand Up @@ -367,6 +360,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
deprecation: None,
module: "derive",
},
Lint {
name: "disallowed_name",
group: "style",
desc: "usage of a disallowed/placeholder name",
deprecation: None,
module: "disallowed_name",
},
Lint {
name: "diverging_sub_expression",
group: "complexity",
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-toml/bad_toml_type/clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blacklisted-names = 42
disallowed-names = 42
2 changes: 1 addition & 1 deletion tests/ui-toml/bad_toml_type/conf_bad_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a
// error-pattern: error reading Clippy's configuration file: `disallowed-names` is expected to be a
// `Vec < String >` but is a `integer`

fn main() {}
1 change: 0 additions & 1 deletion tests/ui-toml/toml_blacklist/clippy.toml

This file was deleted.

46 changes: 0 additions & 46 deletions tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.stderr

This file was deleted.

1 change: 1 addition & 0 deletions tests/ui-toml/toml_disallowlist/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disallowed-names = ["toto", "tata", "titi"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(dead_code)]
#![allow(clippy::single_match)]
#![allow(unused_variables)]
#![warn(clippy::blacklisted_name)]
#![warn(clippy::disallowed_name)]

fn test(toto: ()) {}

Expand Down
46 changes: 46 additions & 0 deletions tests/ui-toml/toml_disallowlist/conf_french_disallowed_name.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
error: use of a disallowed/placeholder name `toto`
--> $DIR/conf_french_disallowed_name.rs:6:9
|
LL | fn test(toto: ()) {}
| ^^^^
|
= note: `-D clippy::disallowed-name` implied by `-D warnings`

error: use of a disallowed/placeholder name `toto`
--> $DIR/conf_french_disallowed_name.rs:9:9
|
LL | let toto = 42;
| ^^^^

error: use of a disallowed/placeholder name `tata`
--> $DIR/conf_french_disallowed_name.rs:10:9
|
LL | let tata = 42;
| ^^^^

error: use of a disallowed/placeholder name `titi`
--> $DIR/conf_french_disallowed_name.rs:11:9
|
LL | let titi = 42;
| ^^^^

error: use of a disallowed/placeholder name `toto`
--> $DIR/conf_french_disallowed_name.rs:17:10
|
LL | (toto, Some(tata), titi @ Some(_)) => (),
| ^^^^

error: use of a disallowed/placeholder name `tata`
--> $DIR/conf_french_disallowed_name.rs:17:21
|
LL | (toto, Some(tata), titi @ Some(_)) => (),
| ^^^^

error: use of a disallowed/placeholder name `titi`
--> $DIR/conf_french_disallowed_name.rs:17:28
|
LL | (toto, Some(tata), titi @ Some(_)) => (),
| ^^^^

error: aborting due to 7 previous errors

2 changes: 1 addition & 1 deletion tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `third-party` at line 5 column 1
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `disallowed-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `third-party` at line 5 column 1

error: aborting due to previous error

Loading