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

LongMethod: add 'ignoreAnnotated' configuration option #3892

Merged
merged 5 commits into from
Jun 24, 2021

Conversation

t-kameyama
Copy link
Contributor

Fixes #3887

@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

Merging #3892 (1c9a382) into main (f4f41f9) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #3892      +/-   ##
============================================
+ Coverage     83.51%   83.54%   +0.02%     
- Complexity     3118     3119       +1     
============================================
  Files           456      456              
  Lines          8992     8974      -18     
  Branches       1752     1746       -6     
============================================
- Hits           7510     7497      -13     
+ Misses          566      565       -1     
+ Partials        916      912       -4     
Impacted Files Coverage Δ
...b/arturbosch/detekt/rules/complexity/LongMethod.kt 89.58% <100.00%> (+0.94%) ⬆️
...b/arturbosch/detekt/rules/naming/FunctionNaming.kt 96.15% <100.00%> (ø)
...rturbosch/detekt/rules/style/UnusedPrivateClass.kt 70.00% <0.00%> (-3.34%) ⬇️
...ls/src/main/kotlin/io/github/detekt/psi/KtFiles.kt 77.77% <0.00%> (+4.24%) ⬆️

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 f4f41f9...1c9a382. Read the comment docs.

@@ -57,6 +61,8 @@ class LongMethod(config: Config = Config.empty) : Rule(config) {
}
for ((function, lines) in functionToLines) {
if (lines >= threshold) {
val annotationExcluder = AnnotationExcluder(function.containingKtFile, ignoreAnnotated)
if (annotationExcluder.shouldExclude(function.annotationEntries)) continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought: How about checking if the function is annotated with an ignored function in visitNamedFunction and not count the lines and put the function into the map in the first place?

@@ -38,6 +39,9 @@ class LongMethod(config: Config = Config.empty) : Rule(config) {
@Configuration("number of lines in a method to trigger the rule")
private val threshold: Int by config(defaultValue = 60)

@Configuration("ignore long methods in the context of these annotation class names")
private val ignoreAnnotated: List<String> by config(listOf("Composable"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the idea that the detekt defaults become more and more android related. In my opinion it should focus on the kotlin language and not on frameworks like Spring or Android.

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've implemented it the same as FunctionNaming.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know, your PR is totally fine. Maybe I should have started a discussion rather than raising this here. Sorry about that.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that we shouldn’t have such opinionated defaults. Sometimes it slipped through the reviews. In general, we handled it in the past like @marschwar said.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove this default value from both rules.

@@ -71,6 +75,9 @@ class LongMethod(config: Config = Config.empty) : Rule(config) {
}

override fun visitNamedFunction(function: KtNamedFunction) {
val annotationExcluder = AnnotationExcluder(function.containingKtFile, ignoreAnnotated)
Copy link
Contributor

@marschwar marschwar Jun 23, 2021

Choose a reason for hiding this comment

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

I don't know how nit picky this is but creating the Excluder for every function seems wasteful. I prefer the way this is implemented in LongParameterList.

private lateinit var annotationExcluder: AnnotationExcluder

override fun visitKtFile(file: KtFile) {
    annotationExcluder = AnnotationExcluder(file, ignoreAnnotated)
    super.visitKtFile(file)
}

Copy link
Member

Choose a reason for hiding this comment

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

+1

@schalkms schalkms merged commit 703487e into detekt:main Jun 24, 2021
@t-kameyama t-kameyama deleted the issue_3887 branch June 24, 2021 21:49
@schalkms schalkms added this to the 1.18.0 milestone Jun 25, 2021
marschwar pushed a commit to marschwar/detekt that referenced this pull request Jul 11, 2021
marschwar pushed a commit to marschwar/detekt that referenced this pull request Jul 11, 2021
BraisGabin pushed a commit that referenced this pull request Jul 13, 2021
#3892) (#3948)

Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
@dugsmith
Copy link

Thank you for adding this! 👏

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: [LongMethod] Ignore based on annotations
4 participants