mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 01:17:16 +00:00
Auto merge of #7350 - camsteffen:suspicious, r=flip1995
Add suspicious group changelog: Introduce `clippy::suspicious` 🤔 group and move several lints into the group Closes #6366. CC #6626. A number of lints are moved from each of `correctness`, `style` and `complexity` groups. Notably I didn't move `suspicious_splitn` since I think that is a `correctness` lint despite the name. Lints moved to `clippy::suspicious`: * `blanket_clippy_restriction_lints` (was `clippy::style`) * `empty_loop` (was `clippy::style`) * `eval_order_dependence` (was `clippy::complexity`) * `float_equality_without_abs` (was `clippy::correctness`) * `for_loops_over_fallibles` (was `clippy::correctness`) * `misrefactored_assign_op` (was `clippy::complexity`) * `mut_range_bound` (was `clippy::complexity`) * `mutable_key_type` (was `clippy::correctness`) * `suspicious_arithmetic_impl` (was `clippy::correctness`) * `suspicious_assignment_formatting` (was `clippy::style`) * `suspicious_else_formatting` (was `clippy::style`) * `suspicious_map` (was `clippy::complexity`) * `suspicious_op_assign_impl` (was `clippy::correctness`) * `suspicious_unary_op_formatting` (was `clippy::style`)
This commit is contained in:
commit
e405c68b3c
19 changed files with 62 additions and 46 deletions
2
.github/workflows/remark.yml
vendored
2
.github/workflows/remark.yml
vendored
|
@ -22,7 +22,7 @@ jobs:
|
|||
uses: actions/setup-node@v1.4.4
|
||||
|
||||
- name: Install remark
|
||||
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended
|
||||
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended remark-gfm
|
||||
|
||||
# Run
|
||||
- name: Check *.md files
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"plugins": [
|
||||
"remark-preset-lint-recommended",
|
||||
"remark-gfm",
|
||||
["remark-lint-list-item-indent", false],
|
||||
["remark-lint-no-literal-urls", false],
|
||||
["remark-lint-no-shortcut-reference-link", false],
|
||||
|
|
|
@ -11,9 +11,10 @@ Lints are divided into categories, each with a default [lint level](https://doc.
|
|||
You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category.
|
||||
|
||||
| Category | Description | Default level |
|
||||
| --------------------- | ----------------------------------------------------------------------- | ------------- |
|
||||
| `clippy::all` | all lints that are on by default (correctness, style, complexity, perf) | **warn/deny** |
|
||||
| `clippy::correctness` | code that is outright wrong or very useless | **deny** |
|
||||
| --------------------- | ----------------------------------------------------------------------------------- | ------------- |
|
||||
| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** |
|
||||
| `clippy::correctness` | code that is outright wrong or useless | **deny** |
|
||||
| `clippy::suspicious` | code that is most likely wrong or useless | **warn** |
|
||||
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
|
||||
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
|
||||
| `clippy::perf` | code that can be written to run faster | **warn** |
|
||||
|
|
|
@ -137,6 +137,7 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
|
|||
.possible_values(&[
|
||||
"style",
|
||||
"correctness",
|
||||
"suspicious",
|
||||
"complexity",
|
||||
"perf",
|
||||
"pedantic",
|
||||
|
|
|
@ -92,7 +92,10 @@ pub fn run(update_mode: UpdateMode) {
|
|||
|| {
|
||||
// clippy::all should only include the following lint groups:
|
||||
let all_group_lints = usable_lints.iter().filter(|l| {
|
||||
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
|
||||
matches!(
|
||||
&*l.group,
|
||||
"correctness" | "suspicious" | "style" | "complexity" | "perf"
|
||||
)
|
||||
});
|
||||
|
||||
gen_lint_group_list(all_group_lints)
|
||||
|
|
|
@ -55,7 +55,7 @@ declare_clippy_lint! {
|
|||
/// a += a + b;
|
||||
/// ```
|
||||
pub MISREFACTORED_ASSIGN_OP,
|
||||
complexity,
|
||||
suspicious,
|
||||
"having a variable on both sides of an assign op"
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ declare_clippy_lint! {
|
|||
/// #![deny(clippy::as_conversions)]
|
||||
/// ```
|
||||
pub BLANKET_CLIPPY_RESTRICTION_LINTS,
|
||||
style,
|
||||
suspicious,
|
||||
"enabling the complete restriction group"
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ declare_clippy_lint! {
|
|||
/// let a = tmp + x;
|
||||
/// ```
|
||||
pub EVAL_ORDER_DEPENDENCE,
|
||||
complexity,
|
||||
suspicious,
|
||||
"whether a variable read occurs before a write depends on sub-expression evaluation order"
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub FLOAT_EQUALITY_WITHOUT_ABS,
|
||||
correctness,
|
||||
suspicious,
|
||||
"float equality check without `.abs()`"
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ declare_clippy_lint! {
|
|||
/// a =- 42; // confusing, should it be `a -= 42` or `a = -42`?
|
||||
/// ```
|
||||
pub SUSPICIOUS_ASSIGNMENT_FORMATTING,
|
||||
style,
|
||||
suspicious,
|
||||
"suspicious formatting of `*=`, `-=` or `!=`"
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub SUSPICIOUS_UNARY_OP_FORMATTING,
|
||||
style,
|
||||
suspicious,
|
||||
"suspicious formatting of unary `-` or `!` on the RHS of a BinOp"
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub SUSPICIOUS_ELSE_FORMATTING,
|
||||
style,
|
||||
suspicious,
|
||||
"suspicious formatting of `else`"
|
||||
}
|
||||
|
||||
|
|
|
@ -60,9 +60,9 @@ use rustc_session::Session;
|
|||
/// 4. The `description` that contains a short explanation on what's wrong with code where the
|
||||
/// lint is triggered.
|
||||
///
|
||||
/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default.
|
||||
/// As said in the README.md of this repository, if the lint level mapping changes, please update
|
||||
/// README.md.
|
||||
/// Currently the categories `style`, `correctness`, `suspicious`, `complexity` and `perf` are
|
||||
/// enabled by default. As said in the README.md of this repository, if the lint level mapping
|
||||
/// changes, please update README.md.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
@ -106,6 +106,11 @@ macro_rules! declare_clippy_lint {
|
|||
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
|
||||
}
|
||||
};
|
||||
{ $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
|
||||
declare_tool_lint! {
|
||||
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
|
||||
}
|
||||
};
|
||||
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
|
||||
declare_tool_lint! {
|
||||
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
|
||||
|
@ -1456,7 +1461,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
store.register_group(true, "clippy::style", Some("clippy_style"), vec![
|
||||
LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
|
||||
LintId::of(assign_ops::ASSIGN_OP_PATTERN),
|
||||
LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
|
||||
LintId::of(blacklisted_name::BLACKLISTED_NAME),
|
||||
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
|
||||
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
|
||||
|
@ -1474,9 +1478,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(eq_op::OP_REF),
|
||||
LintId::of(eta_reduction::REDUNDANT_CLOSURE),
|
||||
LintId::of(float_literal::EXCESSIVE_PRECISION),
|
||||
LintId::of(formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING),
|
||||
LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING),
|
||||
LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
|
||||
LintId::of(from_over_into::FROM_OVER_INTO),
|
||||
LintId::of(from_str_radix_10::FROM_STR_RADIX_10),
|
||||
LintId::of(functions::DOUBLE_MUST_USE),
|
||||
|
@ -1489,7 +1490,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(len_zero::LEN_ZERO),
|
||||
LintId::of(literal_representation::INCONSISTENT_DIGIT_GROUPING),
|
||||
LintId::of(literal_representation::UNUSUAL_BYTE_GROUPINGS),
|
||||
LintId::of(loops::EMPTY_LOOP),
|
||||
LintId::of(loops::FOR_KV_MAP),
|
||||
LintId::of(loops::NEEDLESS_RANGE_LOOP),
|
||||
LintId::of(loops::SAME_ITEM_PUSH),
|
||||
|
@ -1569,7 +1569,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
]);
|
||||
|
||||
store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec![
|
||||
LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP),
|
||||
LintId::of(attrs::DEPRECATED_CFG_ATTR),
|
||||
LintId::of(booleans::NONMINIMAL_BOOL),
|
||||
LintId::of(casts::CHAR_LIT_AS_U8),
|
||||
|
@ -1579,7 +1578,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(double_parens::DOUBLE_PARENS),
|
||||
LintId::of(duration_subsec::DURATION_SUBSEC),
|
||||
LintId::of(eval_order_dependence::DIVERGING_SUB_EXPRESSION),
|
||||
LintId::of(eval_order_dependence::EVAL_ORDER_DEPENDENCE),
|
||||
LintId::of(explicit_write::EXPLICIT_WRITE),
|
||||
LintId::of(format::USELESS_FORMAT),
|
||||
LintId::of(functions::TOO_MANY_ARGUMENTS),
|
||||
|
@ -1590,7 +1588,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(lifetimes::NEEDLESS_LIFETIMES),
|
||||
LintId::of(loops::EXPLICIT_COUNTER_LOOP),
|
||||
LintId::of(loops::MANUAL_FLATTEN),
|
||||
LintId::of(loops::MUT_RANGE_BOUND),
|
||||
LintId::of(loops::SINGLE_ELEMENT_LOOP),
|
||||
LintId::of(loops::WHILE_LET_LOOP),
|
||||
LintId::of(manual_strip::MANUAL_STRIP),
|
||||
|
@ -1614,7 +1611,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(methods::OPTION_FILTER_MAP),
|
||||
LintId::of(methods::SEARCH_IS_SOME),
|
||||
LintId::of(methods::SKIP_WHILE_NEXT),
|
||||
LintId::of(methods::SUSPICIOUS_MAP),
|
||||
LintId::of(methods::UNNECESSARY_FILTER_MAP),
|
||||
LintId::of(methods::USELESS_ASREF),
|
||||
LintId::of(misc::SHORT_CIRCUIT_STATEMENT),
|
||||
|
@ -1683,7 +1679,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT),
|
||||
LintId::of(eq_op::EQ_OP),
|
||||
LintId::of(erasing_op::ERASING_OP),
|
||||
LintId::of(float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS),
|
||||
LintId::of(formatting::POSSIBLE_MISSING_COMMA),
|
||||
LintId::of(functions::NOT_UNSAFE_PTR_ARG_DEREF),
|
||||
LintId::of(if_let_mutex::IF_LET_MUTEX),
|
||||
|
@ -1693,7 +1688,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(inline_fn_without_body::INLINE_FN_WITHOUT_BODY),
|
||||
LintId::of(let_underscore::LET_UNDERSCORE_LOCK),
|
||||
LintId::of(literal_representation::MISTYPED_LITERAL_SUFFIXES),
|
||||
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
|
||||
LintId::of(loops::ITER_NEXT_LOOP),
|
||||
LintId::of(loops::NEVER_LOOP),
|
||||
LintId::of(loops::WHILE_IMMUTABLE_CONDITION),
|
||||
|
@ -1708,7 +1702,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(misc::CMP_NAN),
|
||||
LintId::of(misc::FLOAT_CMP),
|
||||
LintId::of(misc::MODULO_ONE),
|
||||
LintId::of(mut_key::MUTABLE_KEY_TYPE),
|
||||
LintId::of(non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS),
|
||||
LintId::of(open_options::NONSENSICAL_OPEN_OPTIONS),
|
||||
LintId::of(option_env_unwrap::OPTION_ENV_UNWRAP),
|
||||
|
@ -1719,8 +1712,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(self_assignment::SELF_ASSIGNMENT),
|
||||
LintId::of(serde_api::SERDE_API_MISUSE),
|
||||
LintId::of(size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT),
|
||||
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
|
||||
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
|
||||
LintId::of(swap::ALMOST_SWAPPED),
|
||||
LintId::of(to_string_in_display::TO_STRING_IN_DISPLAY),
|
||||
LintId::of(transmute::UNSOUND_COLLECTION_TRANSMUTE),
|
||||
|
@ -1737,6 +1728,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(vec_resize_to_zero::VEC_RESIZE_TO_ZERO),
|
||||
]);
|
||||
|
||||
store.register_group(true, "clippy::suspicious", None, vec![
|
||||
LintId::of(assign_ops::MISREFACTORED_ASSIGN_OP),
|
||||
LintId::of(attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
|
||||
LintId::of(eval_order_dependence::EVAL_ORDER_DEPENDENCE),
|
||||
LintId::of(float_equality_without_abs::FLOAT_EQUALITY_WITHOUT_ABS),
|
||||
LintId::of(formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING),
|
||||
LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING),
|
||||
LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
|
||||
LintId::of(loops::EMPTY_LOOP),
|
||||
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
|
||||
LintId::of(loops::MUT_RANGE_BOUND),
|
||||
LintId::of(methods::SUSPICIOUS_MAP),
|
||||
LintId::of(mut_key::MUTABLE_KEY_TYPE),
|
||||
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
|
||||
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
|
||||
]);
|
||||
|
||||
store.register_group(true, "clippy::perf", Some("clippy_perf"), vec![
|
||||
LintId::of(entry::MAP_ENTRY),
|
||||
LintId::of(escape::BOXED_LOCAL),
|
||||
|
|
|
@ -199,7 +199,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub FOR_LOOPS_OVER_FALLIBLES,
|
||||
correctness,
|
||||
suspicious,
|
||||
"for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ declare_clippy_lint! {
|
|||
/// loop {}
|
||||
/// ```
|
||||
pub EMPTY_LOOP,
|
||||
style,
|
||||
suspicious,
|
||||
"empty `loop {}`, which should block or sleep"
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub MUT_RANGE_BOUND,
|
||||
complexity,
|
||||
suspicious,
|
||||
"for loop over a range where one of the bounds is a mutable variable"
|
||||
}
|
||||
|
||||
|
|
|
@ -1248,7 +1248,7 @@ declare_clippy_lint! {
|
|||
/// let _ = (0..3).map(|x| x + 2).count();
|
||||
/// ```
|
||||
pub SUSPICIOUS_MAP,
|
||||
complexity,
|
||||
suspicious,
|
||||
"suspicious usage of map"
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub MUTABLE_KEY_TYPE,
|
||||
correctness,
|
||||
suspicious,
|
||||
"Check for mutable `Map`/`Set` key type"
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub SUSPICIOUS_ARITHMETIC_IMPL,
|
||||
correctness,
|
||||
suspicious,
|
||||
"suspicious use of operators in impl of arithmetic trait"
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ declare_clippy_lint! {
|
|||
/// }
|
||||
/// ```
|
||||
pub SUSPICIOUS_OP_ASSIGN_IMPL,
|
||||
correctness,
|
||||
suspicious,
|
||||
"suspicious use of operators in impl of OpAssign trait"
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,9 @@ const DEPRECATED_LINT_GROUP_STR: &str = "deprecated";
|
|||
const DEPRECATED_LINT_LEVEL: &str = "none";
|
||||
/// This array holds Clippy's lint groups with their corresponding default lint level. The
|
||||
/// lint level for deprecated lints is set in `DEPRECATED_LINT_LEVEL`.
|
||||
const DEFAULT_LINT_LEVELS: [(&str, &str); 8] = [
|
||||
const DEFAULT_LINT_LEVELS: &[(&str, &str)] = &[
|
||||
("correctness", "deny"),
|
||||
("suspicious", "warn"),
|
||||
("restriction", "allow"),
|
||||
("style", "warn"),
|
||||
("pedantic", "allow"),
|
||||
|
|
|
@ -4,7 +4,7 @@ error: mutable key type
|
|||
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[deny(clippy::mutable_key_type)]` on by default
|
||||
= note: `-D clippy::mutable-key-type` implied by `-D warnings`
|
||||
|
||||
error: mutable key type
|
||||
--> $DIR/mut_key.rs:27:72
|
||||
|
|
|
@ -12,7 +12,7 @@ error: suspicious use of binary operator in `AddAssign` impl
|
|||
LL | *self = *self - other;
|
||||
| ^
|
||||
|
|
||||
= note: `#[deny(clippy::suspicious_op_assign_impl)]` on by default
|
||||
= note: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings`
|
||||
|
||||
error: suspicious use of binary operator in `MulAssign` impl
|
||||
--> $DIR/suspicious_arithmetic_impl.rs:32:16
|
||||
|
|
|
@ -19,6 +19,7 @@ comment_re = re.compile(r'''\s*/// ?(.*)''')
|
|||
|
||||
lint_levels = {
|
||||
"correctness": 'Deny',
|
||||
"suspicious": 'Warn',
|
||||
"style": 'Warn',
|
||||
"complexity": 'Warn',
|
||||
"perf": 'Warn',
|
||||
|
|
Loading…
Reference in a new issue