Skip to content

Commit

Permalink
improve fixit to not leave behind whitespace
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Sep 27, 2024
1 parent fdc2b8a commit 1de6c81
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
24 changes: 12 additions & 12 deletions test/chplcheck/IncorrectIndentation.good-fixit
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/chplcheck/UnusedTaskIntent.good-fixit
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 17 additions & 3 deletions tools/chplcheck/src/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 1de6c81

Please sign in to comment.