Skip to content

Commit

Permalink
Merge pull request #34 from rohaquinlop/issue-16
Browse files Browse the repository at this point in the history
fix(algorithm): #16 fix cognitive complexity
  • Loading branch information
rohaquinlop committed Mar 12, 2024
2 parents 3f3b313 + bad6590 commit 294bba3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "complexipy"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Robin Quintero <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion complexipy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
root_dir = Path(__file__).resolve().parent.parent
app = typer.Typer(name="complexipy")
console = Console()
version = "0.3.0"
version = "0.3.1"


@app.command()
Expand Down
7 changes: 6 additions & 1 deletion src/cognitive_complexity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ fn statement_cognitive_complexity(statement: Stmt, nesting_level: u64) -> PyResu
}
}
Stmt::Assign(a) => {
complexity += count_bool_ops(*a.value);
match *a.value {
ast::Expr::IfExp(..) => {
complexity += count_bool_ops(*a.value);
}
_ => {}
}

if complexity > 0 {
complexity += nesting_level;
Expand Down
11 changes: 4 additions & 7 deletions src/cognitive_complexity/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,13 @@ pub fn count_bool_ops(expr: ast::Expr) -> u64 {
let mut complexity: u64 = 0;

match expr {
ast::Expr::BoolOp(..) => {
ast::Expr::BoolOp(b) => {
complexity += 1;
}
ast::Expr::BinOp(b) => {
complexity += 1;
complexity += count_bool_ops(*b.left);
complexity += count_bool_ops(*b.right);
for value in b.values.iter() {
complexity += count_bool_ops(value.clone());
}
}
ast::Expr::UnaryOp(u) => {
complexity += 1;
complexity += count_bool_ops(*u.operand);
}
ast::Expr::Compare(c) => {
Expand Down

0 comments on commit 294bba3

Please sign in to comment.