[Chapel Merge] Misleading indent var warn

Branch: refs/heads/main
Revision: c84a1def70ee0b84208ba268b629c58c193c1fb8
Author: DanilaFe
Link: Misleading indent var warn by DanilaFe · Pull Request #25207 · chapel-lang/chapel · GitHub
Log Message:
Misleading indent var warn (#25207)

This was caused by the incorrect location reporting for variables. If
the code above is 4-indented, and then location of the name is used,
that name is also 4-indented, code flags as misleading.

As an example:

      for 1..10 do
          writeln("Hello, world!");
      var unrelated = "hi";

Note that unrelated and writeln happen to be aligned, which is
sufficient for the false positive.

Reported by @alvaradoo -- thanks!

The solution is to steal the logic from IncorrectIndentation that avoids
AST nodes that report their locations oddly.

Reviewed by @jabraham17 -- thanks!

Testing

  • start_test test/chplcheck.

Compare: Comparing 00d7194f0da7ef88ee0a3da0c2166a12d5a159aa...618245955ab6bc527d1fd48456ec5ef153173135 · chapel-lang/chapel · GitHub

Diff:
M test/chplcheck/MisleadingIndentation.chpl
M test/chplcheck/MisleadingIndentation.good-fixit
M tools/chplcheck/src/rules.py
https://github.com/chapel-lang/chapel/pull/25207.diff