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

Add ignoreAnnotated option to LongParameterList #2570

Merged
merged 10 commits into from
Apr 6, 2020

Conversation

ZacSweers
Copy link
Contributor

Resolves #2563

This adds a new ignoreAnnotated option to LongParameterList, that allows for ignoring annotations within function/class/file scope.

Resolves detekt#2563

This adds a new `ignoreAnnotated` option to `LongParameterList`, that allows for ignoring annotations within function/class/file scope.
@codecov-io
Copy link

codecov-io commented Apr 1, 2020

Codecov Report

Merging #2570 into master will increase coverage by 0.02%.
The diff coverage is 9.09%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2570      +/-   ##
============================================
+ Coverage     25.11%   25.13%   +0.02%     
  Complexity      392      392              
============================================
  Files           378      377       -1     
  Lines          7391     7388       -3     
  Branches       1221     1220       -1     
============================================
+ Hits           1856     1857       +1     
+ Misses         5404     5400       -4     
  Partials        131      131              
Impacted Files Coverage Δ Complexity Δ
...bosch/detekt/rules/complexity/LongParameterList.kt 26.19% <9.09%> (-2.39%) 2.00 <0.00> (ø)
...kotlin/io/gitlab/arturbosch/detekt/DetektPlugin.kt 0.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
.../arturbosch/detekt/internal/GradleProjectChecks.kt

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 adff475...e7e111d. Read the comment docs.

@arturbosch arturbosch added this to the 1.8.0 milestone Apr 2, 2020
Copy link
Member

@arturbosch arturbosch left a comment

Choose a reason for hiding this comment

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

Awesome first time contribution! Please see my two comments below.

}
}

private fun KtFile.isIgnored(): Boolean {
Copy link
Member

@arturbosch arturbosch Apr 2, 2020

Choose a reason for hiding this comment

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

These three nodes have KtAnnotated as a common super type.
Please refactor to something like:

    private fun KtAnnotated.isIgnored(): Boolean =
        annotationEntries.any { ignoreAnnotated.contains(it.typeReference?.text) }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -4,4 +4,7 @@ dependencies {
implementation(project(":detekt-api"))

testImplementation(project(":detekt-test"))

// For @javax.inject.Inject usage in LongParameterListSpec.kt
testImplementation("javax.inject:javax.inject:1")
Copy link
Member

Choose a reason for hiding this comment

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

This dependency is actually not needed for the parser as we do not resolve any types. Please make sure the tests run without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CI checks fail without this, see the failure on the commit before I added it

Copy link
Member

Choose a reason for hiding this comment

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

If we use compileAndLint we need it in the classpath. The other option is to declare that annotation in every code snipet.

Copy link
Member

Choose a reason for hiding this comment

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

Can we use just a custom annotation or any already present in the jdk? Deprecated for example.
The test case does not necessary need javax.inject :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated!

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

Thanks for the awesome and quick implementation of the requested feature. I like it.

@@ -26,6 +29,7 @@ import org.jetbrains.kotlin.psi.KtSecondaryConstructor
* @configuration constructorThreshold - number of constructor parameters required to trigger the rule (default: `7`)
* @configuration ignoreDefaultParameters - ignore parameters that have a default value (default: `false`)
* @configuration ignoreDataClasses - ignore long constructor parameters list for data classes (default: `true`)
* @configuration ignoreAnnotated - ignore long parameters list for constructors or functions in the context of these comma-separated annotation class names (default: `''`)
Copy link
Member

Choose a reason for hiding this comment

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

@BraisGabin I'm not show whether we should use the yaml list syntax for this configuration option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was matching what some others that used fully qualified names do, and this allows for some wildcard matching. Unclear if using the actual yml list format would support this

Copy link
Member

Choose a reason for hiding this comment

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

I would go with string for now. For consistency. I'll change all at once. And, to give a bit of context, we are talking about #2498

ZacSweers and others added 3 commits April 3, 2020 16:19
Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
@schalkms schalkms requested a review from arturbosch April 4, 2020 14:47
@arturbosch arturbosch merged commit 3450420 into detekt:master Apr 6, 2020
@ZacSweers ZacSweers deleted the z/ignoreAnnotated branch February 6, 2021 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule configuration request: Ignore based on annotations
5 participants