Skip to content

Commit

Permalink
Auto merge of rust-lang#8974 - Metaswitch:remove-blacklist-terminolog…
Browse files Browse the repository at this point in the history
…y, r=Manishearth

Remove "blacklist" terminology

Picking up where rust-lang/rust-clippy#5896 left off, this renames the `blacklisted_name` lint to `disallowed_names` (pluralised for compliance with naming conventions).  The old name is still available though is deprecated (both in the lint name, and in the TOML configuration file).

This has been proposed/requested a few times, most recently in rust-lang/rust-clippy#7582 where `@xFrednet` suggested pinging the Clippy team when a PR was created hence...

cc: `@rust-lang/clippy`

changelog: [`disallowed_names`] lint replaces `blacklisted_name`
  • Loading branch information
bors committed Jul 29, 2022
2 parents 53a09d4 + 56c9cc4 commit a0ed687
Show file tree
Hide file tree
Showing 63 changed files with 290 additions and 269 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ Released 2021-09-09
[#7407](https://github.com/rust-lang/rust-clippy/pull/7407)
* [`redundant_allocation`]: Now additionally supports the `Arc<>` type
[#7308](https://github.com/rust-lang/rust-clippy/pull/7308)
* [`blacklisted_name`]: Now allows blacklisted names in test code
* [`disallowed_names`]: Now allows disallowed names in test code
[#7379](https://github.com/rust-lang/rust-clippy/pull/7379)
* [`redundant_closure`]: Suggests `&mut` for `FnMut`
[#7437](https://github.com/rust-lang/rust-clippy/pull/7437)
Expand Down Expand Up @@ -2066,7 +2066,7 @@ Released 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_names`]: 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 @@ -3522,6 +3522,7 @@ Released 2018-09-13
[`derive_partial_eq_without_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
[`disallowed_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ value` mapping e.g.

```toml
avoid-breaking-exported-api = false
blacklisted-names = ["toto", "tata", "titi"]
disallowed-names = ["toto", "tata", "titi"]
cognitive-complexity-threshold = 30
```

Expand Down
2 changes: 1 addition & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ basic `variable = value` mapping eg.

```toml
avoid-breaking-exported-api = false
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 @@ -6,7 +6,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};

declare_clippy_lint! {
/// ### What it does
/// Checks for usage of blacklisted names for variables, such
/// Checks for usage of disallowed names for variables, such
/// as `foo`.
///
/// ### Why is this bad?
Expand All @@ -18,21 +18,21 @@ declare_clippy_lint! {
/// let foo = 3.14;
/// ```
#[clippy::version = "pre 1.29.0"]
pub BLACKLISTED_NAME,
pub DISALLOWED_NAMES,
style,
"usage of a blacklisted/placeholder name"
"usage of a disallowed/placeholder name"
}

#[derive(Clone, Debug)]
pub struct BlacklistedName {
blacklist: FxHashSet<String>,
pub struct DisallowedNames {
disallow: FxHashSet<String>,
test_modules_deep: u32,
}

impl BlacklistedName {
pub fn new(blacklist: FxHashSet<String>) -> Self {
impl DisallowedNames {
pub fn new(disallow: FxHashSet<String>) -> Self {
Self {
blacklist,
disallow,
test_modules_deep: 0,
}
}
Expand All @@ -42,9 +42,9 @@ impl BlacklistedName {
}
}

impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
impl_lint_pass!(DisallowedNames => [DISALLOWED_NAMES]);

impl<'tcx> LateLintPass<'tcx> for BlacklistedName {
impl<'tcx> LateLintPass<'tcx> for DisallowedNames {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if is_test_module_or_function(cx.tcx, item) {
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
Expand All @@ -58,12 +58,12 @@ impl<'tcx> LateLintPass<'tcx> for BlacklistedName {
}

if let PatKind::Binding(.., ident, _) = pat.kind {
if self.blacklist.contains(&ident.name.to_string()) {
if self.disallow.contains(&ident.name.to_string()) {
span_lint(
cx,
BLACKLISTED_NAME,
DISALLOWED_NAMES,
ident.span,
&format!("use of a blacklisted/placeholder name `{}`", ident.name),
&format!("use of a disallowed/placeholder name `{}`", ident.name),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE),
LintId::of(await_holding_invalid::AWAIT_HOLDING_LOCK),
LintId::of(await_holding_invalid::AWAIT_HOLDING_REFCELL_REF),
LintId::of(blacklisted_name::BLACKLISTED_NAME),
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
LintId::of(booleans::LOGIC_BUG),
Expand Down Expand Up @@ -47,6 +46,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(derive::DERIVE_ORD_XOR_PARTIAL_ORD),
LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
LintId::of(disallowed_methods::DISALLOWED_METHODS),
LintId::of(disallowed_names::DISALLOWED_NAMES),
LintId::of(disallowed_types::DISALLOWED_TYPES),
LintId::of(doc::MISSING_SAFETY_DOC),
LintId::of(doc::NEEDLESS_DOCTEST_MAIN),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ store.register_lints(&[
await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE,
await_holding_invalid::AWAIT_HOLDING_LOCK,
await_holding_invalid::AWAIT_HOLDING_REFCELL_REF,
blacklisted_name::BLACKLISTED_NAME,
blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS,
bool_assert_comparison::BOOL_ASSERT_COMPARISON,
booleans::LOGIC_BUG,
Expand Down Expand Up @@ -116,6 +115,7 @@ store.register_lints(&[
derive::EXPL_IMPL_CLONE_ON_COPY,
derive::UNSAFE_DERIVE_DESERIALIZE,
disallowed_methods::DISALLOWED_METHODS,
disallowed_names::DISALLOWED_NAMES,
disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS,
disallowed_types::DISALLOWED_TYPES,
doc::DOC_MARKDOWN,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.register_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
store.register_group(true, "clippy::style", Some("clippy_style"), vec![
LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
LintId::of(assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES),
LintId::of(blacklisted_name::BLACKLISTED_NAME),
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
LintId::of(casts::FN_TO_NUMERIC_CAST),
Expand All @@ -18,6 +17,7 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
LintId::of(dereference::NEEDLESS_BORROW),
LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
LintId::of(disallowed_methods::DISALLOWED_METHODS),
LintId::of(disallowed_names::DISALLOWED_NAMES),
LintId::of(disallowed_types::DISALLOWED_TYPES),
LintId::of(doc::MISSING_SAFETY_DOC),
LintId::of(doc::NEEDLESS_DOCTEST_MAIN),
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ mod assertions_on_result_states;
mod async_yields_async;
mod attrs;
mod await_holding_invalid;
mod blacklisted_name;
mod blocks_in_if_conditions;
mod bool_assert_comparison;
mod booleans;
Expand Down Expand Up @@ -205,6 +204,7 @@ mod dereference;
mod derivable_impls;
mod derive;
mod disallowed_methods;
mod disallowed_names;
mod disallowed_script_idents;
mod disallowed_types;
mod doc;
Expand Down Expand Up @@ -683,8 +683,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| Box::new(swap::Swap));
store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional));
store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default()));
let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move || Box::new(blacklisted_name::BlacklistedName::new(blacklisted_names.clone())));
let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move || Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone())));
let too_many_arguments_threshold = conf.too_many_arguments_threshold;
let too_many_lines_threshold = conf.too_many_lines_threshold;
store.register_late_pass(move || {
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/renamed_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::block_in_if_condition_expr", "clippy::blocks_in_if_conditions"),
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_if_conditions"),
("clippy::box_vec", "clippy::box_collection"),
("clippy::blacklisted_name", "clippy::disallowed_names"),
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
("clippy::disallowed_method", "clippy::disallowed_methods"),
Expand Down
21 changes: 13 additions & 8 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
"MinGW",
"CamelCase",
];
const DEFAULT_BLACKLISTED_NAMES: &[&str] = &["foo", "baz", "quux"];
const DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"];

/// Holds information used by `MISSING_ENFORCED_IMPORT_RENAMES` lint.
#[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -159,7 +159,7 @@ macro_rules! define_Conf {
"duplicate field `", stringify!($new_conf),
"` (provided as `", stringify!($name), "`)"
))),
None => $new_conf = Some(value),
None => $new_conf = $name.clone(),
})?
},
}
Expand Down Expand Up @@ -217,12 +217,11 @@ define_Conf! {
///
/// The minimum rust version that the project supports
(msrv: Option<String> = None),
/// Lint: BLACKLISTED_NAME.
/// DEPRECATED LINT: BLACKLISTED_NAME.
///
/// The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses. The value
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
/// default configuration of Clippy. By default any configuraction will replace the default value.
(blacklisted_names: Vec<String> = super::DEFAULT_BLACKLISTED_NAMES.iter().map(ToString::to_string).collect()),
/// Use the Disallowed Names lint instead
#[conf_deprecated("Please use `disallowed-names` instead", disallowed_names)]
(blacklisted_names: Vec<String> = Vec::new()),
/// Lint: COGNITIVE_COMPLEXITY.
///
/// The maximum cognitive complexity a function can have
Expand All @@ -232,6 +231,12 @@ define_Conf! {
/// Use the Cognitive Complexity lint instead.
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
(cyclomatic_complexity_threshold: u64 = 25),
/// Lint: DISALLOWED_NAMES.
///
/// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
/// default configuration of Clippy. By default any configuration will replace the default value.
(disallowed_names: Vec<String> = super::DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect()),
/// Lint: DOC_MARKDOWN.
///
/// The list of words this lint should not consider as identifiers needing ticks. The value
Expand Down Expand Up @@ -434,7 +439,7 @@ pub fn read(path: &Path) -> TryConf {
match toml::from_str::<TryConf>(&content) {
Ok(mut conf) => {
extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS);
extend_vec_if_indicator_present(&mut conf.conf.blacklisted_names, DEFAULT_BLACKLISTED_NAMES);
extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES);

conf
},
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/internal_lints/metadata_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
if_chain! {
// item validation
if is_lint_ref_type(cx, ty);
// blacklist check
// disallow check
let lint_name = sym_to_string(item.ident.name).to_ascii_lowercase();
if !BLACK_LISTED_LINTS.contains(&lint_name.as_str());
// metadata extraction
Expand All @@ -644,7 +644,7 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {

if_chain! {
if is_deprecated_lint(cx, ty);
// blacklist check
// disallow check
let lint_name = sym_to_string(item.ident.name).to_ascii_lowercase();
if !BLACK_LISTED_LINTS.contains(&lint_name.as_str());
// Metadata the little we can get from a deprecated lint
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.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`: invalid type: integer `42`, expected a sequence for key `blacklisted-names`
error: error reading Clippy's configuration file `$DIR/clippy.toml`: invalid type: integer `42`, expected a sequence for key `disallowed-names`

error: aborting due to previous error

16 changes: 0 additions & 16 deletions tests/ui-toml/blacklisted_names_append/blacklisted_names.stderr

This file was deleted.

1 change: 0 additions & 1 deletion tests/ui-toml/blacklisted_names_append/clippy.toml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/ui-toml/blacklisted_names_replace/blacklisted_names.stderr

This file was deleted.

1 change: 0 additions & 1 deletion tests/ui-toml/blacklisted_names_replace/clippy.toml

This file was deleted.

3 changes: 2 additions & 1 deletion tests/ui-toml/conf_deprecated_key/clippy.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# that one is a warning
# Expect errors from these deprecated configs
cyclomatic-complexity-threshold = 2
blacklisted-names = [ "..", "wibble" ]

# that one is white-listed
[third-party]
Expand Down
4 changes: 3 additions & 1 deletion tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead

warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `blacklisted-names`. Please use `disallowed-names` instead

error: the function has a cognitive complexity of (3/2)
--> $DIR/conf_deprecated_key.rs:4:4
|
Expand All @@ -9,5 +11,5 @@ LL | fn cognitive_complexity() {
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: you could split it up into multiple smaller functions

error: aborting due to previous error; 1 warning emitted
error: aborting due to previous error; 2 warnings emitted

1 change: 1 addition & 0 deletions tests/ui-toml/disallowed_names_append/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disallowed-names = ["ducks", ".."]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[warn(clippy::blacklisted_name)]
#[warn(clippy::disallowed_names)]

fn main() {
// `foo` is part of the default configuration
let foo = "bar";
// `ducks` was unrightfully blacklisted
// `ducks` was unrightfully disallowed
let ducks = ["quack", "quack"];
// `fox` is okay
let fox = ["what", "does", "the", "fox", "say", "?"];
Expand Down
16 changes: 16 additions & 0 deletions tests/ui-toml/disallowed_names_append/disallowed_names.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: use of a disallowed/placeholder name `foo`
--> $DIR/disallowed_names.rs:5:9
|
LL | let foo = "bar";
| ^^^
|
= note: `-D clippy::disallowed-names` implied by `-D warnings`

error: use of a disallowed/placeholder name `ducks`
--> $DIR/disallowed_names.rs:7:9
|
LL | let ducks = ["quack", "quack"];
| ^^^^^

error: aborting due to 2 previous errors

1 change: 1 addition & 0 deletions tests/ui-toml/disallowed_names_replace/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disallowed-names = ["ducks"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[warn(clippy::blacklisted_name)]
#[warn(clippy::disallowed_names)]

fn main() {
// `foo` is part of the default configuration
let foo = "bar";
// `ducks` was unrightfully blacklisted
// `ducks` was unrightfully disallowed
let ducks = ["quack", "quack"];
// `fox` is okay
let fox = ["what", "does", "the", "fox", "say", "?"];
Expand Down
10 changes: 10 additions & 0 deletions tests/ui-toml/disallowed_names_replace/disallowed_names.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: use of a disallowed/placeholder name `ducks`
--> $DIR/disallowed_names.rs:7:9
|
LL | let ducks = ["quack", "quack"];
| ^^^^^
|
= note: `-D clippy::disallowed-names` implied by `-D warnings`

error: aborting due to previous error

1 change: 0 additions & 1 deletion tests/ui-toml/toml_blacklist/clippy.toml

This file was deleted.

Loading

0 comments on commit a0ed687

Please sign in to comment.