Skip to content

Commit

Permalink
chplcheck: allow ignoring parent/child incorrect indentation using `@…
Browse files Browse the repository at this point in the history
…chplcheck.ignore` (#25800)

This RP allows for disabling the `IncorrectIndentation` warning for
statements that are incorrectly indented relatively to their parent:

```Chapel
@chplcheck.ignore("IncorrectIndentation")
module M {
proc foo() { // would warn; silenced by attribute
  writeln("Hi");
    writeln("There"); // still warns; attribute doesn't globally disable warnings
}
}
```

This helps the case in which a previously-implicit module is converted
into an explicit module.

This code:
```Chapel
proc foo() {
  writeln("Hi");
    writeln("There");
}
```

Becomes:

```Chapel
module NewMod {
proc foo() { // would warn; silenced by attribute
  writeln("Hi");
    writeln("There"); // still warns; attribute doesn't globally disable warnings
}
}
```

Now, `foo` is incorrectly indented. To fix this, the entire file would
need to be indented by two spaces, which creates a big diff and may be
undesirable. By adding the ability to ignore an individual parent/child
indentation violation using `@chplcheck.ignore`, this PR makes it
possible to silence the warnings from explicitly defining `NewMod`,
while preserving all other indentation warnings that had existed in the
code previously (or would appear in the code in the future).

This PR also adds the `chplcheck` attribute to a list of well-known
tools by the compiler, in preparation of using this attribute with the
standard library.

Reviewed by @jabraham17 -- thanks!

## Testing
- [x] `test/chplcheck`
  • Loading branch information
DanilaFe authored Aug 22, 2024
2 parents 3b13bda + 425813f commit 45710bb
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 3 deletions.
1 change: 1 addition & 0 deletions frontend/include/chpl/framework/all-global-strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ X(swap , "<=>")
X(chplBy , "chpl_by")
X(chplAlign , "chpl_align")
X(chpldocDot , "chpldoc.")
X(chplcheckDot , "chplcheck.")
X(llvmDot , "llvm.")
X(llvmMetadata , "llvm.metadata")
X(llvmAssertVectorized, "llvm.assertVectorized")
Expand Down
1 change: 1 addition & 0 deletions frontend/lib/uast/post-parse-checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,7 @@ void Visitor::checkAttributeNameRecognizedOrToolSpaced(const Attribute* node) {
node->name() == USTR("assertOnGpu") ||
node->name() == USTR("gpu.blockSize") ||
node->name().startsWith(USTR("chpldoc.")) ||
node->name().startsWith(USTR("chplcheck.")) ||
node->name().startsWith(USTR("llvm."))) {
// TODO: should we match chpldoc.nodoc or anything toolspaced with chpldoc.?
return;
Expand Down
2 changes: 1 addition & 1 deletion test/chplcheck/COMPOPTS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--using-attribute-toolname chplcheck --stop-after-pass=parseAndConvertUast
--stop-after-pass=parseAndConvertUast
34 changes: 34 additions & 0 deletions test/chplcheck/IncorrectIndentation.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,38 @@ module IncorrectIndentation {
private use super.M2;
private use super.M2;
}


@chplcheck.ignore("IncorrectIndentation")
module DirectChildrenNotIndented {
proc f1()
{
writeln("hi");
writeln("??");
}

proc f2()
{
writeln("hi");
}

@chplcheck.ignore("IncorrectIndentation")
proc f3() {
writeln("hi");
}

proc f4() {
writeln("hi");
writeln("hi");
}

proc f5() {
writeln("hi"); writeln("hi");
}

proc f6() {
for 1..10 do
writeln("hi");
}
}
}
5 changes: 5 additions & 0 deletions test/chplcheck/IncorrectIndentation.good
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ IncorrectIndentation.chpl:305: node violates rule IncorrectIndentation
IncorrectIndentation.chpl:308: node violates rule EmptyStmts
IncorrectIndentation.chpl:314: node violates rule IncorrectIndentation
IncorrectIndentation.chpl:321: node violates rule IncorrectIndentation
IncorrectIndentation.chpl:339: node violates rule IncorrectIndentation
IncorrectIndentation.chpl:349: node violates rule IncorrectIndentation
IncorrectIndentation.chpl:353: node violates rule IncorrectIndentation
IncorrectIndentation.chpl:358: node violates rule IncorrectIndentation
[Success matching fixit for IncorrectIndentation]
Loading

0 comments on commit 45710bb

Please sign in to comment.