Skip to content

New rule: Unreachable code should be removed #177

Open
@fourls

Description

@fourls

Prerequisites

  • This rule has not already been suggested.
  • This should be a new rule, not an improvement to an existing rule.
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestruleImprovements or additions to rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions