sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

New rule: StrUtils should be preferred over 'Copy'

Open Skarvion opened this issue 6 months ago • 1 comments

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

Should use 'LeftStr' instead of 'Copy' from start

Rule description

Using Copy(Text, 1, Count) is the equivalent of using LeftStr(Text, Count) but impacts readability and making the intention harder to understand. Using LeftStr conveys intention better.

Rationale

Seeing many Copy used in different context makes it harder to understand the intention of its usage. By removing a sizeable chunk of generic Copy(Text, 1, Count), it makes it easier to focus on where other usage of Copy does matter.

Skarvion avatar Aug 12 '24 02:08 Skarvion