make two files worse - #100
Conversation
49735fb to
fc6ded2
Compare
fc6ded2 to
c9f9db9
Compare
|
/cs-agent skill:fix-code-health-degradations |
|
4a289f4 to
c9f9db9
Compare
f40ae4f to
49cea05
Compare
There was a problem hiding this comment.
Gates Failed
Enforce critical code health rules
(1 file with Bumpy Road Ahead, Deep, Nested Complexity)
Enforce advisory code health rules
(2 files with Complex Method, Complex Conditional, Lines of Code in a Single File, Code Duplication, Overall Code Complexity)
Fix Code Health degradations ℹ️
Gates Passed
4 Quality Gates Passed
Reason for failure
| Enforce critical code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| csharp-example.cs | 2 critical rules | 10.00 → 7.57 | Suppress |
| Enforce advisory code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| csharp-example.cs | 2 advisory rules | 10.00 → 7.57 | Suppress |
| python-example.py | 4 advisory rules | 5.06 → 3.89 | Suppress |
Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
| static int CalculateExecutionScore(string[] args, int seed, bool dryRun) | ||
| { | ||
| int score = seed; | ||
| int retries = 0; | ||
| bool force = false; | ||
| bool resetRequested = false; | ||
| bool hasCritical = false; | ||
| string mode = "normal"; | ||
|
|
||
| if (args == null) | ||
| { | ||
| return -1; | ||
| } | ||
|
|
||
| if (args.Length == 0) | ||
| { | ||
| score -= 10; | ||
| } | ||
|
|
||
| for (int i = 0; i < args.Length; i++) | ||
| { | ||
| string token = args[i]; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(token)) | ||
| { | ||
| score -= 2; | ||
| continue; | ||
| } | ||
|
|
||
| if (token.StartsWith("--")) | ||
| { | ||
| if (token == "--force") | ||
| { | ||
| force = true; | ||
| score += 7; | ||
| } | ||
| else if (token == "--reset") | ||
| { | ||
| resetRequested = true; | ||
| score = 5; | ||
| } | ||
| else if (token == "--boost") | ||
| { | ||
| score += 15; | ||
| } | ||
| else if (token == "--halve") | ||
| { | ||
| score /= 2; | ||
| } | ||
| else if (token == "--invert") | ||
| { | ||
| score = -score; | ||
| } | ||
| else | ||
| { | ||
| score -= 1; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| int parsed; | ||
| if (int.TryParse(token, out parsed)) | ||
| { | ||
| if (parsed > 100) | ||
| { | ||
| score += 20; | ||
| hasCritical = true; | ||
| } | ||
| else if (parsed < 0) | ||
| { | ||
| score -= 5; | ||
| } | ||
| else | ||
| { | ||
| score += parsed; | ||
| } | ||
| } | ||
| else if (token.Contains(":")) | ||
| { | ||
| string[] pair = token.Split(':'); | ||
| if (pair.Length > 1) | ||
| { | ||
| mode = pair[0]; | ||
| score += pair[1].Length; | ||
| } | ||
| else | ||
| { | ||
| score -= 3; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| score += token.Length % 3; | ||
| } | ||
| } | ||
|
|
||
| if (mode == "strict") | ||
| { | ||
| score -= 2; | ||
| } | ||
| else if (mode == "relaxed") | ||
| { | ||
| score += 2; | ||
| } | ||
| else if (mode == "legacy") | ||
| { | ||
| score -= 1; | ||
| } | ||
| } | ||
|
|
||
| while (retries < 3 && score < 150) | ||
| { | ||
| if (score % 2 == 0) | ||
| { | ||
| score += retries + 4; | ||
| } | ||
| else | ||
| { | ||
| score -= retries + 1; | ||
| } | ||
|
|
||
| if (dryRun && retries == 1) | ||
| { | ||
| score -= 6; | ||
| } | ||
|
|
||
| if (score > 120 || retries == 2) | ||
| { | ||
| hasCritical = true; | ||
| } | ||
|
|
||
| if (score < 20) | ||
| { | ||
| score += 11; | ||
| } | ||
|
|
||
| retries++; | ||
| } | ||
|
|
||
| if (force && !dryRun && score > 0) | ||
| { | ||
| score += 30; | ||
| } | ||
|
|
||
| if (resetRequested && score > 10) | ||
| { | ||
| score = 10; | ||
| } | ||
|
|
||
| if (score % 5 == 0) | ||
| { | ||
| score += 1; | ||
| } | ||
|
|
||
| if (hasCritical && (score < 50 || score > 140)) | ||
| { | ||
| score += 9; | ||
| } | ||
|
|
||
| if (mode == "strict") | ||
| { | ||
| if (score < 60) | ||
| { | ||
| score = 60; | ||
| } | ||
| } | ||
| else if (mode == "relaxed") | ||
| { | ||
| if (score < 20) | ||
| { | ||
| score = 20; | ||
| } | ||
| } | ||
| else if (mode == "legacy" && score < 40) | ||
| { | ||
| score = 40; | ||
| } | ||
|
|
||
| return score; |
There was a problem hiding this comment.
❌ New issue: Complex Method
CalculateExecutionScore has a cyclomatic complexity of 43, threshold = 9
| if (force && !dryRun && score > 0) | ||
| { | ||
| score += 30; | ||
| } | ||
|
|
||
| if (resetRequested && score > 10) | ||
| { | ||
| score = 10; | ||
| } | ||
|
|
||
| if (score % 5 == 0) | ||
| { | ||
| score += 1; | ||
| } | ||
|
|
||
| if (hasCritical && (score < 50 || score > 140)) |
There was a problem hiding this comment.
❌ New issue: Complex Conditional
CalculateExecutionScore has 2 complex conditionals with 4 branches, threshold = 2
| static int CalculateExecutionScore(string[] args, int seed, bool dryRun) | ||
| { | ||
| int score = seed; | ||
| int retries = 0; | ||
| bool force = false; | ||
| bool resetRequested = false; | ||
| bool hasCritical = false; | ||
| string mode = "normal"; | ||
|
|
||
| if (args == null) | ||
| { | ||
| return -1; | ||
| } | ||
|
|
||
| if (args.Length == 0) | ||
| { | ||
| score -= 10; | ||
| } | ||
|
|
||
| for (int i = 0; i < args.Length; i++) | ||
| { | ||
| string token = args[i]; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(token)) | ||
| { | ||
| score -= 2; | ||
| continue; | ||
| } | ||
|
|
||
| if (token.StartsWith("--")) | ||
| { | ||
| if (token == "--force") | ||
| { | ||
| force = true; | ||
| score += 7; | ||
| } | ||
| else if (token == "--reset") | ||
| { | ||
| resetRequested = true; | ||
| score = 5; | ||
| } | ||
| else if (token == "--boost") | ||
| { | ||
| score += 15; | ||
| } | ||
| else if (token == "--halve") | ||
| { | ||
| score /= 2; | ||
| } | ||
| else if (token == "--invert") | ||
| { | ||
| score = -score; | ||
| } | ||
| else | ||
| { | ||
| score -= 1; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| int parsed; | ||
| if (int.TryParse(token, out parsed)) | ||
| { | ||
| if (parsed > 100) | ||
| { | ||
| score += 20; | ||
| hasCritical = true; | ||
| } | ||
| else if (parsed < 0) | ||
| { | ||
| score -= 5; | ||
| } | ||
| else | ||
| { | ||
| score += parsed; | ||
| } | ||
| } | ||
| else if (token.Contains(":")) | ||
| { | ||
| string[] pair = token.Split(':'); | ||
| if (pair.Length > 1) | ||
| { | ||
| mode = pair[0]; | ||
| score += pair[1].Length; | ||
| } | ||
| else | ||
| { | ||
| score -= 3; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| score += token.Length % 3; | ||
| } | ||
| } | ||
|
|
||
| if (mode == "strict") | ||
| { | ||
| score -= 2; | ||
| } | ||
| else if (mode == "relaxed") | ||
| { | ||
| score += 2; | ||
| } | ||
| else if (mode == "legacy") | ||
| { | ||
| score -= 1; | ||
| } | ||
| } | ||
|
|
||
| while (retries < 3 && score < 150) | ||
| { | ||
| if (score % 2 == 0) | ||
| { | ||
| score += retries + 4; | ||
| } | ||
| else | ||
| { | ||
| score -= retries + 1; | ||
| } | ||
|
|
||
| if (dryRun && retries == 1) | ||
| { | ||
| score -= 6; | ||
| } | ||
|
|
||
| if (score > 120 || retries == 2) | ||
| { | ||
| hasCritical = true; | ||
| } | ||
|
|
||
| if (score < 20) | ||
| { | ||
| score += 11; | ||
| } | ||
|
|
||
| retries++; | ||
| } | ||
|
|
||
| if (force && !dryRun && score > 0) | ||
| { | ||
| score += 30; | ||
| } | ||
|
|
||
| if (resetRequested && score > 10) | ||
| { | ||
| score = 10; | ||
| } | ||
|
|
||
| if (score % 5 == 0) | ||
| { | ||
| score += 1; | ||
| } | ||
|
|
||
| if (hasCritical && (score < 50 || score > 140)) | ||
| { | ||
| score += 9; | ||
| } | ||
|
|
||
| if (mode == "strict") | ||
| { | ||
| if (score < 60) | ||
| { | ||
| score = 60; | ||
| } | ||
| } | ||
| else if (mode == "relaxed") | ||
| { | ||
| if (score < 20) | ||
| { | ||
| score = 20; | ||
| } | ||
| } | ||
| else if (mode == "legacy" && score < 40) | ||
| { | ||
| score = 40; | ||
| } | ||
|
|
||
| return score; |
There was a problem hiding this comment.
❌ New issue: Bumpy Road Ahead
CalculateExecutionScore has 7 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is 3 blocks per function
| static int CalculateExecutionScore(string[] args, int seed, bool dryRun) | ||
| { | ||
| int score = seed; | ||
| int retries = 0; | ||
| bool force = false; | ||
| bool resetRequested = false; | ||
| bool hasCritical = false; | ||
| string mode = "normal"; | ||
|
|
||
| if (args == null) | ||
| { | ||
| return -1; | ||
| } | ||
|
|
||
| if (args.Length == 0) | ||
| { | ||
| score -= 10; | ||
| } | ||
|
|
||
| for (int i = 0; i < args.Length; i++) | ||
| { | ||
| string token = args[i]; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(token)) | ||
| { | ||
| score -= 2; | ||
| continue; | ||
| } | ||
|
|
||
| if (token.StartsWith("--")) | ||
| { | ||
| if (token == "--force") | ||
| { | ||
| force = true; | ||
| score += 7; | ||
| } | ||
| else if (token == "--reset") | ||
| { | ||
| resetRequested = true; | ||
| score = 5; | ||
| } | ||
| else if (token == "--boost") | ||
| { | ||
| score += 15; | ||
| } | ||
| else if (token == "--halve") | ||
| { | ||
| score /= 2; | ||
| } | ||
| else if (token == "--invert") | ||
| { | ||
| score = -score; | ||
| } | ||
| else | ||
| { | ||
| score -= 1; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| int parsed; | ||
| if (int.TryParse(token, out parsed)) | ||
| { | ||
| if (parsed > 100) | ||
| { | ||
| score += 20; | ||
| hasCritical = true; | ||
| } | ||
| else if (parsed < 0) | ||
| { | ||
| score -= 5; | ||
| } | ||
| else | ||
| { | ||
| score += parsed; | ||
| } | ||
| } | ||
| else if (token.Contains(":")) | ||
| { | ||
| string[] pair = token.Split(':'); | ||
| if (pair.Length > 1) | ||
| { | ||
| mode = pair[0]; | ||
| score += pair[1].Length; | ||
| } | ||
| else | ||
| { | ||
| score -= 3; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| score += token.Length % 3; | ||
| } | ||
| } | ||
|
|
||
| if (mode == "strict") | ||
| { | ||
| score -= 2; | ||
| } | ||
| else if (mode == "relaxed") | ||
| { | ||
| score += 2; | ||
| } | ||
| else if (mode == "legacy") | ||
| { | ||
| score -= 1; | ||
| } | ||
| } | ||
|
|
||
| while (retries < 3 && score < 150) | ||
| { | ||
| if (score % 2 == 0) | ||
| { | ||
| score += retries + 4; | ||
| } | ||
| else | ||
| { | ||
| score -= retries + 1; | ||
| } | ||
|
|
||
| if (dryRun && retries == 1) | ||
| { | ||
| score -= 6; | ||
| } | ||
|
|
||
| if (score > 120 || retries == 2) | ||
| { | ||
| hasCritical = true; | ||
| } | ||
|
|
||
| if (score < 20) | ||
| { | ||
| score += 11; | ||
| } | ||
|
|
||
| retries++; | ||
| } | ||
|
|
||
| if (force && !dryRun && score > 0) | ||
| { | ||
| score += 30; | ||
| } | ||
|
|
||
| if (resetRequested && score > 10) | ||
| { | ||
| score = 10; | ||
| } | ||
|
|
||
| if (score % 5 == 0) | ||
| { | ||
| score += 1; | ||
| } | ||
|
|
||
| if (hasCritical && (score < 50 || score > 140)) | ||
| { | ||
| score += 9; | ||
| } | ||
|
|
||
| if (mode == "strict") | ||
| { | ||
| if (score < 60) | ||
| { | ||
| score = 60; | ||
| } | ||
| } | ||
| else if (mode == "relaxed") | ||
| { | ||
| if (score < 20) | ||
| { | ||
| score = 20; | ||
| } | ||
| } | ||
| else if (mode == "legacy" && score < 40) | ||
| { | ||
| score = 40; | ||
| } | ||
|
|
||
| return score; |
There was a problem hiding this comment.
❌ New issue: Deep, Nested Complexity
CalculateExecutionScore has a nested complexity depth of 4, threshold = 4
| return res | ||
|
|
||
|
|
||
| def create_transaction_from_cart_for_checkout(cart: Cart) -> DbTransaction: |
There was a problem hiding this comment.
❌ New issue: Lines of Code in a Single File
This module has 621 lines of code, improve code health by reducing it to 600
| def create_transaction_from_cart_for_checkout(cart: Cart) -> DbTransaction: | ||
| """Create a transaction based on cart information""" | ||
| res = DbTransaction(type=TransactionType.PURCHASE, currency=cart.currency, timestamp=now(), | ||
| total_amount=cart.total_amount, state=TransactionState.INITIALIZED, id=ObjectId()) | ||
| items = [] | ||
| vat: Dict[Decimal, Vat] = {} | ||
| for item in cart.items: | ||
| ps = item.product_set.fetch() | ||
| t_item = TransactionItem(amount=item.amount, count=item.count, | ||
| product_set_id=ps.full_id, product_set_title=item.product_set_title) | ||
| if item.manual_activation is not None: | ||
| t_item.manual_activation = item.manual_activation | ||
| if item.mtb_product_owner is not None: | ||
| t_item.mtb_product_owner = item.mtb_product_owner | ||
| if item.mtb_bearer is not None: | ||
| t_item.mtb_bearer = item.mtb_bearer | ||
| if item.start_of_validity is not None: | ||
| t_item.start_of_validity = item.start_of_validity | ||
| items.append(t_item) | ||
| for percentage, amount in ps.vat().items(): | ||
| amount *= item.count | ||
| if percentage in vat: | ||
| vat[percentage].amount += amount | ||
| else: | ||
| vat[percentage] = Vat(amount=amount, percentage=percentage) | ||
| res.items = items | ||
| res.vat = list(vat.values()) | ||
| res.discount_codes = list(cart.discount_codes) | ||
| res.description = cart.name | ||
| return res |
There was a problem hiding this comment.
❌ New issue: Code Duplication
The module contains 3 functions with similar structure: create_transaction_from_cart,create_transaction_from_cart_for_checkout,create_transaction_from_cart_for_saved_cart
| if ((purchase.manual_activation and purchase.start_of_validity is None and mtb_bearer is None) | ||
| or (purchase.start_of_validity and not purchase.manual_activation and mtb_product_owner is None) | ||
| or (purchase.mtb_product_owner and mtb_bearer is not None and mtb_product_owner is not None | ||
| and mtb_bearer.owner.id == mtb_product_owner.id)): |
There was a problem hiding this comment.
❌ New issue: Complex Conditional
initialize_purchase_transaction has 1 complex conditionals with 9 branches, threshold = 2
| return res | ||
|
|
||
|
|
||
| def create_transaction_from_cart_for_checkout(cart: Cart) -> DbTransaction: |
There was a problem hiding this comment.
❌ New issue: Overall Code Complexity
This module has a mean cyclomatic complexity of 8.21 across 28 functions. The mean complexity threshold is 8
No description provided.