Skip to content

New rule: Array iteration should be in range #95

@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

Array iteration should be in range

Rule description

This rule would pick up on cases where a loop iterator may become out of range of the underlying array, by determining that the upper bound of iteration is less than or equal to the length of the array - 1. For example:

for I := 0 to Length(MyArr) do begin
  // ...
end;

This could also be extended to lists:

for I := 0 to MyList.Count do begin
  // ...
end;

Rationale

It's a very common problem to write for I := 0 to Length(MyArr), as it looks correct at first glance. This rule would catch those cases before causing a range check error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestruleImprovements or additions to rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions