integrated-application-development / integrated-application-development/sonar-delphi
New rule: Unreachable code should be removed
- 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
Unreachable code should be removed
### Rule description
This rule would pick up simple statically verifiable cases of unreachable code, by raising an issue when encountering a statement immediately after the following (i.e. in the same block):
- `Exit`
- `Break`
- `Continue`
- `raise`
- `goto`
As a gotcha, the rule must not raise an issue if the "dead" statement is a goto label, or contains a goto label nested inside it.
### Rationale
Accidental unreachable code is a common problem when writing or refactoring code, and is at best messy and at worst an avenue for bugs and unexpected behaviour. Delphi also has no built in functionality to detect unreachable code, so this would fill a useful niche.
Contributor guide
Assessment
This issue has not been assessed yet.