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

Ignore actual functions in FunctionOnlyReturningConstant (#3388) #3390

Conversation

sczerwinski
Copy link
Contributor

@sczerwinski sczerwinski commented Jan 19, 2021

Closes #3388

Expected Behavior of the rule

By default, actual functions in multiplatform projects should be ignored when evaluating FunctionOnlyReturningConstant.

There should be a configuration option ignoreActualFunction, which would allow changing this behaviour.

Example

commonMain

expect class Foo {
    fun foo(param: Any): Boolean
}

jvmMain

actual class Foo {
    actual fun foo(param: Any): Boolean = checkSomeCondition(param)
}

jsMain

actual class Foo {
    actual fun foo(param: Any): Boolean = false    // <-- FunctionOnlyReturningConstant should be ignored
}

Context

Similar to ignoreOverridableFunction.

Implementing an actual function, is conceptually similar to overriding a function from an interface/abstract class.
It makes sense for such a function to provide complex logic on some platforms, and only return a constant value on others.

@codecov
Copy link

codecov bot commented Jan 19, 2021

Codecov Report

Merging #3390 (c66c7f2) into master (a7efff2) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3390      +/-   ##
============================================
- Coverage     80.46%   80.40%   -0.06%     
- Complexity     2739     2745       +6     
============================================
  Files           448      448              
  Lines          8282     8279       -3     
  Branches       1573     1582       +9     
============================================
- Hits           6664     6657       -7     
+ Misses          771      767       -4     
- Partials        847      855       +8     
Impacted Files Coverage Δ Complexity Δ
...o/gitlab/arturbosch/detekt/rules/KtModifierList.kt 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
...etekt/rules/style/FunctionOnlyReturningConstant.kt 97.29% <100.00%> (+0.42%) 34.00 <10.00> (+6.00)
...t/rules/coroutines/SuspendFunWithFlowReturnType.kt 71.42% <0.00%> (-14.29%) 7.00% <0.00%> (ø%)
...n/io/gitlab/arturbosch/detekt/core/DetektResult.kt 90.00% <0.00%> (-10.00%) 7.00% <0.00%> (ø%)
...ain/kotlin/io/github/detekt/metrics/LinesOfCode.kt 93.10% <0.00%> (-6.90%) 0.00% <0.00%> (ø%)
...b/arturbosch/detekt/rules/complexity/LargeClass.kt 91.17% <0.00%> (-5.89%) 12.00% <0.00%> (ø%)
...b/arturbosch/detekt/rules/complexity/LongMethod.kt 84.09% <0.00%> (-4.55%) 16.00% <0.00%> (ø%)
...o/gitlab/arturbosch/detekt/invoke/DetektInvoker.kt 48.38% <0.00%> (-1.62%) 0.00% <0.00%> (ø%)
...n/io/github/detekt/report/sarif/RuleDescriptors.kt 20.00% <0.00%> (-1.06%) 0.00% <0.00%> (ø%)
...ain/kotlin/io/gitlab/arturbosch/detekt/api/Rule.kt 82.60% <0.00%> (ø) 16.00% <0.00%> (ø%)
... and 26 more

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 a7efff2...c66c7f2. Read the comment docs.

@@ -6,7 +6,7 @@ on:
- master
pull_request:
branches:
- '*'
- '**'
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for fixing the glob pattern in github workflows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to help. The difference between * and ** is well hidden in GitHub Actions documentation. Took me some time to figure out the first time.

Copy link
Member

Choose a reason for hiding this comment

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

I learned Filter Pattern Cheat Sheet by reviewing this PR 🙏

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!

@schalkms schalkms merged commit 1164c34 into detekt:master Jan 19, 2021
@sczerwinski sczerwinski deleted the FunctionOnlyReturningConstant/ignoreActualFunction branch January 20, 2021 00:04
@cortinico cortinico added this to the 1.16.0 milestone Feb 19, 2021
This was referenced Mar 11, 2021
This was referenced Mar 11, 2021
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.

FunctionOnlyReturningConstant should ignore actual functions
4 participants