Ignore #[test]
fns in cyclomatic_complexity
This commit is contained in:
parent
c23b684ea5
commit
831b8fc1b5
@ -1,12 +1,12 @@
|
||||
//! calculate cyclomatic complexity and warn about overly complex functions
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::cfg::CFG;
|
||||
use rustc::lint::*;
|
||||
use rustc::ty;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::{Visitor, walk_expr};
|
||||
use syntax::ast::Attribute;
|
||||
use syntax::attr::*;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use utils::{in_macro, LimitStack, span_help_and_lint};
|
||||
@ -44,6 +44,7 @@ impl CyclomaticComplexity {
|
||||
if in_macro(cx, span) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cfg = CFG::new(cx.tcx, block);
|
||||
let n = cfg.graph.len_nodes() as u64;
|
||||
let e = cfg.graph.len_edges() as u64;
|
||||
@ -84,7 +85,9 @@ impl CyclomaticComplexity {
|
||||
impl LateLintPass for CyclomaticComplexity {
|
||||
fn check_item(&mut self, cx: &LateContext, item: &Item) {
|
||||
if let ItemFn(_, _, _, _, _, ref block) = item.node {
|
||||
self.check(cx, block, item.span);
|
||||
if !attr::contains_name(&item.attrs, "test") {
|
||||
self.check(cx, block, item.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,6 +171,17 @@ fn bar() { //~ ERROR: the function has a cyclomatic complexity of 2
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cyclomatic_complexity = "0"]
|
||||
/// Tests are usually complex but simple at the same time. `cyclomatic_complexity` used to give
|
||||
/// lots of false-positives in tests.
|
||||
fn dont_warn_on_tests() {
|
||||
match 99 {
|
||||
0 => println!("hi"),
|
||||
_ => println!("bye"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cyclomatic_complexity = "0"]
|
||||
fn barr() { //~ ERROR: the function has a cyclomatic complexity of 2
|
||||
match 99 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user