-
Notifications
You must be signed in to change notification settings - Fork 39
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
Suppress in individual files #255
Conversation
### What's done: * First ideas
### What's done: * Warn method remade * Added suppress check * Added test
### What's done: * Warn method remade * Added suppress check * Added test
…iles' into feature/suppress-in-individual-files # Conflicts: # diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/SuppressTest.kt
# Conflicts: # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/LineLength.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/comments/CommentsRule.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/files/FileSize.kt
### What's done: * Fixed bugs
### What's done: * Fixed bugs
### What's done: * Fixed bugs
Codecov Report
@@ Coverage Diff @@
## master #255 +/- ##
============================================
+ Coverage 81.23% 81.25% +0.02%
- Complexity 956 957 +1
============================================
Files 50 50
Lines 2510 2524 +14
Branches 782 788 +6
============================================
+ Hits 2039 2051 +12
Misses 190 190
- Partials 281 283 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
### What's done: * Fixed bugs
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.
Please add more tests
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/BlockStructureBraces.kt
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,22 @@ | |||
package org.cqfn.diktat.ruleset.chapter3 |
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.
Why you have two tests in different directories?
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
### What's done: * Fixed bugs
### What's done: * Fixed bugs
…-individual-files # Conflicts: # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/LongNumericalValuesSeparatedRule.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/comments/CommentsRule.kt # diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/kdoc/KdocComments.kt
### What's done: * Fixed bugs
### What's done: * Fixed bugs
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
import org.cqfn.diktat.util.LintTestBase | ||
import org.junit.jupiter.api.Test | ||
|
||
class SuppressTest : LintTestBase(::IdentifierNaming) { |
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.
Please add more tests with various locations of annotation: on file level, on some top-level declarations etc.
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.
Please check if it is possible to suppress warnings for the entire file using @file:Suppress("...")
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.
This is an important feature, we need more tests: that other annotations do not cause false suppressions, that @Suppress
without parameters or with other parameters doesn't cause false suppressions, file-level annotations etc.
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.
See comments above
### What's done: * Fixed bugs
…-individual-files
### What's done: * Fixed bugs
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
Outdated
Show resolved
Hide resolved
…-individual-files
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
Show resolved
Hide resolved
### What's done: * Fixed bug
### What's done: * Added to README.md
### What's done: * Fixed description
### What's done: * Fixed bugs
…-individual-files
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
Outdated
Show resolved
Hide resolved
import org.cqfn.diktat.util.LintTestBase | ||
import org.junit.jupiter.api.Test | ||
|
||
class SuppressTest : LintTestBase(::IdentifierNaming) { |
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.
This is an important feature, we need more tests: that other annotations do not cause false suppressions, that @Suppress
without parameters or with other parameters doesn't cause false suppressions, file-level annotations etc.
### What's done: * Fixed bugs
### What's done: * Added test
&& it.valueArgumentList?.arguments?.isNotEmpty() ?: false // don't suppress anything | ||
&& it.valueArgumentList?.arguments | ||
?.firstOrNull()?.text?.contains(warningName) ?: true |
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.
&& it.valueArgumentList?.arguments?.isNotEmpty() ?: false // don't suppress anything | |
&& it.valueArgumentList?.arguments | |
?.firstOrNull()?.text?.contains(warningName) ?: true | |
&& it.valueArgumentList?.arguments | |
?.firstOrNull()?.text?.contains(warningName) ?: false |
If list is empty, firstOrNull
will return null and result will be false
.
val code = | ||
""" | ||
class SomeClass() { | ||
@set:[Suppress("IDENTIFIER_LENGTH") Inject] |
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.
👍
### What's done: * Fixed bugs
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.
Just a couple of minor suggestions
?.any { | ||
it.shortName.toString() == Suppress::class.simpleName | ||
&& it.valueArgumentList?.arguments | ||
?.firstOrNull()?.text?.contains(warningName) ?: false |
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.
?.firstOrNull()?.text?.contains(warningName) ?: false | |
?.firstOrNull()?.text?.equals(warningName) ?: false |
@@ -303,10 +307,27 @@ fun ASTNode?.isAccessibleOutside(): Boolean = | |||
true | |||
} | |||
|
|||
fun ASTNode.hasSuppress(warningName: String): Boolean { | |||
return parent({ node -> | |||
val children: ASTNode? = if (node.elementType != 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.
val children: ASTNode? = if (node.elementType != FILE) { | |
val annotationNode = if (node.elementType != FILE) { |
### What's done: * Fixed bugs
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.
LGTM
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.
LGTM
What has been done:
Actions checklist
Closes #176