Make panic in CC silencable (partial #478)
This commit is contained in:
parent
5827240e17
commit
dc414e6c02
3 changed files with 26 additions and 12 deletions
|
@ -4,5 +4,5 @@ sudo: false
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- python util/update_lints.py -c
|
- python util/update_lints.py -c
|
||||||
- cargo test
|
- cargo test --features debugging
|
||||||
- bash util/dogfood.sh
|
- bash util/dogfood.sh
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "clippy"
|
name = "clippy"
|
||||||
version = "0.0.27"
|
version = "0.0.28"
|
||||||
authors = [
|
authors = [
|
||||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||||
"Andre Bogus <bogusandre@gmail.com>",
|
"Andre Bogus <bogusandre@gmail.com>",
|
||||||
|
@ -28,3 +28,4 @@ lazy_static = "*"
|
||||||
[features]
|
[features]
|
||||||
|
|
||||||
structured_logging = []
|
structured_logging = []
|
||||||
|
debugging = []
|
||||||
|
|
|
@ -44,17 +44,16 @@ impl CyclomaticComplexity {
|
||||||
if narms > 0 {
|
if narms > 0 {
|
||||||
narms = narms - 1;
|
narms = narms - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc < narms {
|
if cc < narms {
|
||||||
println!("cc = {}, arms = {}", cc, narms);
|
report_cc_bug(cx, cc, narms, span);
|
||||||
println!("{:?}", block);
|
} else {
|
||||||
println!("{:?}", span);
|
let rust_cc = cc - narms;
|
||||||
panic!("cc = {}, arms = {}", cc, narms);
|
if rust_cc > self.limit.limit() {
|
||||||
}
|
cx.span_lint_help(CYCLOMATIC_COMPLEXITY, span,
|
||||||
let rust_cc = cc - narms;
|
&format!("The function has a cyclomatic complexity of {}.", rust_cc),
|
||||||
if rust_cc > self.limit.limit() {
|
"You could split it up into multiple smaller functions");
|
||||||
cx.span_lint_help(CYCLOMATIC_COMPLEXITY, span,
|
}
|
||||||
&format!("The function has a cyclomatic complexity of {}.", rust_cc),
|
|
||||||
"You could split it up into multiple smaller functions");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,3 +102,17 @@ impl<'a> Visitor<'a> for MatchArmCounter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature="debugging")]
|
||||||
|
fn report_cc_bug(cx: &LateContext, cc: u64, narms: u64, span: Span) {
|
||||||
|
cx.sess().span_bug(span, &format!("Clippy encountered a bug calculating cyclomatic complexity: \
|
||||||
|
cc = {}, arms = {}. Please file a bug report.", cc, narms));;
|
||||||
|
}
|
||||||
|
#[cfg(not(feature="debugging"))]
|
||||||
|
fn report_cc_bug(cx: &LateContext, cc: u64, narms: u64, span: Span) {
|
||||||
|
if cx.current_level(CYCLOMATIC_COMPLEXITY) != Level::Allow {
|
||||||
|
cx.sess().span_note(span, &format!("Clippy encountered a bug calculating cyclomatic complexity \
|
||||||
|
(hide this message with `#[allow(cyclomatic_complexity)]`): \
|
||||||
|
cc = {}, arms = {}. Please file a bug report.", cc, narms));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue