[Chapel Merge] chplcheck: provide alternative fix-it for misleading indentation

Branch: refs/heads/main
Revision: 5b779c2d16121d7464f72c4163c31dff7fb3fa2b
Author: DanilaFe
Link: chplcheck: provide alternative fix-it for misleading indentation by DanilaFe · Pull Request #28560 · chapel-lang/chapel · GitHub
Log Message:
chplcheck: provide alternative fix-it for misleading indentation (#28560)

Bad codeOld fixitThis Fixit
for i in 1..10 do
    writeln("Hi");
    writeln("Hello");
    writeln("World!");
    writeln("World!");
    if i == 5 {
        writeln("lol");
    }
writeln();
for i in 1..10 do
    writeln("Hi");
writeln("Hello");
    writeln("World!");
    writeln("World!");
    if i == 5 {
        writeln("lol");
    }
writeln();
for i in 1..10 {
    writeln("Hi");
    writeln("Hello");
    writeln("World!");
    writeln("World!");
    if i == 5 {
        writeln("lol");
    }
}
writeln();

This PR adds another way to fix misleading indentation for loops. In
theory, this could apply to other constructs, but I wanted to keep the
initial proof-of-concept simple.

This was motivated by a demonstration during our talk at HPSF, where
Jade showed off auto-fixes for misleading indentation. I had a thought:

Well, if the user thought Chapel is whitespace-sensitive, and indented
several lines hoping to run them all as part of the loop, shouldn't the
auto-fix help them by making the program do that? Right now, it actively
fights the intent by unindenting code.

This PR implements that idea. It works by identifying all
misleadingly-indented children and grouping all of them. The workflow it
really intends to support is one in which uses indent multiple lines at
once, only to learn that they need to switch to curly braces.

workflow

Reviewed by @jabraham17 -- thanks!

Testing

  • new chplcheck tests pass

Compare: Comparing fe4e7247dcbc3b11e7f66f360af53837726381ec...3be842674d0de7fa5b96b8a9ad357985e5320d62 · chapel-lang/chapel · GitHub

Diff:
M test/chplcheck/MisleadingIndentation.chpl
M test/chplcheck/MisleadingIndentation.good
M test/chplcheck/MisleadingIndentation.good-fixit
A test/chplcheck/fixit-interactive/MisleadingIndentation.chpl
A test/chplcheck/fixit-interactive/MisleadingIndentation.good
A test/chplcheck/fixit-interactive/MisleadingIndentation.input
M tools/chplcheck/src/chplcheck.py
M tools/chplcheck/src/fixits.py
M tools/chplcheck/src/rule_types.py
M tools/chplcheck/src/rules.py
https://github.com/chapel-lang/chapel/pull/28560.diff