Skip to content

Commit

Permalink
python: Consider boolean operator in tuples for cognitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 committed Mar 8, 2021
1 parent 8411302 commit 2a865e7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/metrics/cognitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Cognitive for PythonCode {
ExceptClause => {
increment(stats);
}
ExpressionList | ExpressionStatement => {
ExpressionList | ExpressionStatement | Tuple => {
stats.boolean_seq.reset();
}
NotOperator => {
Expand Down Expand Up @@ -497,6 +497,19 @@ mod tests {
);
}

#[test]
fn python_tuple() {
check_metrics!(
"def f(a, b):
return \"%s%s\" % (a and \"Get\" or \"Set\", b)",
"foo.py",
PythonParser,
cognitive,
[(cognitive, 2, usize)],
[(cognitive_average, 2.0)]
);
}

#[test]
fn python_elif_function() {
check_metrics!(
Expand Down

0 comments on commit 2a865e7

Please sign in to comment.