diff --git a/frontend/include/chpl/framework/all-global-strings.h b/frontend/include/chpl/framework/all-global-strings.h index 772dc699c775..46da096453eb 100644 --- a/frontend/include/chpl/framework/all-global-strings.h +++ b/frontend/include/chpl/framework/all-global-strings.h @@ -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") diff --git a/frontend/lib/uast/post-parse-checks.cpp b/frontend/lib/uast/post-parse-checks.cpp index 733680e4d467..129e43902f1e 100644 --- a/frontend/lib/uast/post-parse-checks.cpp +++ b/frontend/lib/uast/post-parse-checks.cpp @@ -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; diff --git a/test/chplcheck/COMPOPTS b/test/chplcheck/COMPOPTS index c94dece26c4d..16b1d028e72c 100644 --- a/test/chplcheck/COMPOPTS +++ b/test/chplcheck/COMPOPTS @@ -1 +1 @@ - --using-attribute-toolname chplcheck --stop-after-pass=parseAndConvertUast + --stop-after-pass=parseAndConvertUast diff --git a/test/chplcheck/IncorrectIndentation.chpl b/test/chplcheck/IncorrectIndentation.chpl index 9244e6bfa5e6..b8a26d69ea97 100644 --- a/test/chplcheck/IncorrectIndentation.chpl +++ b/test/chplcheck/IncorrectIndentation.chpl @@ -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"); + } + } } diff --git a/test/chplcheck/IncorrectIndentation.good b/test/chplcheck/IncorrectIndentation.good index a15ca0936223..2af1bee54482 100644 --- a/test/chplcheck/IncorrectIndentation.good +++ b/test/chplcheck/IncorrectIndentation.good @@ -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] diff --git a/test/chplcheck/IncorrectIndentation.good-fixit b/test/chplcheck/IncorrectIndentation.good-fixit new file mode 100644 index 000000000000..fd5e9aa9ae15 --- /dev/null +++ b/test/chplcheck/IncorrectIndentation.good-fixit @@ -0,0 +1,388 @@ +module IncorrectIndentation { + proc f1() + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + 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() { + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + module M1 + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + module M2 + { + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + module M3 { + writeln("hi"); + } + + module M4 { + writeln("hi"); + writeln("hi"); + } + + module M5 { + writeln("hi"); writeln("hi"); + } + + module M6 { + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + for 1..10 { + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + for 1..10 + { + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + for 1..10 { + writeln("hi"); + } + + module NestedOuter { + module NestedInner { + writeln("hi"); + writeln("??"); + writeln("??"); + record nestedRecord { + proc firstProc() {} + proc secondProc() {} + proc thirdProc() {} + + proc nestedProcOuter() { + proc nestedProcInner(x: int) do return x; + proc nestedProcInner(x: string) { + writeln(x); + writeln(x); + writeln(x); + return x; + } + } + } + } + } + + on here + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + on here + { + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + on here { + writeln("hi"); + } + + on here { + writeln("hi"); + writeln("hi"); + } + + on here { + writeln("hi"); writeln("hi"); + } + + on here { + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + begin + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + begin + { + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + begin { + writeln("hi"); + } + + begin { + writeln("hi"); + writeln("hi"); + } + + begin { + writeln("hi"); writeln("hi"); + } + + begin { + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + var dummy: int; + + begin with (ref dummy) + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + begin with (ref dummy) + { + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + begin with (ref dummy) { + writeln("hi"); + } + + begin with (ref dummy) { + writeln("hi"); + writeln("hi"); + } + + begin with (ref dummy) { + writeln("hi"); writeln("hi"); + } + + begin with (ref dummy) { + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + // Note: 'cobegins' with one statement throw warning, so all tests here include + // at least two statements. + + cobegin + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + cobegin + { + writeln("hi"); + writeln("hi"); + } + + @chplcheck.ignore("IncorrectIndentation") + cobegin { + writeln("hi"); + writeln("hi"); + } + + cobegin { + writeln("hi"); + writeln("hi"); + } + + cobegin { + writeln("hi"); writeln("hi"); + } + + cobegin { + writeln("hi"); + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + cobegin with (ref dummy) + { + writeln("hi"); + writeln("??"); + } + + cobegin with (ref dummy) + { + writeln("hi"); + writeln("hi"); + } + + cobegin with (ref dummy) { + writeln("hi"); + writeln("hi"); + } + + cobegin with (ref dummy) { + writeln("hi"); + writeln("hi"); + } + + cobegin with (ref dummy) { + writeln("hi"); writeln("hi"); + } + + cobegin with (ref dummy) { + writeln("hi"); + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + + enum e1 + { + first, + second + } + + @chplcheck.ignore("IncorrectIndentation") + enum e2 + { + first + } + + @chplcheck.ignore("IncorrectIndentation") + enum e3 { + first + } + + enum e4 { + first, + second + } + + enum e5 { + first, second + } + + union u1 + { + var element: int; + proc firstProc() {} + } + + @chplcheck.ignore("IncorrectIndentation") + union u2 + { + var element: int; + + proc firstProc() {} + } + + @chplcheck.ignore("IncorrectIndentation") + union u3 { + var element: int; + + proc firstProc() {} + } + + union u4 { + var element: int; + + proc firstProc() {} + proc secondProc() {} + } + + union u5 { + var element: int; + + proc firstProc() {} proc secondProc() {} + } + + enum color { red, green, blue } // semicolon warning does not issue bad indentation + + // Since locations are incorrectly reported with 'public' and 'private', + // these shouldn't warn. + module M7 { + proc f1 {} + proc g1 {} + public proc f2 {} + public proc g2 {} + private proc f3 {} + private proc g3 {} + + use super.M1; + use super.M1; + public use super.M2; + public use super.M2; + private use super.M2; + private use super.M2; + } + + + @chplcheck.ignore("IncorrectIndentation") + module DirectChildrenNotIndented { + proc f1() + { + writeln("hi"); + writeln("??"); + } + + @chplcheck.ignore("IncorrectIndentation") + 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() { + @chplcheck.ignore("IncorrectIndentation") + for 1..10 do + writeln("hi"); + } + } +} diff --git a/test/chplcheck/MisleadingIndentation.good-fixit b/test/chplcheck/MisleadingIndentation.good-fixit index 4930cbb9d44e..c3ac8c1086f4 100644 --- a/test/chplcheck/MisleadingIndentation.good-fixit +++ b/test/chplcheck/MisleadingIndentation.good-fixit @@ -20,7 +20,7 @@ writeln(i); ("second thing"); // the only fixit here is ignore, don't know the indentation level - @chplcheck.ignore("MisleadingIndentation") + @chplcheck.ignore("IncorrectIndentation") for i in 1..10 do writeln(i); writeln("second thing"); diff --git a/tools/chplcheck/src/rules.py b/tools/chplcheck/src/rules.py index cf3aba6545ab..8e7d8336f4cb 100644 --- a/tools/chplcheck/src/rules.py +++ b/tools/chplcheck/src/rules.py @@ -813,7 +813,7 @@ def unwrap_intermediate_block(node: AstNode) -> Optional[AstNode]: # var x: int; # } elif parent_depth and depth == parent_depth: - yield child + yield AdvancedRuleResult(child, anchor=parent_for_indentation) prev_depth = depth prev = child