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 RedundantHigherOrderMapUsage rule #3182

Merged
merged 3 commits into from
Oct 29, 2020
Merged

Conversation

t-kameyama
Copy link
Contributor

Fixes #2975

@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #3182 into master will decrease coverage by 0.04%.
The diff coverage is 72.91%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3182      +/-   ##
============================================
- Coverage     79.58%   79.53%   -0.05%     
- Complexity     2603     2631      +28     
============================================
  Files           439      440       +1     
  Lines          7919     7966      +47     
  Branches       1502     1521      +19     
============================================
+ Hits           6302     6336      +34     
  Misses          820      820              
- Partials        797      810      +13     
Impacted Files Coverage Δ Complexity Δ
...detekt/rules/style/RedundantHigherOrderMapUsage.kt 71.73% <71.73%> (ø) 28.00 <28.00> (?)
...rturbosch/detekt/rules/style/StyleGuideProvider.kt 100.00% <100.00%> (ø) 3.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 e2bd8ad...c8e57dd. Read the comment docs.

Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

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

I really like this rule. The tests are really good and you are checking a lot of edge cases. Great work 👏.

assertThat(findings).hasSize(1)
assertThat(findings).hasSourceLocation(5, 10)
assertThat(findings[0]).hasMessage("This 'map' call can be replaced with 'onEach' or 'forEach'.")
}
Copy link
Member

Choose a reason for hiding this comment

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

This! 👏👏👏👏👏 I saw it SO MANY TIMES! A map that should be replaced with an onEach. And it slow down the reading of the code a lot.

import org.jetbrains.kotlin.types.KotlinType

/**
* Turn on this rule to flag redundant 'map' calls.
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 change the description with something like:

Redundant maps add complexity to the code and accomplish nothing. They should be removed or replaced with the proper operator.

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.

Great addition 👍

Comment on lines 100 to 108
val message = if (lambdaStatements.size == 1) {
if (receiverIsSet) {
"This 'map' call can be replaced with 'toList'."
} else {
"This 'map' call can be removed."
}
} else {
"This 'map' call can be replaced with 'onEach' or 'forEach'."
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you convert this to a when?

@schalkms schalkms merged commit 7b0d944 into detekt:master Oct 29, 2020
@t-kameyama t-kameyama deleted the issue_2975 branch October 29, 2020 18:09
@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
* Add RedundantHigherOrderMapUsage rule

* Fix description

* Convert `if` to `when`
arturbosch pushed a commit that referenced this pull request Dec 21, 2020
* Add RedundantHigherOrderMapUsage rule

* Fix description

* Convert `if` to `when`
arturbosch pushed a commit that referenced this pull request Jan 16, 2021
* Add RedundantHigherOrderMapUsage rule

* Fix description

* Convert `if` to `when`
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.

Map { it } must return an error
5 participants