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

Fix ReturnCount false positive when excludeReturnFromLambda is enabled #5459

Merged
merged 6 commits into from Oct 26, 2022

Conversation

sanggggg
Copy link
Contributor

@sanggggg sanggggg commented Oct 21, 2022

Fixes #5341

When excludeReturnFromLambda is enabled, then ignore every labeled return in lambda block.

There can be some extra cases like below, which may go against excludeReturnFromLambda's general purpose. (do not count return for lambda)

fun asdf() {
  kotlin.run {
    return@asdf // do not counted when if excludeReturnFromLambda is enabled.
  }
}

But for a clear definition of the excludeReturnFromLambda (if the labeled return from a lambda should be ignored), I excluded it.

@@ -65,7 +64,7 @@ class ReturnCount(config: Config = Config.empty) : Rule(config) {
@Configuration("if labeled return statements should be ignored")
private val excludeLabeled: Boolean by config(false)

@Configuration("if labeled return from a lambda should be ignored")
@Configuration("if labeled return from a lambda should be ignored (takes precedence over excludeLabeled.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@Configuration("if labeled return from a lambda should be ignored (takes precedence over excludeLabeled.")
@Configuration("if labeled return from a lambda should be ignored (takes precedence over excludeLabeled).")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, the configurations for excluding seem to be or conditions. (The added explanation is only making more confusion for the user). So I revert it.

1b806d8

Comment on lines 116 to 117
.none()
.not()
Copy link
Member

Choose a reason for hiding this comment

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

.none().not() is sort of confusing here. Can we rewrite with any or count() >= 1

Copy link
Member

Choose a reason for hiding this comment

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

.count() will unnecessarily materialize the sequence. .any() returns a Boolean and will only materialize at most one element of the sequence.

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be isNotEmpty?

Copy link
Member

Choose a reason for hiding this comment

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

it's a Sequence, isNotEmpty is only on Collections, because for a "sequence" emptiness doesn't mathematically make sense: "Unlike collections, sequences don't contain elements, they produce them."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BraisGabin BraisGabin added this to the 1.22.0 milestone Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReturnCount false positive on lambda returns
4 participants