From 1de6c81cf72caa6ccf9655f43ee0397faa7b3c82 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Fri, 27 Sep 2024 13:03:51 -0700 Subject: [PATCH] improve fixit to not leave behind whitespace Signed-off-by: Jade Abraham --- .../chplcheck/IncorrectIndentation.good-fixit | 24 +++++++++---------- test/chplcheck/UnusedTaskIntent.good-fixit | 8 +++---- tools/chplcheck/src/rules.py | 20 +++++++++++++--- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/test/chplcheck/IncorrectIndentation.good-fixit b/test/chplcheck/IncorrectIndentation.good-fixit index 8546595e2072..a15ca2d590da 100644 --- a/test/chplcheck/IncorrectIndentation.good-fixit +++ b/test/chplcheck/IncorrectIndentation.good-fixit @@ -163,31 +163,31 @@ module IncorrectIndentation { var dummy: int; - begin + begin { writeln("hi"); writeln("??"); } - begin + begin { writeln("hi"); } - begin { + begin { writeln("hi"); } - begin { + begin { writeln("hi"); writeln("hi"); } - begin { + begin { writeln("hi"); writeln("hi"); } - begin { + begin { @chplcheck.ignore("IncorrectIndentation") for 1..10 do writeln("hi"); @@ -229,33 +229,33 @@ module IncorrectIndentation { writeln("hi"); } - cobegin + cobegin { writeln("hi"); writeln("??"); } - cobegin + cobegin { writeln("hi"); writeln("hi"); } - cobegin { + cobegin { writeln("hi"); writeln("hi"); } - cobegin { + cobegin { writeln("hi"); writeln("hi"); } - cobegin { + cobegin { writeln("hi"); writeln("hi"); } - cobegin { + cobegin { writeln("hi"); @chplcheck.ignore("IncorrectIndentation") for 1..10 do diff --git a/test/chplcheck/UnusedTaskIntent.good-fixit b/test/chplcheck/UnusedTaskIntent.good-fixit index 8ecd3e3b4cfe..69a434794b6c 100644 --- a/test/chplcheck/UnusedTaskIntent.good-fixit +++ b/test/chplcheck/UnusedTaskIntent.good-fixit @@ -11,16 +11,16 @@ module UnusedTaskIntent { with (ref A, in B) {} - coforall 1..10 {} + coforall 1..10 {} begin with (ref A, + reduce B) {} - begin {} + begin {} - cobegin { } + cobegin { } - [1..10 ] { ; } + [1..10] { ; } @chplcheck.ignore("UnusedTaskIntent") [1..10 with (in A, diff --git a/tools/chplcheck/src/rules.py b/tools/chplcheck/src/rules.py index fa81119bd931..9177fe237f16 100644 --- a/tools/chplcheck/src/rules.py +++ b/tools/chplcheck/src/rules.py @@ -653,7 +653,7 @@ def UnusedTaskIntent(context: Context, root: AstNode): if isinstance(task_block, chapel.Loop): anchor = task_block yield AdvancedRuleResult( - taskvar, anchor, data=(taskvar, with_clause, task_block) + taskvar, anchor, data=(with_clause, task_block) ) @driver.fixit(UnusedTaskIntent) @@ -662,12 +662,26 @@ def RemoveTaskIntent(context: Context, result: AdvancedRuleResult): Remove the unused task intent from the function. """ assert isinstance(result.data, tuple) - _, with_clause, _ = result.data + with_clause, task_block = result.data fixit = None # if the with clause only has one expr, remove the entire with clause if len(list(with_clause.exprs())) == 1: - fixit = Fixit.build(Edit.build(with_clause.location(), "")) + with_loc = with_clause.location() + header_loc = ( + task_block.header_location() + if isinstance(task_block, Loop) + else task_block.block_header() + ) + if header_loc is not None: + start = header_loc.end() + end = with_loc.end() + else: + start = with_loc.start() + end = with_loc.end() + + fixit = Fixit.build(Edit(with_loc.path(), start, end, "")) + else: # for now, locations are messy enough that we can't easily cleanly # remove the taskvar