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

New rule: Identifiers should not shadow keywords

Open
#72 1 comment 1 reaction 0 assignees View on GitHub
feature good first issue 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

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.

```delphi
type
stdcall = string;

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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.