-
Notifications
You must be signed in to change notification settings - Fork 506
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
AnnotationRule: disallow empty line between annotation and annotated target #755
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AdamMTGreenberg
force-pushed
the
issue_688
branch
from
June 4, 2020 05:06
012f2cc
to
b29a868
Compare
romtsn
changed the title
Issue 688
AnnotationRule: disallow empty line between annotation and annotated target
Jun 5, 2020
romtsn
reviewed
Jun 8, 2020
...experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/AnnotationRuleTest.kt
Show resolved
Hide resolved
AdamMTGreenberg
force-pushed
the
issue_688
branch
from
June 10, 2020 13:56
dd95ebf
to
d0b7f36
Compare
…ent that the annotation is not separated from the object it is annotating
… Eg, this test should result in a failure since the @JvmField annotation is separated from the function by a blank line
…based on above rules for ensuring that we have a stable break with the list of annotations. Next step is to run unit test to make sure this triggers a failure
…hat we can ensure we see a valid break in the tests. Next step is to create a test for the auto correction
…get a solid check for our issue once the autoformat is added to our code
…re we have all the fields input correctly and we remove redundant line breaks
…er on ./gradlew :ktlint
@JvmField @JvmStatic fun foo() = Unit // and @JvmField @JvmStatic fun foo() = Unit
AdamMTGreenberg
force-pushed
the
issue_688
branch
from
June 18, 2020 09:31
d0b7f36
to
f7bbb59
Compare
romtsn
approved these changes
Jun 18, 2020
val diff = nextLineNumber - lineNumber | ||
// Ensure declaration is not on the same line, there is a line break in between, and it is not an | ||
// annotation we explicitly want to have a line break between | ||
if (lineNumber != nextLineNumber && diff > 1 && !node.text.contains("@file")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think diff > 1
is sufficient here right?
also not sure about the check for @file
presence - aren't you doing this already above with !it.isPartOf(FILE_ANNOTATION_LIST)
?
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #688
In essence, we should not have empty lines between an annotation and the thing that it's "annotating".
My fix adds an extra check in the annotation file that will ensure there is no duplicate spaces between Annotations and the elements that they are annotating. In addition, a suite of new tests have verified this assertion and the auto correct.