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

Suppress in individual files #255

Merged
merged 33 commits into from
Sep 15, 2020
Merged

Conversation

aktsay6
Copy link
Collaborator

@aktsay6 aktsay6 commented Sep 8, 2020

What has been done:

  1. Warn method remade so it checks if there is suppress on this warning
  2. Added test
  3. All warn and warnAndFix calls fixed

Actions checklist

  • Implemented Rule, added Warnings
  • Added tests on checks
  • Added tests on fixers
  • Updated rules-config.json
  • Updated available-rules.md

Closes #176

### 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
@aktsay6 aktsay6 added the enhancement New feature or request label Sep 8, 2020
@aktsay6 aktsay6 requested review from petertrr and kentr0w September 8, 2020 13:58
# 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
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #255 into master will increase coverage by 0.02%.
The diff coverage is 87.96%.

Impacted file tree graph

@@             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     
Flag Coverage Δ Complexity Δ
#unittests 81.25% <87.96%> (+0.02%) 957.00 <7.00> (+1.00)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...kotlin/org/cqfn/diktat/ruleset/rules/FileNaming.kt 8.69% <0.00%> (ø) 2.00 <0.00> (ø)
...tlin/org/cqfn/diktat/ruleset/constants/Warnings.kt 96.38% <50.00%> (ø) 8.00 <3.00> (+1.00)
.../cqfn/diktat/ruleset/rules/BlockStructureBraces.kt 83.67% <50.00%> (ø) 53.00 <0.00> (ø)
.../ruleset/rules/BracesInConditionalsAndLoopsRule.kt 80.35% <50.00%> (ø) 26.00 <0.00> (ø)
...kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt 66.66% <66.66%> (ø) 10.00 <0.00> (ø)
...g/cqfn/diktat/ruleset/rules/kdoc/KdocFormatting.kt 76.35% <80.95%> (ø) 81.00 <0.00> (ø)
...tlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt 83.42% <81.81%> (-0.11%) 0.00 <0.00> (ø)
...cqfn/diktat/ruleset/rules/AnnotationNewLineRule.kt 90.90% <100.00%> (ø) 15.00 <0.00> (ø)
...ktat/ruleset/rules/ClassLikeStructuresOrderRule.kt 80.30% <100.00%> (ø) 26.00 <0.00> (ø)
...cqfn/diktat/ruleset/rules/ConsecutiveSpacesRule.kt 92.00% <100.00%> (ø) 15.00 <0.00> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2d6ac6...0a40734. Read the comment docs.

### What's done:
 * Fixed bugs
Copy link
Collaborator

@kentr0w kentr0w left a 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

@@ -0,0 +1,22 @@
package org.cqfn.diktat.ruleset.chapter3
Copy link
Collaborator

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?

aktsay6 and others added 9 commits September 10, 2020 15:16
### 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
@aktsay6 aktsay6 requested a review from kentr0w September 10, 2020 17:39
import org.cqfn.diktat.util.LintTestBase
import org.junit.jupiter.api.Test

class SuppressTest : LintTestBase(::IdentifierNaming) {
Copy link
Member

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.

Copy link
Member

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("...")

Copy link
Member

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.

Copy link
Member

@petertrr petertrr left a 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
@aktsay6 aktsay6 requested a review from petertrr September 11, 2020 11:44
### What's done:
  * Fixed bug
### What's done:
  * Added to README.md
README.md Outdated Show resolved Hide resolved
### What's done:
  * Fixed description
@aktsay6 aktsay6 requested a review from petertrr September 14, 2020 10:56
import org.cqfn.diktat.util.LintTestBase
import org.junit.jupiter.api.Test

class SuppressTest : LintTestBase(::IdentifierNaming) {
Copy link
Member

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
@aktsay6 aktsay6 requested a review from petertrr September 15, 2020 12:04
### What's done:
 * Added test
Comment on lines 321 to 323
&& it.valueArgumentList?.arguments?.isNotEmpty() ?: false // don't suppress anything
&& it.valueArgumentList?.arguments
?.firstOrNull()?.text?.contains(warningName) ?: true
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
&& 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]
Copy link
Member

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
Copy link
Member

@petertrr petertrr left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
?.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) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val children: ASTNode? = if (node.elementType != FILE) {
val annotationNode = if (node.elementType != FILE) {

### What's done:
 * Fixed bugs
Copy link
Member

@petertrr petertrr left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@kentr0w kentr0w left a comment

Choose a reason for hiding this comment

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

LGTM

@aktsay6 aktsay6 merged commit e60f271 into master Sep 15, 2020
@aktsay6 aktsay6 deleted the feature/suppress-in-individual-files branch September 15, 2020 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to suppress individual warnings for individual files
4 participants