Skip to content

New rule: Identifiers should not shadow keywords #72

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

Identifiers should not shadow keywords

Rule description

This rule identifies identifiers that share a name with a keyword.

This would include a configurable whitelist for acceptable keywords to shadow, such as message or index.

Rationale

It can be easy to accidentally share the name of a variable with a keyword, as many of Delphi's keywords are context-dependent. This can be very confusing, particularly when used in a similar place to where the keyword is seen. In certain circumstances, the compiler can interpret attempted usages of your identifier as a keyword, making certain constructions impossible for identifiers that shadow a keyword.

type
  stdcall = string;

  override = class
    public function public: stdcall overload stdcall;
  end;

In the Delphi IDE, these are all highlighted as keywords.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestgood first issueGood for newcomersruleImprovements or additions to rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions