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

Introduce NamedArguments rule #3167

Merged
merged 3 commits into from
Oct 26, 2020
Merged

Conversation

sowmyav24
Copy link
Contributor

Fixes #1007

Changes done:

  • Introduce NamedArguments rule which enforces function invocation to have named parameters when they cross the threshold of number of non-named parameters.
  • Currently, the default is set to 3.

@codecov
Copy link

codecov bot commented Oct 24, 2020

Codecov Report

Merging #3167 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3167      +/-   ##
============================================
+ Coverage     79.51%   79.53%   +0.02%     
- Complexity     2599     2606       +7     
============================================
  Files           437      439       +2     
  Lines          7865     7927      +62     
  Branches       1497     1510      +13     
============================================
+ Hits           6254     6305      +51     
- Misses          817      821       +4     
- Partials        794      801       +7     
Impacted Files Coverage Δ Complexity Δ
...osch/detekt/rules/complexity/ComplexityProvider.kt 100.00% <100.00%> (ø) 3.00 <0.00> (ø)
...turbosch/detekt/rules/complexity/NamedArguments.kt 100.00% <100.00%> (ø) 8.00 <8.00> (?)
...kt/rules/style/LibraryCodeMustSpecifyReturnType.kt 87.50% <0.00%> (-12.50%) 12.00% <0.00%> (-4.00%)
...lab/arturbosch/detekt/rules/style/MaxLineLength.kt 79.41% <0.00%> (-5.89%) 22.00% <0.00%> (-1.00%)
...n/io/github/detekt/report/html/HtmlOutputReport.kt 94.28% <0.00%> (-0.46%) 18.00% <0.00%> (-2.00%)
...in/io/gitlab/arturbosch/detekt/rules/style/Junk.kt 100.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
...bosch/detekt/formatting/KtLintLineColCalculator.kt 88.09% <0.00%> (ø) 6.00% <0.00%> (?%)
...lab/arturbosch/detekt/formatting/FormattingRule.kt 96.42% <0.00%> (+0.13%) 11.00% <0.00%> (ø%)

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 cee6149...81d02e1. Read the comment docs.

Copy link
Member

@cortinico cortinico 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 your contrib @sowmyav24

Please clarify the documentation as the semantic is a bit unclear right now. The threshold applies to the whole number of parameters, and not just to the named parameters.

Copy link
Member

@cortinico cortinico 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
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 contribution! Please see my attached comments. I'm not sure whether there should be a bigger test coverage.

)

override fun visitCallExpression(expression: KtCallExpression) {
val valueArguments = expression.valueArguments
Copy link
Member

Choose a reason for hiding this comment

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

What happens when calling constructors? Shall a test be added?

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 rule gets triggered. Have added tests for them

@schalkms
Copy link
Member

@cortinico & @BraisGabin should this rule also report constructors or just functions? What's your take on this?

@BraisGabin
Copy link
Member

I think that it should report constructors. But maybe we could have two different threshold.

@cortinico
Copy link
Member

@cortinico & @BraisGabin should this rule also report constructors or just functions? What's your take on this?

Seems like it works also for ctors.

I think that it should report constructors. But maybe we could have two different threshold.

Don't have a strong opinion on this actually. Considered that the rule is not enabled by default, I'd be fine having a single threshold for now and adding another one in the future if needed.

@schalkms schalkms merged commit b6d298a into detekt:master Oct 26, 2020
@arturbosch arturbosch added this to the 1.15.0 milestone Nov 2, 2020
arturbosch pushed a commit that referenced this pull request Nov 15, 2020
* Introduce NamedArguments rule when function is invoked with more than default number of non-named parameters

* Change the documentation to make the intent of default threshold clear

* Add compliant and non-compliant code documentation. Add tests for constructor
arturbosch pushed a commit that referenced this pull request Dec 21, 2020
* Introduce NamedArguments rule when function is invoked with more than default number of non-named parameters

* Change the documentation to make the intent of default threshold clear

* Add compliant and non-compliant code documentation. Add tests for constructor
arturbosch pushed a commit that referenced this pull request Jan 16, 2021
* Introduce NamedArguments rule when function is invoked with more than default number of non-named parameters

* Change the documentation to make the intent of default threshold clear

* Add compliant and non-compliant code documentation. Add tests for constructor
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.

Suggestion: LongParameterList rule but on method call if named argument is not used
5 participants