Renamed: Cyclomatic Complexity -> Cognitive Complexity

* Ran automatic naming update

* Formalized rename of `cyclomatic_complexity` to `cognitive_complexity`
** Added the rename to `lib.rs`
** Added rename test

* Added warning for deprecated key `cyclomatic_complexity_threshold` and tests for it

* Added deprecation status for Clippy's builtin attribute

* Updated tests for new builtin attribute renaming
This commit is contained in:
Félix Fischer 2019-02-22 22:19:50 -03:00
parent 15d1731ce8
commit ddc718087f
29 changed files with 176 additions and 121 deletions

View file

@ -798,11 +798,11 @@ All notable changes to this project will be documented in this file.
[`cmp_nan`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_nan
[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
[`cyclomatic_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cyclomatic_complexity
[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const

View file

@ -131,7 +131,7 @@ Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml
```toml
blacklisted-names = ["toto", "tata", "titi"]
cyclomatic-complexity-threshold = 30
cognitive-complexity-threshold = 30
```
See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which lints can be configured and the

View file

@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
},
hir::ExprKind::Assign(assignee, e) => {
if let hir::ExprKind::Binary(op, l, r) = &e.node {
#[allow(clippy::cyclomatic_complexity)]
#[allow(clippy::cognitive_complexity)]
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
let ty = cx.tables.expr_ty(assignee);
let rty = cx.tables.expr_ty(rhs);

View file

@ -1,4 +1,4 @@
//! calculate cyclomatic complexity and warn about overly complex functions
//! calculate cognitive complexity and warn about overly complex functions
use rustc::cfg::CFG;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
@ -12,25 +12,25 @@ use syntax::source_map::Span;
use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
declare_clippy_lint! {
/// **What it does:** Checks for methods with high cyclomatic complexity.
/// **What it does:** Checks for methods with high cognitive complexity.
///
/// **Why is this bad?** Methods of high cyclomatic complexity tend to be badly
/// readable. Also LLVM will usually optimize small methods better.
/// **Why is this bad?** Methods of high cognitive complexity tend to be hard to
/// both read and maintain. Also LLVM will tend to optimize small methods better.
///
/// **Known problems:** Sometimes it's hard to find a way to reduce the
/// complexity.
///
/// **Example:** No. You'll see it when you get the warning.
pub CYCLOMATIC_COMPLEXITY,
pub COGNITIVE_COMPLEXITY,
complexity,
"functions that should be split up into multiple functions"
}
pub struct CyclomaticComplexity {
pub struct CognitiveComplexity {
limit: LimitStack,
}
impl CyclomaticComplexity {
impl CognitiveComplexity {
pub fn new(limit: u64) -> Self {
Self {
limit: LimitStack::new(limit),
@ -38,17 +38,17 @@ impl CyclomaticComplexity {
}
}
impl LintPass for CyclomaticComplexity {
impl LintPass for CognitiveComplexity {
fn get_lints(&self) -> LintArray {
lint_array!(CYCLOMATIC_COMPLEXITY)
lint_array!(COGNITIVE_COMPLEXITY)
}
fn name(&self) -> &'static str {
"CyclomaticComplexity"
"CognitiveComplexity"
}
}
impl CyclomaticComplexity {
impl CognitiveComplexity {
fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {
if in_macro(span) {
return;
@ -105,9 +105,9 @@ impl CyclomaticComplexity {
if rust_cc > self.limit.limit() {
span_help_and_lint(
cx,
CYCLOMATIC_COMPLEXITY,
COGNITIVE_COMPLEXITY,
span,
&format!("the function has a cyclomatic complexity of {}", rust_cc),
&format!("the function has a cognitive complexity of {}", rust_cc),
"you could split it up into multiple smaller functions",
);
}
@ -115,7 +115,7 @@ impl CyclomaticComplexity {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CyclomaticComplexity {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
@ -132,10 +132,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CyclomaticComplexity {
}
fn enter_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) {
self.limit.push_attrs(cx.sess(), attrs, "cyclomatic_complexity");
self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity");
}
fn exit_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) {
self.limit.pop_attrs(cx.sess(), attrs, "cyclomatic_complexity");
self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
}
}
@ -201,7 +201,7 @@ fn report_cc_bug(
) {
span_bug!(
span,
"Clippy encountered a bug calculating cyclomatic complexity: cc = {}, arms = {}, \
"Clippy encountered a bug calculating cognitive complexity: cc = {}, arms = {}, \
div = {}, shorts = {}, returns = {}. Please file a bug report.",
cc,
narms,
@ -222,12 +222,12 @@ fn report_cc_bug(
span: Span,
id: HirId,
) {
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
if !is_allowed(cx, COGNITIVE_COMPLEXITY, id) {
cx.sess().span_note_without_error(
span,
&format!(
"Clippy encountered a bug calculating cyclomatic complexity \
(hide this message with `#[allow(cyclomatic_complexity)]`): \
"Clippy encountered a bug calculating cognitive complexity \
(hide this message with `#[allow(cognitive_complexity)]`): \
cc = {}, arms = {}, div = {}, shorts = {}, returns = {}. \
Please file a bug report.",
cc, narms, div, shorts, returns

View file

@ -152,11 +152,11 @@ pub mod block_in_if_condition;
pub mod booleans;
pub mod bytecount;
pub mod cargo_common_metadata;
pub mod cognitive_complexity;
pub mod collapsible_if;
pub mod const_static_lifetime;
pub mod copies;
pub mod copy_iterator;
pub mod cyclomatic_complexity;
pub mod dbg_macro;
pub mod default_trait_access;
pub mod derive;
@ -478,7 +478,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box temporary_assignment::Pass);
reg.register_late_lint_pass(box transmute::Transmute);
reg.register_late_lint_pass(
box cyclomatic_complexity::CyclomaticComplexity::new(conf.cyclomatic_complexity_threshold)
box cognitive_complexity::CognitiveComplexity::new(conf.cognitive_complexity_threshold)
);
reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
reg.register_early_lint_pass(box misc_early::MiscEarly);
@ -666,11 +666,11 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
booleans::LOGIC_BUG,
booleans::NONMINIMAL_BOOL,
bytecount::NAIVE_BYTECOUNT,
cognitive_complexity::COGNITIVE_COMPLEXITY,
collapsible_if::COLLAPSIBLE_IF,
const_static_lifetime::CONST_STATIC_LIFETIME,
copies::IFS_SAME_COND,
copies::IF_SAME_THEN_ELSE,
cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
derive::DERIVE_HASH_XOR_EQ,
double_comparison::DOUBLE_COMPARISONS,
double_parens::DOUBLE_PARENS,
@ -962,7 +962,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
assign_ops::MISREFACTORED_ASSIGN_OP,
attrs::DEPRECATED_CFG_ATTR,
booleans::NONMINIMAL_BOOL,
cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
cognitive_complexity::COGNITIVE_COMPLEXITY,
double_comparison::DOUBLE_COMPARISONS,
double_parens::DOUBLE_PARENS,
duration_subsec::DURATION_SUBSEC,
@ -1131,6 +1131,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity");
}
// only exists to let the dogfood integration test works.

View file

@ -821,7 +821,7 @@ impl LintPass for Pass {
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
#[allow(clippy::cyclomatic_complexity)]
#[allow(clippy::cognitive_complexity)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if in_macro(expr.span) {
return;

View file

@ -15,7 +15,11 @@ pub enum DeprecationStatus {
pub const BUILTIN_ATTRIBUTES: &[(&str, DeprecationStatus)] = &[
("author", DeprecationStatus::None),
("cyclomatic_complexity", DeprecationStatus::None),
("cognitive_complexity", DeprecationStatus::None),
(
"cyclomatic_complexity",
DeprecationStatus::Replaced("cognitive_complexity"),
),
("dump", DeprecationStatus::None),
];

View file

@ -110,8 +110,10 @@ macro_rules! define_Conf {
define_Conf! {
/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about
(blacklisted_names, "blacklisted_names", ["foo", "bar", "baz", "quux"] => Vec<String>),
/// Lint: CYCLOMATIC_COMPLEXITY. The maximum cyclomatic complexity a function can have
(cyclomatic_complexity_threshold, "cyclomatic_complexity_threshold", 25 => u64),
/// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have
(cognitive_complexity_threshold, "cognitive_complexity_threshold", 25 => u64),
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
(cyclomatic_complexity_threshold, "cyclomatic_complexity_threshold", None => Option<u64>),
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
(doc_valid_idents, "doc_valid_idents", [
"KiB", "MiB", "GiB", "TiB", "PiB", "EiB",
@ -227,13 +229,24 @@ pub fn read(path: Option<&path::Path>) -> (Conf, Vec<Error>) {
assert!(ERRORS.lock().expect("no threading -> mutex always safe").is_empty());
match toml::from_str(&file) {
Ok(toml) => (
toml,
ERRORS.lock().expect("no threading -> mutex always safe").split_off(0),
),
Ok(toml) => {
let mut errors = ERRORS.lock().expect("no threading -> mutex always safe").split_off(0);
let toml_ref: &Conf = &toml;
let cyc_field: Option<u64> = toml_ref.cyclomatic_complexity_threshold;
if cyc_field.is_some() {
let cyc_err = "found deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead.".to_string();
errors.push(Error::Toml(cyc_err));
}
(toml, errors)
},
Err(e) => {
let mut errors = ERRORS.lock().expect("no threading -> mutex always safe").split_off(0);
errors.push(Error::Toml(e.to_string()));
default(errors)
},
}

View file

@ -0,0 +1,6 @@
# that one is an error
cyclomatic-complexity-threshold = 42
# that one is white-listed
[third-party]
clippy-feature = "nightly"

View file

@ -0,0 +1,4 @@
// error-pattern: error reading Clippy's configuration file: found deprecated field
// `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead.
fn main() {}

View file

@ -0,0 +1,4 @@
error: error reading Clippy's configuration file `$DIR/clippy.toml`: found deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead.
error: aborting due to previous error

View file

@ -0,0 +1,3 @@
# that one is white-listed
[third-party]
clippy-feature = "nightly"

View file

@ -0,0 +1,3 @@
// error-pattern: should give absolutely no error
fn main() {}

View file

@ -1,4 +1,4 @@
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `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`, `third-party`
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`, `third-party`
error: aborting due to previous error

View file

@ -1,5 +1,5 @@
#![allow(clippy::all)]
#![warn(clippy::cyclomatic_complexity)]
#![warn(clippy::cognitive_complexity)]
#![allow(unused)]
#[rustfmt::skip]
@ -87,7 +87,7 @@ fn main() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn kaboom() {
let n = 0;
'a: for i in 0..20 {
@ -133,17 +133,17 @@ fn bloo() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn lots_of_short_circuits() -> bool {
true && false && true && false && true && false && true
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn lots_of_short_circuits2() -> bool {
true || false || true || false || true || false || true
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn baa() {
let x = || match 99 {
0 => 0,
@ -161,7 +161,7 @@ fn baa() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn bar() {
match 99 {
0 => println!("hi"),
@ -170,8 +170,8 @@ fn bar() {
}
#[test]
#[clippy::cyclomatic_complexity = "0"]
/// Tests are usually complex but simple at the same time. `clippy::cyclomatic_complexity` used to
#[clippy::cognitive_complexity = "0"]
/// Tests are usually complex but simple at the same time. `clippy::cognitive_complexity` used to
/// give lots of false-positives in tests.
fn dont_warn_on_tests() {
match 99 {
@ -180,7 +180,7 @@ fn dont_warn_on_tests() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn barr() {
match 99 {
0 => println!("hi"),
@ -190,7 +190,7 @@ fn barr() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn barr2() {
match 99 {
0 => println!("hi"),
@ -206,7 +206,7 @@ fn barr2() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn barrr() {
match 99 {
0 => println!("hi"),
@ -216,7 +216,7 @@ fn barrr() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn barrr2() {
match 99 {
0 => println!("hi"),
@ -232,7 +232,7 @@ fn barrr2() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn barrrr() {
match 99 {
0 => println!("hi"),
@ -242,7 +242,7 @@ fn barrrr() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn barrrr2() {
match 99 {
0 => println!("hi"),
@ -258,7 +258,7 @@ fn barrrr2() {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn cake() {
if 4 == 5 {
println!("yea");
@ -268,7 +268,7 @@ fn cake() {
println!("whee");
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
pub fn read_file(input_path: &str) -> String {
use std::fs::File;
use std::io::{Read, Write};
@ -299,20 +299,20 @@ pub fn read_file(input_path: &str) -> String {
enum Void {}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn void(void: Void) {
if true {
match void {}
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn mcarton_sees_all() {
panic!("meh");
panic!("möh");
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn try() -> Result<i32, &'static str> {
match 5 {
5 => Ok(5),
@ -320,7 +320,7 @@ fn try() -> Result<i32, &'static str> {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn try_again() -> Result<i32, &'static str> {
let _ = try!(Ok(42));
let _ = try!(Ok(43));
@ -336,7 +336,7 @@ fn try_again() -> Result<i32, &'static str> {
}
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn early() -> Result<i32, &'static str> {
return Ok(5);
return Ok(5);
@ -350,7 +350,7 @@ fn early() -> Result<i32, &'static str> {
}
#[rustfmt::skip]
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn early_ret() -> i32 {
let a = if true { 42 } else { return 0; };
let a = if a < 99 { 42 } else { return 0; };

View file

@ -1,5 +1,5 @@
error: the function has a cyclomatic complexity of 28
--> $DIR/cyclomatic_complexity.rs:6:1
error: the function has a cognitive complexity of 28
--> $DIR/cognitive_complexity.rs:6:1
|
LL | / fn main() {
LL | | if true {
@ -10,11 +10,11 @@ LL | | }
LL | | }
| |_^
|
= note: `-D clippy::cyclomatic-complexity` implied by `-D warnings`
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 7
--> $DIR/cyclomatic_complexity.rs:91:1
error: the function has a cognitive complexity of 7
--> $DIR/cognitive_complexity.rs:91:1
|
LL | / fn kaboom() {
LL | | let n = 0;
@ -27,8 +27,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:137:1
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:137:1
|
LL | / fn lots_of_short_circuits() -> bool {
LL | | true && false && true && false && true && false && true
@ -37,8 +37,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:142:1
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:142:1
|
LL | / fn lots_of_short_circuits2() -> bool {
LL | | true || false || true || false || true || false || true
@ -47,8 +47,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:147:1
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:147:1
|
LL | / fn baa() {
LL | | let x = || match 99 {
@ -61,8 +61,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:148:13
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:148:13
|
LL | let x = || match 99 {
| _____________^
@ -76,8 +76,8 @@ LL | | };
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:165:1
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:165:1
|
LL | / fn bar() {
LL | | match 99 {
@ -89,8 +89,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:184:1
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:184:1
|
LL | / fn barr() {
LL | | match 99 {
@ -103,8 +103,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:194:1
error: the function has a cognitive complexity of 3
--> $DIR/cognitive_complexity.rs:194:1
|
LL | / fn barr2() {
LL | | match 99 {
@ -117,8 +117,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:210:1
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:210:1
|
LL | / fn barrr() {
LL | | match 99 {
@ -131,8 +131,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:220:1
error: the function has a cognitive complexity of 3
--> $DIR/cognitive_complexity.rs:220:1
|
LL | / fn barrr2() {
LL | | match 99 {
@ -145,8 +145,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:236:1
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:236:1
|
LL | / fn barrrr() {
LL | | match 99 {
@ -159,8 +159,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:246:1
error: the function has a cognitive complexity of 3
--> $DIR/cognitive_complexity.rs:246:1
|
LL | / fn barrrr2() {
LL | | match 99 {
@ -173,8 +173,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:262:1
error: the function has a cognitive complexity of 2
--> $DIR/cognitive_complexity.rs:262:1
|
LL | / fn cake() {
LL | | if 4 == 5 {
@ -187,8 +187,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 4
--> $DIR/cyclomatic_complexity.rs:272:1
error: the function has a cognitive complexity of 4
--> $DIR/cognitive_complexity.rs:272:1
|
LL | / pub fn read_file(input_path: &str) -> String {
LL | | use std::fs::File;
@ -201,8 +201,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:303:1
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:303:1
|
LL | / fn void(void: Void) {
LL | | if true {
@ -213,8 +213,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:316:1
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:316:1
|
LL | / fn try() -> Result<i32, &'static str> {
LL | | match 5 {
@ -226,8 +226,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:324:1
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:324:1
|
LL | / fn try_again() -> Result<i32, &'static str> {
LL | | let _ = try!(Ok(42));
@ -240,8 +240,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:340:1
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:340:1
|
LL | / fn early() -> Result<i32, &'static str> {
LL | | return Ok(5);
@ -254,8 +254,8 @@ LL | | }
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 8
--> $DIR/cyclomatic_complexity.rs:354:1
error: the function has a cognitive complexity of 8
--> $DIR/cognitive_complexity.rs:354:1
|
LL | / fn early_ret() -> i32 {
LL | | let a = if true { 42 } else { return 0; };

View file

@ -1,11 +1,11 @@
#![warn(clippy::cyclomatic_complexity)]
#![warn(clippy::cognitive_complexity)]
#![warn(unused)]
fn main() {
kaboom();
}
#[clippy::cyclomatic_complexity = "0"]
#[clippy::cognitive_complexity = "0"]
fn kaboom() {
if 42 == 43 {
panic!();

View file

@ -1,5 +1,5 @@
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity_attr_used.rs:9:1
error: the function has a cognitive complexity of 3
--> $DIR/cognitive_complexity_attr_used.rs:9:1
|
LL | / fn kaboom() {
LL | | if 42 == 43 {
@ -10,7 +10,7 @@ LL | | }
LL | | }
| |_^
|
= note: `-D clippy::cyclomatic-complexity` implied by `-D warnings`
= 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

View file

@ -1,5 +1,5 @@
// run-rustfix
#![allow(clippy::cyclomatic_complexity, clippy::assertions_on_constants)]
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]

View file

@ -1,5 +1,5 @@
// run-rustfix
#![allow(clippy::cyclomatic_complexity, clippy::assertions_on_constants)]
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]

View file

@ -29,7 +29,7 @@ impl Unrelated {
clippy::linkedlist,
clippy::shadow_unrelated,
clippy::unnecessary_mut_passed,
clippy::cyclomatic_complexity,
clippy::cognitive_complexity,
clippy::similar_names
)]
#[allow(clippy::many_single_char_names, unused_variables, clippy::into_iter_on_array)]

View file

@ -2,7 +2,7 @@
#![allow(
clippy::blacklisted_name,
clippy::collapsible_if,
clippy::cyclomatic_complexity,
clippy::cognitive_complexity,
clippy::eq_op,
clippy::needless_return,
clippy::never_loop,

View file

@ -1,7 +1,7 @@
#![allow(
clippy::blacklisted_name,
clippy::collapsible_if,
clippy::cyclomatic_complexity,
clippy::cognitive_complexity,
clippy::eq_op,
clippy::needless_continue,
clippy::needless_return,

View file

@ -1,4 +1,5 @@
#![allow(stutter)]
#![warn(clippy::cyclomatic_complexity)]
#[warn(clippy::stutter)]
fn main() {}

View file

@ -6,16 +6,22 @@ LL | #![allow(stutter)]
|
= note: `-D unknown-lints` implied by `-D warnings`
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
--> $DIR/rename.rs:3:8
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
--> $DIR/rename.rs:2:9
|
LL | #[warn(clippy::stutter)]
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
LL | #![warn(clippy::cyclomatic_complexity)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
|
= note: `-D renamed-and-removed-lints` implied by `-D warnings`
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
--> $DIR/rename.rs:4:8
|
LL | #[warn(clippy::stutter)]
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
--> $DIR/rename.rs:6:8
--> $DIR/rename.rs:7:8
|
LL | #[warn(clippy::new_without_default_derive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default`
@ -26,11 +32,11 @@ error: unknown lint: `stutter`
LL | #![allow(stutter)]
| ^^^^^^^
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
--> $DIR/rename.rs:3:8
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
--> $DIR/rename.rs:2:9
|
LL | #[warn(clippy::stutter)]
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
LL | #![warn(clippy::cyclomatic_complexity)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
error: aborting due to 5 previous errors
error: aborting due to 6 previous errors

View file

@ -0,0 +1,2 @@
#[clippy::cyclomatic_complexity = "1"]
fn main() {}

View file

@ -0,0 +1,8 @@
error: Usage of deprecated attribute
--> $DIR/renamed_builtin_attr.rs:1:11
|
LL | #[clippy::cyclomatic_complexity = "1"]
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity`
error: aborting due to previous error

View file

@ -1,3 +1,3 @@
#[clippy::unknown]
#[clippy::cyclomatic_complexity = "1"]
#[clippy::cognitive_complexity = "1"]
fn main() {}

View file

@ -1,5 +1,5 @@
#![warn(clippy::while_let_loop, clippy::empty_loop, clippy::while_let_on_iterator)]
#![allow(dead_code, clippy::never_loop, unused, clippy::cyclomatic_complexity)]
#![allow(dead_code, clippy::never_loop, unused, clippy::cognitive_complexity)]
fn main() {
let y = Some(true);