Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Tree deletion suggestions #347

Merged
merged 3 commits into from
Nov 21, 2022

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Nov 13, 2022

Suggested commit message:

Improve `Tree` deletion suggestions (#347)

When suggesting to remove a method or method annotation, also remove any
trailing whitespace. This avoids the possible introduction of an empty
line right at the start of a code block.

See also this comment.

@Stephan202 Stephan202 added this to the 0.6.0 milestone Nov 13, 2022
@Stephan202 Stephan202 requested a review from rickie November 13, 2022 13:16
@Stephan202 Stephan202 marked this pull request as ready for review November 13, 2022 13:29
@rickie rickie requested a review from ibabiankou November 16, 2022 10:15
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit.

WDYT about removing the XXX at the top of the class of SourceCode? I think by now it kinda "fits" in the util package together with the other utilities.

Nice and creative way of testing this 🚀 !

}

/**
* Uses {@link SourceCode#deleteWithTrailingWhitespace(Tree, VisitorState)} to suggest the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all @BugPatterns we start with A {@link BugChecker} that, so would suggest to do the same here.

@Stephan202 Stephan202 force-pushed the sschroevers/avoid-empty-lines-at-start-of-code-block branch from fcf3521 to defbb27 Compare November 19, 2022 10:06
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit.

I don't see a second commit 👀

WDYT about removing the XXX at the top of the class of SourceCode? I think by now it kinda "fits" in the util package together with the other utilities.

Works for me!

Rebased and added a commit ;)

@rickie
Copy link
Member

rickie commented Nov 19, 2022

Oops, I don't know what happened but thanks for applying 😉.

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be afk for the next >24 hours; can add a commit later.

Comment on lines 56 to 59
int actualEnd = NON_WHITESPACE_MATCHER.indexIn(sourceCode, endPos);
return actualEnd == -1
? SuggestedFix.delete(tree)
: SuggestedFix.replace(((DiagnosticPosition) tree).getStartPosition(), actualEnd, "");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I think we ever hit this case, but I think we should use sourceCode.length() if actualEnd == -1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit.

When suggesting to remove a method or method annotation, also remove any
trailing whitespace. This avoids the possible introduction of an empty
line right at the start of a code block.
@Stephan202 Stephan202 force-pushed the sschroevers/avoid-empty-lines-at-start-of-code-block branch from defbb27 to bdb60ee Compare November 20, 2022 14:21
Copy link

@ibabiankou ibabiankou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 🚀

@rickie rickie merged commit 98185b9 into master Nov 21, 2022
@rickie rickie deleted the sschroevers/avoid-empty-lines-at-start-of-code-block branch November 21, 2022 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants