From 2f0837c7bb2f567291ed4e7debfea39eeeb67112 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 22 Aug 2024 09:48:18 -0700 Subject: [PATCH 1/5] Enable silencing incorrect indentation between parent and child statements It's unclear how to silence this for sibling statements; using attributes on either sibling doesn't seem like the right approach. Signed-off-by: Danila Fedorin --- tools/chplcheck/src/rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 2060afe74b3f771028e85a9e84888eb1599ca228 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 22 Aug 2024 09:50:37 -0700 Subject: [PATCH 2/5] Add test for silencing incorrect indentation warnings Signed-off-by: Danila Fedorin --- test/chplcheck/IncorrectIndentation.chpl | 34 ++++++++++++++++++++++++ test/chplcheck/IncorrectIndentation.good | 4 +++ 2 files changed, 38 insertions(+) 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..2dae0454759b 100644 --- a/test/chplcheck/IncorrectIndentation.good +++ b/test/chplcheck/IncorrectIndentation.good @@ -59,3 +59,7 @@ 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 From 4a32f83188c78dce0627354c43b9f3de338709e3 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 22 Aug 2024 09:52:20 -0700 Subject: [PATCH 3/5] Make chplcheck a known tool attribute namespace Signed-off-by: Danila Fedorin --- frontend/include/chpl/framework/all-global-strings.h | 1 + frontend/lib/uast/post-parse-checks.cpp | 1 + test/chplcheck/COMPOPTS | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) 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 87e9b0a32801..d04613f69cf1 100644 --- a/frontend/lib/uast/post-parse-checks.cpp +++ b/frontend/lib/uast/post-parse-checks.cpp @@ -1602,6 +1602,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 From cbd3769cc7acd43a8550cea971345083e92a16ed Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 22 Aug 2024 10:07:03 -0700 Subject: [PATCH 4/5] Update a test which now prefers a different fixit Signed-off-by: Danila Fedorin --- test/chplcheck/MisleadingIndentation.good-fixit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"); From 425813fde35a5c67ed3dfa0729ef88a147570b75 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 22 Aug 2024 10:26:15 -0700 Subject: [PATCH 5/5] Add an auto-fixit good file Signed-off-by: Danila Fedorin --- test/chplcheck/IncorrectIndentation.good | 1 + .../chplcheck/IncorrectIndentation.good-fixit | 388 ++++++++++++++++++ 2 files changed, 389 insertions(+) create mode 100644 test/chplcheck/IncorrectIndentation.good-fixit diff --git a/test/chplcheck/IncorrectIndentation.good b/test/chplcheck/IncorrectIndentation.good index 2dae0454759b..2af1bee54482 100644 --- a/test/chplcheck/IncorrectIndentation.good +++ b/test/chplcheck/IncorrectIndentation.good @@ -63,3 +63,4 @@ 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"); + } + } +}