Skip to content

Potential fix for code scanning alert no. 32: Complex condition#6

Merged
DoubledDoge merged 3 commits into
mainfrom
alert-autofix-32
Mar 8, 2026
Merged

Potential fix for code scanning alert no. 32: Complex condition#6
DoubledDoge merged 3 commits into
mainfrom
alert-autofix-32

Conversation

@DoubledDoge
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/DoubledDoge/typeguard/security/code-scanning/32

In general, to fix complex conditions you extract parts of the logic into well-named boolean variables or helper methods, then combine those with a simpler expression. This preserves behavior while making the intent clearer and reducing the cognitive load when reading or modifying the code.

For this specific case in src/TypeGuard.Core/Rules/IpAddressRules.cs, the best approach is to factor each private range check into its own local boolean variable inside IsValid, then return the disjunction (||) of those variables. For example, create bool is10Range, bool is172Range, bool is192Range, and bool isApipaRange, assigning them the same conditions currently embedded in the single return statement. Then change the return to return is10Range || is172Range || is192Range || isApipaRange;. This keeps all logic within the same method, avoids changing signatures or adding public helpers, and does not alter functionality. No new imports are required, and all changes are confined to the body of PrivateIpRule.IsValid (lines 37–51).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

DoubledDoge and others added 3 commits March 8, 2026 21:53
Complex return condition simplified through variable assignment

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@DoubledDoge DoubledDoge marked this pull request as ready for review March 8, 2026 20:32
@DoubledDoge DoubledDoge merged commit 19d3fdc into main Mar 8, 2026
7 checks passed
@DoubledDoge DoubledDoge deleted the alert-autofix-32 branch March 8, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant