Skip to content

Commit 3f372ca

Browse files
Add MisleadingIndentation linting for On statement
Also added testing Signed-off-by: Shreyas Khandekar <[email protected]>
1 parent 8519e8f commit 3f372ca

File tree

4 files changed

+123
-2
lines changed

4 files changed

+123
-2
lines changed

test/chplcheck/MisleadingIndentation.chpl

+51
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,55 @@ writeln("second thing");
2828
writeln("Hello, world!");
2929
var unrelated = "hi";
3030
}
31+
32+
on Locale[0] do
33+
writeln("Hello, world!");
34+
writeln("Hello, world!");
35+
36+
for 1..10 do
37+
for 1..10 do
38+
writeln("Hello, world!");
39+
writeln("Hello, world!");
40+
41+
for 1..10 do
42+
on Locale[0] do
43+
writeln("Hello, world!");
44+
writeln("Hello, world!");
45+
46+
on Locale[0] do
47+
for 1..10 do
48+
writeln("Hello, world!");
49+
writeln("Hello, world!");
50+
51+
on Locale[0] do
52+
on Locale[0] do
53+
writeln("Hello, world!");
54+
writeln("Hello, world!");
55+
56+
57+
for 1..10 do
58+
for 1..10 do
59+
for 1..10 do
60+
writeln("Hello, world!");
61+
writeln("Hello, world!");
62+
63+
for 1..10 do
64+
for 1..10 do
65+
for 1..10 do
66+
for 1..10 do
67+
writeln("Hello, world!");
68+
writeln("Hello, world!");
69+
70+
for 1..10 do
71+
for 1..10 do
72+
on Locale[0] do
73+
writeln("Hello, world!");
74+
writeln("Hello, world!");
75+
76+
on Locale[0] do
77+
on Locale[0] do
78+
on Locale[0] do
79+
writeln("Hello, world!");
80+
writeln("Hello, world!");
81+
3182
}

test/chplcheck/MisleadingIndentation.good

+9
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@ MisleadingIndentation.chpl:13: node violates rule MisleadingIndentation
33
MisleadingIndentation.chpl:18: node violates rule MisleadingIndentation
44
MisleadingIndentation.chpl:23: node violates rule IncorrectIndentation
55
MisleadingIndentation.chpl:24: node violates rule MisleadingIndentation
6+
MisleadingIndentation.chpl:34: node violates rule MisleadingIndentation
7+
MisleadingIndentation.chpl:39: node violates rule MisleadingIndentation
8+
MisleadingIndentation.chpl:44: node violates rule MisleadingIndentation
9+
MisleadingIndentation.chpl:49: node violates rule MisleadingIndentation
10+
MisleadingIndentation.chpl:54: node violates rule MisleadingIndentation
11+
MisleadingIndentation.chpl:61: node violates rule MisleadingIndentation
12+
MisleadingIndentation.chpl:68: node violates rule MisleadingIndentation
13+
MisleadingIndentation.chpl:74: node violates rule MisleadingIndentation
14+
MisleadingIndentation.chpl:80: node violates rule MisleadingIndentation
615
[Success matching fixit for MisleadingIndentation]

test/chplcheck/MisleadingIndentation.good-fixit

+51
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,55 @@ writeln(i);
3030
writeln("Hello, world!");
3131
var unrelated = "hi";
3232
}
33+
34+
on Locale[0] do
35+
writeln("Hello, world!");
36+
writeln("Hello, world!");
37+
38+
for 1..10 do
39+
for 1..10 do
40+
writeln("Hello, world!");
41+
writeln("Hello, world!");
42+
43+
for 1..10 do
44+
on Locale[0] do
45+
writeln("Hello, world!");
46+
writeln("Hello, world!");
47+
48+
on Locale[0] do
49+
for 1..10 do
50+
writeln("Hello, world!");
51+
writeln("Hello, world!");
52+
53+
on Locale[0] do
54+
on Locale[0] do
55+
writeln("Hello, world!");
56+
writeln("Hello, world!");
57+
58+
59+
for 1..10 do
60+
for 1..10 do
61+
for 1..10 do
62+
writeln("Hello, world!");
63+
writeln("Hello, world!");
64+
65+
for 1..10 do
66+
for 1..10 do
67+
for 1..10 do
68+
for 1..10 do
69+
writeln("Hello, world!");
70+
writeln("Hello, world!");
71+
72+
for 1..10 do
73+
for 1..10 do
74+
on Locale[0] do
75+
writeln("Hello, world!");
76+
writeln("Hello, world!");
77+
78+
on Locale[0] do
79+
on Locale[0] do
80+
on Locale[0] do
81+
writeln("Hello, world!");
82+
writeln("Hello, world!");
83+
3384
}

tools/chplcheck/src/rules.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ def MisleadingIndentation(context: Context, root: AstNode):
551551
fix = append_nested_single_stmt(child, prev)
552552

553553
def append_nested_single_stmt(node, prev: List[AstNode]):
554-
if (isinstance(node, Loop)) and node.block_style() == "implicit":
554+
if isinstance(node, Loop) and node.block_style() == "implicit":
555555
children = list(node)
556-
# safe to access [-1], loops or on stmt must have at least 1 child
556+
# safe to access [-1], loops must have at least 1 child
557557
for blockchild in reversed(list(children[-1])):
558558
if isinstance(blockchild, Comment):
559559
continue
@@ -562,6 +562,16 @@ def append_nested_single_stmt(node, prev: List[AstNode]):
562562
prev.append(blockchild)
563563
append_nested_single_stmt(blockchild, prev)
564564
return node # Return the outermost loop to use an anchor
565+
elif isinstance(node, On) and node.block_style() == "implicit":
566+
for stmt in node.stmts():
567+
if isinstance(stmt, Comment):
568+
continue
569+
if might_incorrectly_report_location(stmt):
570+
continue
571+
prev.append(stmt)
572+
append_nested_single_stmt(stmt, prev)
573+
return node # Return the outermost on to use an anchor
574+
# Should we also check for Conditionals here?
565575
return None
566576

567577
@driver.fixit(MisleadingIndentation)

0 commit comments

Comments
 (0)