complexipy 8.3.0__tar.gz → 9.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. {complexipy-8.3.0 → complexipy-9.0.0}/Cargo.lock +7 -6
  2. {complexipy-8.3.0 → complexipy-9.0.0}/Cargo.toml +2 -1
  3. {complexipy-8.3.0 → complexipy-9.0.0}/PKG-INFO +80 -36
  4. {complexipy-8.3.0 → complexipy-9.0.0}/README.md +79 -35
  5. {complexipy-8.3.0 → complexipy-9.0.0}/complexipy/__init__.py +2 -0
  6. {complexipy-8.3.0 → complexipy-9.0.0}/complexipy/_complexipy.pyi +12 -0
  7. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/Cargo.toml +1 -1
  8. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/args.rs +6 -0
  9. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/main.rs +2 -1
  10. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/diff/tests.rs +21 -1
  11. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/diff.rs +24 -1
  12. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/fix/tests.rs +37 -0
  13. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/fix.rs +32 -27
  14. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/messages/tests.rs +40 -3
  15. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/messages.rs +24 -0
  16. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/refactor/tests.rs +24 -1
  17. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/refactor.rs +14 -4
  18. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/render/tests.rs +7 -6
  19. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/render.rs +46 -7
  20. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/rows/tests.rs +3 -0
  21. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output/rows.rs +1 -0
  22. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/output.rs +49 -4
  23. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/run/tests.rs +46 -2
  24. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/run.rs +119 -58
  25. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/types.rs +14 -2
  26. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/config/tests.rs +14 -1
  27. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/config.rs +6 -0
  28. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/fix/tests.rs +2 -2
  29. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/fix.rs +2 -6
  30. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/gitlab.rs +16 -10
  31. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/paths/tests.rs +9 -3
  32. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/paths.rs +7 -5
  33. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/sarif.rs +12 -3
  34. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/Cargo.toml +1 -0
  35. complexipy-9.0.0/crates/complexipy-core/src/bindings/tests.rs +219 -0
  36. complexipy-9.0.0/crates/complexipy-core/src/bindings.rs +293 -0
  37. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/classes.rs +12 -0
  38. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/cognitive_complexity.rs +305 -99
  39. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/config.rs +10 -1
  40. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/diff/tests.rs +141 -0
  41. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/diff.rs +220 -2
  42. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/fix/tests.rs +90 -0
  43. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/fix.rs +164 -35
  44. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/lib.rs +8 -4
  45. complexipy-9.0.0/crates/complexipy-core/src/recursion/tests.rs +400 -0
  46. complexipy-9.0.0/crates/complexipy-core/src/recursion.rs +1278 -0
  47. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules/complexity/tests.rs +47 -24
  48. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules/complexity.rs +89 -35
  49. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules/registry/tests.rs +29 -5
  50. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules/registry.rs +23 -2
  51. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules/types/tests.rs +68 -17
  52. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules/types.rs +38 -8
  53. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/rules.rs +9 -1
  54. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/runner.rs +30 -0
  55. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/utils/export_tests.rs +30 -1
  56. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/utils.rs +232 -116
  57. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/deep_expressions.rs +12 -1
  58. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/main.rs +3 -0
  59. complexipy-9.0.0/crates/complexipy-core/tests/it/nested_ternaries.rs +36 -0
  60. complexipy-9.0.0/crates/complexipy-core/tests/it/python_constructs.rs +45 -0
  61. complexipy-9.0.0/crates/complexipy-core/tests/it/statement_parts.rs +157 -0
  62. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/Cargo.toml +1 -1
  63. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/analysis.rs +209 -10
  64. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/documents.rs +30 -0
  65. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/lib.rs +1 -0
  66. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/main.rs +2 -1
  67. complexipy-9.0.0/crates/complexipy-lsp/src/scan/tests.rs +279 -0
  68. complexipy-9.0.0/crates/complexipy-lsp/src/scan.rs +252 -0
  69. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/server/tests.rs +221 -3
  70. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/server.rs +362 -63
  71. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/workspace.rs +28 -0
  72. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/tests/it/analysis.rs +206 -4
  73. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/tests/it/protocol.rs +151 -13
  74. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-python/Cargo.toml +4 -1
  75. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-python/src/lib.rs +5 -3
  76. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-types/src/lib.rs +15 -0
  77. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-types/src/python/tests.rs +2 -2
  78. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-types/src/python.rs +3 -17
  79. {complexipy-8.3.0 → complexipy-9.0.0}/LICENSE +0 -0
  80. {complexipy-8.3.0 → complexipy-9.0.0}/complexipy/cli.py +0 -0
  81. {complexipy-8.3.0 → complexipy-9.0.0}/complexipy/py.typed +0 -0
  82. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/args/tests.rs +0 -0
  83. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/lib.rs +0 -0
  84. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/types/tests.rs +0 -0
  85. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/cache/tests.rs +0 -0
  86. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/cache.rs +0 -0
  87. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/fingerprint.rs +0 -0
  88. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/gitlab/tests.rs +0 -0
  89. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/ignored/tests.rs +0 -0
  90. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/ignored.rs +0 -0
  91. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/sarif/tests.rs +0 -0
  92. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/snapshot/tests.rs +0 -0
  93. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/snapshot.rs +0 -0
  94. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils/toml.rs +0 -0
  95. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-cli/src/utils.rs +0 -0
  96. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/api/tests.rs +0 -0
  97. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/api.rs +0 -0
  98. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/encoding/tests.rs +0 -0
  99. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/encoding.rs +0 -0
  100. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/fs_guard/tests.rs +0 -0
  101. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/fs_guard.rs +0 -0
  102. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/helpers/exclude/tests.rs +0 -0
  103. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/helpers/exclude.rs +0 -0
  104. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/helpers.rs +0 -0
  105. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/refactor_plans.rs +0 -0
  106. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/sanitize/tests.rs +0 -0
  107. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/sanitize.rs +0 -0
  108. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/syntax_tree/tests.rs +0 -0
  109. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/syntax_tree.rs +0 -0
  110. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/src/utils/tests.rs +0 -0
  111. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/config.rs +0 -0
  112. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/discovery.rs +0 -0
  113. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/exclude.rs +0 -0
  114. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/gate_coverage.rs +0 -0
  115. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/lib_surface.rs +0 -0
  116. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/line_endings.rs +0 -0
  117. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/plans_for_function.rs +0 -0
  118. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/python315.rs +0 -0
  119. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-core/tests/it/syntax_error.rs +0 -0
  120. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/transport/tests.rs +0 -0
  121. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/transport.rs +0 -0
  122. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/src/workspace/tests.rs +0 -0
  123. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/tests/it/documents.rs +0 -0
  124. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-lsp/tests/it/main.rs +0 -0
  125. {complexipy-8.3.0 → complexipy-9.0.0}/crates/complexipy-types/Cargo.toml +0 -0
  126. {complexipy-8.3.0 → complexipy-9.0.0}/pyproject.toml +0 -0
