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

Rule configuration request: Ignore based on annotations #2563

Closed
ZacSweers opened this issue Mar 31, 2020 · 2 comments · Fixed by #2570
Closed

Rule configuration request: Ignore based on annotations #2563

ZacSweers opened this issue Mar 31, 2020 · 2 comments · Fixed by #2570

Comments

@ZacSweers
Copy link
Contributor

Expected Behavior of the rule

LongParameterList:
  active: true
  functionThreshold: 7
  constructorThreshold: 7
  ignoreDefaultParameters: false
  ignoreDataClasses: true
  ignoreAnnotated: "javax.inject.Inject,javax.annotation.Generated"

Context

Currently the LongParameterList rule applies to all constructors but has an opt-out for data classes. I'd like to suggest adding a new configuration to ignore based on annotations, such as javax.inject.Inject. This comes up often in our DI plumbing

@schalkms
Copy link
Member

schalkms commented Mar 31, 2020

Please go ahead. I think this a good idea.
Do you have resources to tackle this? @ZacSweers
It should be very easy to add this in the LongParameterList class in the following function.
The function can be extended to check constructor.annotations.any { ignoreAnnotated.contains(it.text) }.

https://github.com/arturbosch/detekt/blob/91fdc64fecb858045059bf544fa9bfb6017c8c1d/detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongParameterList.kt#L65-L71

ZacSweers added a commit to ZacSweers/detekt that referenced this issue Apr 1, 2020
Resolves detekt#2563

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

Done: #2570

@arturbosch arturbosch added this to the 1.8.0 milestone Apr 2, 2020
arturbosch pushed a commit that referenced this issue Apr 6, 2020
* Add ignoreAnnotated option to LongParameterList

Resolves #2563

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

* Fix detekt issues

* Fix docs

* Fix moar

* Add inject

* Use deprecated instead

* Consolidate KAnnotated

* Use function

Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>

* Fix suggestion conflicts

* Fix detekt

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants