[C#] Label one char variables as code smell

Why: Variables with a one char name (“i”) are making it harder to read and understand code because its not clear what function they have.

Noncompliant code:
int i;

for (i = 0; i < 10; i++)


Compliant code:
int counter;

for (counter = 0; counter < 10; counter++)


Type: Code smell

thanks, @flyerwire ! (cc @Nicolas_Harraudeau)

Hi @flyerwire,

Thank you for this suggestion. It is indeed a best practice to name correctly variables and one letter variables can make the code less readable. However I am not sure that raising an issue on every one-letter variable is a good approach. In some cases such variable names can make sense. For example x, y and z are perfectly fine for coordinates.

As described here, it depends on the conventions and scope of the variables.

It is true that some tools such as pylint will raise issues on one-letter variable names, but SonarSource products try to raise as little false positives as possible. Thus we can’t accept this rule as it is defined.

We could however try to reduce the scope of this rule to specific cases, such as function parameters.