@@ -322,7 +322,7 @@ dependencies = [
322
322
 
323
323
  [[package]]
324
324
  name = "complexipy-cli"
325
- version = "8.3.0"
325
+ version = "9.0.0"
326
326
  dependencies = [
327
327
  "blake2",
328
328
  "clap",
@@ -345,7 +345,7 @@ dependencies = [
345
345
 
346
346
  [[package]]
347
347
  name = "complexipy-core"
348
- version = "8.3.0"
348
+ version = "9.0.0"
349
349
  dependencies = [
350
350
  "complexipy-types",
351
351
  "csv",
@@ -356,6 +356,7 @@ dependencies = [
356
356
  "regex",
357
357
  "ruff_python_ast",
358
358
  "ruff_python_parser",
359
+ "ruff_text_size",
359
360
  "schemars",
360
361
  "serde",
361
362
  "serde_json",
@@ -366,7 +367,7 @@ dependencies = [
366
367
 
367
368
  [[package]]
368
369
  name = "complexipy-lsp"
369
- version = "8.3.0"
370
+ version = "9.0.0"
370
371
  dependencies = [
371
372
  "complexipy-core",
372
373
  "crossbeam-channel",
@@ -380,7 +381,7 @@ dependencies = [
380
381
 
381
382
  [[package]]
382
383
  name = "complexipy-python"
383
- version = "8.3.0"
384
+ version = "9.0.0"
384
385
  dependencies = [
385
386
  "clap",
386
387
  "complexipy-cli",
@@ -394,7 +395,7 @@ dependencies = [
394
395
 
395
396
  [[package]]
396
397
  name = "complexipy-types"
397
- version = "8.3.0"
398
+ version = "9.0.0"
398
399
  dependencies = [
399
400
  "pyo3",
400
401
  "serde",
@@ -402,7 +403,7 @@ dependencies = [
402
403
 
403
404
  [[package]]
404
405
  name = "complexipy-wasm"
405
- version = "8.3.0"
406
+ version = "9.0.0"
406
407
  dependencies = [
407
408
  "complexipy-core",
408
409
  "console_error_panic_hook",
@@ -3,7 +3,7 @@ members = ["crates/*"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "8.3.0"
6
+ version = "9.0.0"
7
7
  edition = "2024"
8
8
  authors = ["Robin Quintero <rohaquinlop301@gmail.com>"]
9
9
  license = "MIT"
@@ -14,6 +14,7 @@ repository = "https://github.com/rohaquinlop/complexipy"
14
14
  [workspace.dependencies]
15
15
  ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", tag = "0.15.14", package = "ruff_python_parser" }
16
16
  ruff_python_ast = { git = "https://github.com/astral-sh/ruff.git", tag = "0.15.14", package = "ruff_python_ast" }
17
+ ruff_text_size = { git = "https://github.com/astral-sh/ruff.git", tag = "0.15.14", package = "ruff_text_size" }
17
18
  regex = "1.11.1"
18
19
  serde = { version = "1.0", features = ["derive"] }
19
20
  serde_json = "1.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: complexipy
3
- Version: 8.3.0
3
+ Version: 9.0.0
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Environment :: Console
6
6
  Classifier: Intended Audience :: Developers
@@ -52,6 +52,7 @@ Project-URL: Repository, https://github.com/rohaquinlop/complexipy
52
52
  <p>
53
53
  <a href="#installation">Installation</a> •
54
54
  <a href="#quick-start">Quick Start</a> •
55
+ <a href="#features">Features</a> •
55
56
  <a href="#integrations">Integrations</a> •
56
57
  <a href="#learn-more">Learn More</a> •
57
58
  <a href="https://complexipy.com/">Documentation</a> •
@@ -60,45 +61,66 @@ Project-URL: Repository, https://github.com/rohaquinlop/complexipy
60
61
  </p>
61
62
  </div>
62
63
 
63
- ## What is Cognitive Complexity?
64
-
65
- > Cognitive complexity measures how hard code is to understand by humans, not machines.
66
-
67
- Unlike traditional metrics like cyclomatic complexity, cognitive complexity accounts for nesting depth and control flow patterns that affect human comprehension. Inspired by [G. Ann Campbell's research](https://www.sonarsource.com/resources/cognitive-complexity/) at SonarSource, complexipy provides a fast, accurate implementation for Python.
68
-
69
- **Key benefits:**
70
-
71
- - **Human-focused** - Penalizes nesting, flow breaks, and human-unfriendly logic
72
- - **Actionable insights** - Identifies genuinely hard-to-maintain code
73
- - **Different from cyclomatic** - Measures readability while cyclomatic measures structural, testing, and branch density
74
-
75
- ## Common Questions
76
-
77
- **[How is complexity calculated?](https://complexipy.com/understanding-scores/)**
78
- Learn about the scoring algorithm, what each control structure contributes, and how nesting affects the final score.
79
-
80
- **[How does this compare to Ruff's PLR0912?](https://complexipy.com/comparison-with-ruff/)**
81
- Understand the key differences between cyclomatic complexity (Ruff) and cognitive complexity (complexipy), and why you might want to use both.
64
+ <p align="center">
65
+ <picture>
66
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/competitors-dark.svg">
67
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/competitors-light.svg">
68
+ <img alt="Bar chart of the wall time to score cognitive complexity of the Django codebase with complexipy, flake8-cognitive-complexity, and pylint-cognitive-complexity" src="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/competitors-light.svg">
69
+ </picture>
70
+ </p>
82
71
 
83
- **[Is this a SonarSource/Sonar product?](https://complexipy.com/about/)**
84
- No. complexipy is an independent project inspired by G. Ann Campbell's research, but it's not affiliated with or endorsed by SonarSource.
72
+ <p align="center"><i>Scoring cognitive complexity of the Django codebase (2,929 files). <a href="https://complexipy.com/benchmarks/">Benchmarks</a></i></p>
85
73
 
86
74
  ## Installation
87
75
 
88
76
  ```bash
89
- pip install complexipy
77
+ uv tool install complexipy
90
78
  # or
91
79
  uv add complexipy
92
80
  # or
93
- uv tool install complexipy
81
+ pip install complexipy
94
82
  ```
95
83
 
96
84
  The `--diff`, `--diff-only`, and `--staged` options require Git 2.30 or newer
97
85
  on your `PATH`. Check your version with `git --version`. Git is not required
98
86
  for analysis without these options.
99
87
 
88
+ ## What is Cognitive Complexity?
89
+
90
+ > Cognitive complexity measures how hard a function's control flow is to follow. Use it to keep code easy to review and change, whether a person or an AI agent wrote it.
91
+
92
+ These two functions have the same cyclomatic complexity, 4. Their cognitive complexity is different:
93
+
94
+ ```python
95
+ # Cognitive complexity: 3
96
+ def example1(a, b, c):
97
+ if a: # +1
98
+ return 1
99
+ if b: # +1
100
+ return 2
101
+ if c: # +1
102
+ return 3
103
+ return 4
104
+ ```
105
+
106
+ ```python
107
+ # Cognitive complexity: 6
108
+ def example2(a, b, c):
109
+ if a: # +1
110
+ if b: # +2 (1 + nesting_level)
111
+ if c: # +3 (1 + nesting_level)
112
+ return 1
113
+ return 4
114
+ ```
115
+
116
+ Nested code makes the reader hold more context, so each nesting level adds to the score. complexipy implements the [Cognitive Complexity](https://www.sonarsource.com/resources/cognitive-complexity/) metric by G. Ann Campbell for Python. [How scores are calculated](https://complexipy.com/understanding-scores/)
117
+
100
118
  ## Quick Start
101
119
 
120
+ <p align="center">
121
+ <img src="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/demo.gif" alt="complexipy scores each function in checkout.py, fails apply_discount at 14 against a limit of 10, and suggests extracting a helper function">
122
+ </p>
123
+
102
124
  ### Command Line
103
125
 
104
126
  ```bash
@@ -127,20 +149,41 @@ complexipy . --exclude "tests/**"
127
149
  from complexipy import file_complexity
128
150
 
129
151
  # Analyze a file
130
- result = file_complexity("app.py", check_script=True)
152
+ result = file_complexity("app.py")
131
153
  print(f"File complexity: {result.complexity}")
132
154
 
133
155
  for func in result.functions:
134
156
  print(f"{func.name}: {func.complexity}")
135
157
  ```
136
158
 
159
+ ## Features
160
+
161
+ - **Cognitive complexity scores** that follow G. Ann Campbell's paper. [How scores work](https://complexipy.com/understanding-scores/)
162
+ - **Gate only what a change makes worse**: `--diff` and `--staged` compare each function with a git reference. [Complexity diff](https://complexipy.com/diff-and-snapshots/#complexity-diff)
163
+ - **Snapshot baselines**: record the current state of an existing codebase, then fail only on new or worse functions. [Snapshots](https://complexipy.com/diff-and-snapshots/#snapshot-baselines)
164
+ - **Refactor suggestions and `--fix`**: rules such as guard clauses and extract helper, and automatic fixes where they are safe. [Refactoring rules](https://complexipy.com/refactoring-rules/)
165
+ - **Output formats**: JSON, CSV, SARIF for GitHub code scanning, and GitLab Code Quality. [Output formats](https://complexipy.com/usage-guide/#output-formats)
166
+ - **Language server**: inlay hints, hover, and warnings in VS Code, Neovim, and Zed. [Editor integration](https://complexipy.com/editors/)
167
+ - **GitHub Action and pre-commit hook** for CI. [Integrations](#integrations)
168
+
169
+ ## Common Questions
170
+
171
+ **[How is complexity calculated?](https://complexipy.com/understanding-scores/)**
172
+ Learn about the scoring algorithm, what each control structure contributes, and how nesting affects the final score.
173
+
174
+ **[How does this compare to Ruff's PLR0912?](https://complexipy.com/comparison-with-ruff/)**
175
+ Understand the key differences between cyclomatic complexity (Ruff) and cognitive complexity (complexipy), and why you might want to use both.
176
+
177
+ **[Is this a SonarSource/Sonar product?](https://complexipy.com/about/)**
178
+ No. complexipy is an independent project inspired by G. Ann Campbell's research, but it's not affiliated with or endorsed by SonarSource.
179
+
137
180
  ## Integrations
138
181
 
139
182
  <details>
140
183
  <summary><strong>🔧 GitHub Actions</strong></summary>
141
184
 
142
185
  ```yaml
143
- - uses: rohaquinlop/complexipy-action@v8
186
+ - uses: rohaquinlop/complexipy-action@v9
144
187
  with:
145
188
  paths: .
146
189
  max_complexity_allowed: 10
@@ -155,7 +198,7 @@ for func in result.functions:
155
198
  ```yaml
156
199
  repos:
157
200
  - repo: https://github.com/rohaquinlop/complexipy-pre-commit
158
- rev: v8.1.0
201
+ rev: v9.0.0
159
202
  hooks:
160
203
  - id: complexipy
161
204
  ```
@@ -163,22 +206,23 @@ repos:
163
206
  </details>
164
207
 
165
208
  <details>
166
- <summary><strong>🔌 VS Code Extension</strong></summary>
167
-
168
- Install from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rohaquinlop.complexipy) or [OpenVSX](https://open-vsx.org/extension/rohaquinlop/complexipy). It runs the complexipy language server, so install `complexipy` too (`uv tool install complexipy`). Inlay hints, hover, and warnings update as you type.
209
+ <summary><strong>🧩 Editors</strong></summary>
169
210
 
170
- </details>
171
-
172
- <details>
173
- <summary><strong>🧩 Editor Integration</strong></summary>
211
+ Every editor uses `complexipy lsp`, a language server with inlay hints, hover, and warnings that update as you type. Install `complexipy` first (`uv tool install complexipy`).
174
212
 
175
- Every editor uses `complexipy lsp`, a language server with inlay hints, hover, and warnings. See [Editor Integration](https://complexipy.com/editors/) for the VS Code, Neovim, and Zed setup.
213
+ - **VS Code**: install the extension from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rohaquinlop.complexipy) or [OpenVSX](https://open-vsx.org/extension/rohaquinlop/complexipy).
214
+ - **Neovim and Zed**: see [Editor Integration](https://complexipy.com/editors/).
176
215
 
177
216
  </details>
178
217
 
179
218
  ## Learn More
180
219
 
181
- - [Usage Guide](https://complexipy.com/usage-guide/) - every CLI flag, configuration files, snapshots, complexity diff, and inline ignores
220
+ - [Usage Guide](https://complexipy.com/usage-guide/) - installation, the basic CLI workflow, and troubleshooting
221
+ - [Adopting in an Existing Codebase](https://complexipy.com/adoption/) - baseline, gate new code, then lower the threshold
222
+ - [Configuration](https://complexipy.com/configuration/) - configuration files and the cache
223
+ - [Diff and Snapshots](https://complexipy.com/diff-and-snapshots/) - complexity diff and snapshot baselines
224
+ - [Ignores and Rule Selection](https://complexipy.com/ignores/) - inline ignores and rule selection
225
+ - [CLI Options](https://complexipy.com/cli-reference/) - every CLI flag
182
226
  - [Editor Integration](https://complexipy.com/editors/) - the language server, inlay hints, and the VS Code, Neovim, and Zed setup
183
227
  - [API Reference](https://complexipy.com/api-reference/) - the complete Python API
184
228
  - [Understanding Scores](https://complexipy.com/understanding-scores/) - how the scoring algorithm works
@@ -14,6 +14,7 @@
14
14
  <p>
15
15
  <a href="#installation">Installation</a> •
16
16
  <a href="#quick-start">Quick Start</a> •
17
+ <a href="#features">Features</a> •
17
18
  <a href="#integrations">Integrations</a> •
18
19
  <a href="#learn-more">Learn More</a> •
19
20
  <a href="https://complexipy.com/">Documentation</a> •
@@ -22,45 +23,66 @@
22
23
  </p>
23
24
  </div>
24
25
 
25
- ## What is Cognitive Complexity?
26
-
27
- > Cognitive complexity measures how hard code is to understand by humans, not machines.
28
-
29
- Unlike traditional metrics like cyclomatic complexity, cognitive complexity accounts for nesting depth and control flow patterns that affect human comprehension. Inspired by [G. Ann Campbell's research](https://www.sonarsource.com/resources/cognitive-complexity/) at SonarSource, complexipy provides a fast, accurate implementation for Python.
30
-
31
- **Key benefits:**
32
-
33
- - **Human-focused** - Penalizes nesting, flow breaks, and human-unfriendly logic
34
- - **Actionable insights** - Identifies genuinely hard-to-maintain code
35
- - **Different from cyclomatic** - Measures readability while cyclomatic measures structural, testing, and branch density
36
-
37
- ## Common Questions
38
-
39
- **[How is complexity calculated?](https://complexipy.com/understanding-scores/)**
40
- Learn about the scoring algorithm, what each control structure contributes, and how nesting affects the final score.
41
-
42
- **[How does this compare to Ruff's PLR0912?](https://complexipy.com/comparison-with-ruff/)**
43
- Understand the key differences between cyclomatic complexity (Ruff) and cognitive complexity (complexipy), and why you might want to use both.
26
+ <p align="center">
27
+ <picture>
28
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/competitors-dark.svg">
29
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/competitors-light.svg">
30
+ <img alt="Bar chart of the wall time to score cognitive complexity of the Django codebase with complexipy, flake8-cognitive-complexity, and pylint-cognitive-complexity" src="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/competitors-light.svg">
31
+ </picture>
32
+ </p>
44
33
 
45
- **[Is this a SonarSource/Sonar product?](https://complexipy.com/about/)**
46
- No. complexipy is an independent project inspired by G. Ann Campbell's research, but it's not affiliated with or endorsed by SonarSource.
34
+ <p align="center"><i>Scoring cognitive complexity of the Django codebase (2,929 files). <a href="https://complexipy.com/benchmarks/">Benchmarks</a></i></p>
47
35
 
48
36
  ## Installation
49
37
 
50
38
  ```bash
51
- pip install complexipy
39
+ uv tool install complexipy
52
40
  # or
53
41
  uv add complexipy
54
42
  # or
55
- uv tool install complexipy
43
+ pip install complexipy
56
44
  ```
57
45
 
58
46
  The `--diff`, `--diff-only`, and `--staged` options require Git 2.30 or newer
59
47
  on your `PATH`. Check your version with `git --version`. Git is not required
60
48
  for analysis without these options.
61
49
 
50
+ ## What is Cognitive Complexity?
51
+
52
+ > Cognitive complexity measures how hard a function's control flow is to follow. Use it to keep code easy to review and change, whether a person or an AI agent wrote it.
53
+
54
+ These two functions have the same cyclomatic complexity, 4. Their cognitive complexity is different:
55
+
56
+ ```python
57
+ # Cognitive complexity: 3
58
+ def example1(a, b, c):
59
+ if a: # +1
60
+ return 1
61
+ if b: # +1
62
+ return 2
63
+ if c: # +1
64
+ return 3
65
+ return 4
66
+ ```
67
+
68
+ ```python
69
+ # Cognitive complexity: 6
70
+ def example2(a, b, c):
71
+ if a: # +1
72
+ if b: # +2 (1 + nesting_level)
73
+ if c: # +3 (1 + nesting_level)
74
+ return 1
75
+ return 4
76
+ ```
77
+
78
+ Nested code makes the reader hold more context, so each nesting level adds to the score. complexipy implements the [Cognitive Complexity](https://www.sonarsource.com/resources/cognitive-complexity/) metric by G. Ann Campbell for Python. [How scores are calculated](https://complexipy.com/understanding-scores/)
79
+
62
80
  ## Quick Start
63
81
 
82
+ <p align="center">
83
+ <img src="https://raw.githubusercontent.com/rohaquinlop/complexipy/refs/heads/main/docs/img/demo.gif" alt="complexipy scores each function in checkout.py, fails apply_discount at 14 against a limit of 10, and suggests extracting a helper function">
84
+ </p>
85
+
64
86
  ### Command Line
65
87
 
66
88
  ```bash
@@ -89,20 +111,41 @@ complexipy . --exclude "tests/**"
89
111
  from complexipy import file_complexity
90
112
 
91
113
  # Analyze a file
92
- result = file_complexity("app.py", check_script=True)
114
+ result = file_complexity("app.py")
93
115
  print(f"File complexity: {result.complexity}")
94
116
 
95
117
  for func in result.functions:
96
118
  print(f"{func.name}: {func.complexity}")
97
119
  ```
98
120
 
121
+ ## Features
122
+
123
+ - **Cognitive complexity scores** that follow G. Ann Campbell's paper. [How scores work](https://complexipy.com/understanding-scores/)
124
+ - **Gate only what a change makes worse**: `--diff` and `--staged` compare each function with a git reference. [Complexity diff](https://complexipy.com/diff-and-snapshots/#complexity-diff)
125
+ - **Snapshot baselines**: record the current state of an existing codebase, then fail only on new or worse functions. [Snapshots](https://complexipy.com/diff-and-snapshots/#snapshot-baselines)
126
+ - **Refactor suggestions and `--fix`**: rules such as guard clauses and extract helper, and automatic fixes where they are safe. [Refactoring rules](https://complexipy.com/refactoring-rules/)
127
+ - **Output formats**: JSON, CSV, SARIF for GitHub code scanning, and GitLab Code Quality. [Output formats](https://complexipy.com/usage-guide/#output-formats)
128
+ - **Language server**: inlay hints, hover, and warnings in VS Code, Neovim, and Zed. [Editor integration](https://complexipy.com/editors/)
129
+ - **GitHub Action and pre-commit hook** for CI. [Integrations](#integrations)
130
+
131
+ ## Common Questions
132
+
133
+ **[How is complexity calculated?](https://complexipy.com/understanding-scores/)**
134
+ Learn about the scoring algorithm, what each control structure contributes, and how nesting affects the final score.
135
+
136
+ **[How does this compare to Ruff's PLR0912?](https://complexipy.com/comparison-with-ruff/)**
137
+ Understand the key differences between cyclomatic complexity (Ruff) and cognitive complexity (complexipy), and why you might want to use both.
138
+
139
+ **[Is this a SonarSource/Sonar product?](https://complexipy.com/about/)**
140
+ No. complexipy is an independent project inspired by G. Ann Campbell's research, but it's not affiliated with or endorsed by SonarSource.
141
+
99
142
  ## Integrations
100
143
 
101
144
  <details>
102
145
  <summary><strong>🔧 GitHub Actions</strong></summary>
103
146
 
104
147
  ```yaml
105
- - uses: rohaquinlop/complexipy-action@v8
148
+ - uses: rohaquinlop/complexipy-action@v9
106
149
  with:
107
150
  paths: .
108
151
  max_complexity_allowed: 10
@@ -117,7 +160,7 @@ for func in result.functions:
117
160
  ```yaml
118
161
  repos:
119
162
  - repo: https://github.com/rohaquinlop/complexipy-pre-commit
120
- rev: v8.1.0
163
+ rev: v9.0.0
121
164
  hooks:
122
165
  - id: complexipy
123
166
  ```
@@ -125,22 +168,23 @@ repos:
125
168
  </details>
126
169
 
127
170
  <details>
128
- <summary><strong>🔌 VS Code Extension</strong></summary>
129
-
130
- Install from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rohaquinlop.complexipy) or [OpenVSX](https://open-vsx.org/extension/rohaquinlop/complexipy). It runs the complexipy language server, so install `complexipy` too (`uv tool install complexipy`). Inlay hints, hover, and warnings update as you type.
171
+ <summary><strong>🧩 Editors</strong></summary>
131
172
 
132
- </details>
133
-
134
- <details>
135
- <summary><strong>🧩 Editor Integration</strong></summary>
173
+ Every editor uses `complexipy lsp`, a language server with inlay hints, hover, and warnings that update as you type. Install `complexipy` first (`uv tool install complexipy`).
136
174
 
137
- Every editor uses `complexipy lsp`, a language server with inlay hints, hover, and warnings. See [Editor Integration](https://complexipy.com/editors/) for the VS Code, Neovim, and Zed setup.
175
+ - **VS Code**: install the extension from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rohaquinlop.complexipy) or [OpenVSX](https://open-vsx.org/extension/rohaquinlop/complexipy).
176
+ - **Neovim and Zed**: see [Editor Integration](https://complexipy.com/editors/).
138
177
 
139
178
  </details>
140
179
 
141
180
  ## Learn More
142
181
 
143
- - [Usage Guide](https://complexipy.com/usage-guide/) - every CLI flag, configuration files, snapshots, complexity diff, and inline ignores
182
+ - [Usage Guide](https://complexipy.com/usage-guide/) - installation, the basic CLI workflow, and troubleshooting
183
+ - [Adopting in an Existing Codebase](https://complexipy.com/adoption/) - baseline, gate new code, then lower the threshold
184
+ - [Configuration](https://complexipy.com/configuration/) - configuration files and the cache
185
+ - [Diff and Snapshots](https://complexipy.com/diff-and-snapshots/) - complexity diff and snapshot baselines
186
+ - [Ignores and Rule Selection](https://complexipy.com/ignores/) - inline ignores and rule selection
187
+ - [CLI Options](https://complexipy.com/cli-reference/) - every CLI flag
144
188
  - [Editor Integration](https://complexipy.com/editors/) - the language server, inlay hints, and the VS Code, Neovim, and Zed setup
145
189
  - [API Reference](https://complexipy.com/api-reference/) - the complete Python API
146
190
  - [Understanding Scores](https://complexipy.com/understanding-scores/) - how the scoring algorithm works
@@ -13,6 +13,7 @@ import complexipy._complexipy as _complexipy
13
13
  from complexipy._complexipy import (
14
14
  Applicability,
15
15
  CodeComplexity,
16
+ CodeInsertion,
16
17
  CodeSuggestion,
17
18
  DiffEntry,
18
19
  DiffStatus,
@@ -33,6 +34,7 @@ from complexipy._complexipy import (
33
34
  __all__ = [
34
35
  "Applicability",
35
36
  "CodeComplexity",
37
+ "CodeInsertion",
36
38
  "CodeSuggestion",
37
39
  "DiffEntry",
38
40
  "DiffStatus",
@@ -76,6 +76,15 @@ class DiffEntry:
76
76
  """Comparison status derived from old and new complexity."""
77
77
  ...
78
78
 
79
+ class CodeInsertion:
80
+ """Text a suggestion inserts outside the plan's own line range."""
81
+
82
+ before_line: int
83
+ """The 1-based line of the original source the text goes in front of."""
84
+
85
+ text: str
86
+ """The inserted text, ending with a line break."""
87
+
79
88
  class CodeSuggestion:
80
89
  """A concrete code suggestion with replacement text and applicability."""
81
90
 
@@ -91,6 +100,9 @@ class CodeSuggestion:
91
100
  spliceable: bool
92
101
  """Whether the replacement is a faithful source splice that can be measured."""
93
102
 
103
+ insertions: List[CodeInsertion]
104
+ """Text to insert before other lines of the source when the suggestion is applied."""
105
+
94
106
  class LineComplexity:
95
107
  """
96
108
  Represents the cognitive complexity contribution of a single line of code.
@@ -40,5 +40,5 @@ complexipy-core = { path = "../complexipy-core", features = ["config", "schema"]
40
40
  schemars = { workspace = true }
41
41
  jsonschema = { workspace = true }
42
42
 
43
- [target.'cfg(any(target_os = "macos", target_os = "windows", all(target_os = "linux", target_arch = "x86_64")))'.dependencies]
43
+ [target.'cfg(any(target_os = "macos", target_os = "windows", all(target_os = "linux", target_arch = "x86_64"), all(target_os = "linux", target_arch = "aarch64", target_env = "musl")))'.dependencies]
44
44
  mimalloc = "0.1.49"
@@ -82,11 +82,17 @@ pub struct CliArgs {
82
82
  #[arg(long, num_args = 0..=1, default_missing_value = "true", require_equals = true)]
83
83
  pub report_ignored: Option<bool>,
84
84
 
85
+ #[arg(long, num_args = 0..=1, default_missing_value = "true", require_equals = true)]
86
+ pub force_exclude: Option<bool>,
87
+
85
88
  #[arg(long, conflicts_with = "config", num_args = 0..=1, default_missing_value = "true", require_equals = true)]
86
89
  pub isolated: Option<bool>,
87
90
 
88
91
  #[arg(long, value_name = "PATH")]
89
92
  pub config: Option<String>,
93
+
94
+ #[arg(long, value_name = "RULE")]
95
+ pub explain: Option<String>,
90
96
  }
91
97
 
92
98
  #[cfg(test)]
@@ -8,7 +8,8 @@ use complexipy_cli::run::run_at;
8
8
  #[cfg(any(
9
9
  target_os = "macos",
10
10
  target_os = "windows",
11
- all(target_os = "linux", target_arch = "x86_64")
11
+ all(target_os = "linux", target_arch = "x86_64"),
12
+ all(target_os = "linux", target_arch = "aarch64", target_env = "musl")
12
13
  ))]
13
14
  #[global_allocator]
14
15
  static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
@@ -1,4 +1,4 @@
1
- use crate::output::diff::format_diff;
1
+ use crate::output::diff::{format_diff, format_ignored_by_change};
2
2
  use complexipy_core::diff::{DiffEntry, Verdict};
3
3
 
4
4
  fn strip_ansi(input: &str) -> String {
@@ -157,3 +157,23 @@ fn a_diff_only_table_has_no_gate() {
157
157
  assert!(!output.contains("Gate"));
158
158
  assert!(!output.contains("FAILS"));
159
159
  }
160
+
161
+ #[test]
162
+ fn ignored_by_change_lists_each_function_with_its_location_and_score() {
163
+ use complexipy_core::diff::IgnoredByChange;
164
+ let function = |func_name: &str, line_start, complexity| IgnoredByChange {
165
+ file_path: "pkg/m.py".to_string(),
166
+ func_name: func_name.to_string(),
167
+ line_start,
168
+ complexity,
169
+ };
170
+
171
+ assert_eq!(format_ignored_by_change(&[], "main"), "");
172
+ assert_eq!(
173
+ format_ignored_by_change(
174
+ &[function("nested", 1, 6), function("bad\u{1b}", 9, 1)],
175
+ "main"
176
+ ),
177
+ "Hidden by an ignore comment now and not at main (the gate does not count these):\n pkg/m.py:1 nested 6\n pkg/m.py:9 bad\\u{1b} 1"
178
+ );
179
+ }
@@ -2,7 +2,7 @@ use comfy_table::{Cell, Table};
2
2
  use owo_colors::{OwoColorize, Stream, Style};
3
3
 
4
4
  use crate::output::render::rule;
5
- use complexipy_core::diff::{DiffEntry, DiffStatus, Verdict};
5
+ use complexipy_core::diff::{DiffEntry, DiffStatus, IgnoredByChange, Verdict};
6
6
  use complexipy_core::sanitize::escape_controls;
7
7
 
8
8
  /// The table of changed entries. With `verdicts`, a Gate column marks the
@@ -62,6 +62,29 @@ pub fn format_diff(entries: &[DiffEntry], git_ref: &str, verdicts: Option<&[Verd
62
62
  )
63
63
  }
64
64
 
65
+ /// The functions an ignore marker hides now and did not hide at `git_ref`,
66
+ /// each with its score with the marker disregarded. Empty when there are
67
+ /// none. It informs a reviewer and never decides the exit code.
68
+ pub fn format_ignored_by_change(ignored: &[IgnoredByChange], git_ref: &str) -> String {
69
+ if ignored.is_empty() {
70
+ return String::new();
71
+ }
72
+ let mut lines = vec![format!(
73
+ "Hidden by an ignore comment now and not at {} (the gate does not count these):",
74
+ escape_controls(git_ref)
75
+ )];
76
+ lines.extend(ignored.iter().map(|function| {
77
+ format!(
78
+ " {}:{} {} {}",
79
+ escape_controls(&function.file_path),
80
+ function.line_start,
81
+ escape_controls(&function.func_name),
82
+ function.complexity
83
+ )
84
+ }));
85
+ lines.join("\n")
86
+ }
87
+
65
88
  fn gate_summary(verdicts: &[Verdict]) -> String {
66
89
  let failures = verdicts
67
90
  .iter()
@@ -1,3 +1,4 @@
1
+ use complexipy_core::CodeInsertion;
1
2
  use complexipy_core::fix::{AppliedFix, FixReport, LineMap, SkipReason, SkippedFix};
2
3
 
3
4
  use super::{format_fix_diff, format_fix_summary, no_fixes_output, pass_label};
@@ -15,6 +16,7 @@ fn applied_fix(line_start: u64, line_end: u64, replacement: &str) -> AppliedFix
15
16
  line_start,
16
17
  line_end,
17
18
  replacement: replacement.to_string(),
19
+ insertions: Vec::new(),
18
20
  reduction: 2,
19
21
  reduction_is_measured: true,
20
22
  }
@@ -196,3 +198,38 @@ fn diff_escapes_terminal_controls_from_the_source_with_and_without_color() {
196
198
  assert!(!rendered.contains("\u{1b}[2J"), "colored = {colored}");
197
199
  }
198
200
  }
201
+
202
+ #[test]
203
+ fn diff_renders_an_insertion_as_its_own_hunk() {
204
+ let source = "def f(a, b):\n if a and b or a:\n return 1\n";
205
+ let mut fix = applied_fix(2, 2, " if _check(a, b):");
206
+ fix.insertions = vec![CodeInsertion {
207
+ before_line: 1,
208
+ text: "def _check(a, b):\n return a and b or a\n\n\n".to_string(),
209
+ }];
210
+ let report = FixReport {
211
+ patched: "def _check(a, b):\n return a and b or a\n\n\ndef f(a, b):\n if _check(a, b):\n return 1\n".to_string(),
212
+ applied: vec![fix],
213
+ skipped: vec![],
214
+ };
215
+
216
+ let rendered = format_fix_diff("a.py", source, &report, false);
217
+
218
+ assert_eq!(
219
+ rendered,
220
+ concat!(
221
+ "--- a/a.py\n",
222
+ "+++ b/a.py\n",
223
+ "@@ -1,1 +1,5 @@ C007 Merge nested if statements\n",
224
+ " 1 +def _check(a, b):\n",
225
+ " 2 + return a and b or a\n",
226
+ " 3 +\n",
227
+ " 4 +\n",
228
+ "1 5 def f(a, b):\n",
229
+ "@@ -2,2 +6,2 @@ C007 Merge nested if statements\n",
230
+ "2 - if a and b or a:\n",
231
+ " 6 + if _check(a, b):\n",
232
+ "3 7 return 1",
233
+ )
234
+ );
235
+ }