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

New rule: `var` arguments should be initialized before the call

Open
#132 1 comment 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

VarArgumentsShouldBeInitialized

### Rule description

In #127, there was a discussion on whether `var` argument should be considered as initializing a variable. Although `out` arguments should be preferred for that, a confusion in the Delphi compiler (`out` and `var` are processed similarly) has lead some teams to accept initialization through `var`. So, this was suggested as a new rule rather than an improvement or the rule that "variables should be initialized before being used".

This rule states that a variable is "used" when passed as a `var` argument to a function call, so doing so without the variable being initialized should be warned against.

### Rationale

If you do not accept in your code base that initialization could be done via a `var` argument, then the rationale is the same as stating that a variable should be initialized before being used.

It is especially important for record variables, for which the Delphi compiler does not enforce this basic rule!

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.