integrated-application-development / integrated-application-development/sonar-delphi

New rule: If expressions should not be too complex

Open
#456 0 comments 0 reactions 0 assignees View on GitHub
feature rule
Dominant language
Java
Stars
159
Forks
31
Avg merge
5d 4h
Merged PRs (30d)
4

Description

### Prerequisites

- [x] This rule has not already been suggested.
- [x] This should be a new rule, not an improvement to an existing rule.
- [x] This rule would be generally useful, not specific to my code or setup.

### Suggested rule title

If expressions should not be too complex

### Rule description

Similar to the existing `RoutineNestingDepth` and `TooManyNestedRoutines` rules, this rule would catch `if` expressions that are unclear due to their size. This could be measured in a few ways, e.g.:

- Sum length of the guard, then, or else expressions
- Number of lines the entire expression covers
- Number of nested `if` expressions
- Whether anonymous methods are present
- etc.

### Rationale

Keeping ternary use limited makes code more readable and less prone to errors.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing RoutineNestingDepth and TooManyNestedRoutines rules to understand how similar complexity checks are defined. Decide which measure or combination best identifies overly complex if expressions, then define the rule's scope and acceptance criteria so it is generally useful and distinguishable from existing rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.