Skip to content

Add allowOmitUnit to rule LibraryCodeMustSpecifyReturnType#5861

Merged
cortinico merged 2 commits into
detekt:mainfrom
atulgpt:fixes-5692
Apr 10, 2023
Merged

Add allowOmitUnit to rule LibraryCodeMustSpecifyReturnType#5861
cortinico merged 2 commits into
detekt:mainfrom
atulgpt:fixes-5692

Conversation

@atulgpt
Copy link
Copy Markdown
Contributor

@atulgpt atulgpt commented Feb 27, 2023

Fixes #5692

Comment on lines +132 to +149
@ParameterizedTest(
name = "does not report for implicit type Unit expression when allowOmitUnit is {0}",
)
@ValueSource(booleans = [true, false])
fun `does not report for Unit expression`(allowOmitUnit: Boolean) {
val code = """
fun foo() = Unit
""".trimIndent()
val subject = ExplicitlyDefineReturn(
TestConfig(
ALLOW_OMIT_UNIT to allowOmitUnit
)
)
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings).isEmpty()
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this case be reported unit is not allowed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I carried this from previous issues reported at #4004

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 28, 2023

Codecov Report

Merging #5861 (dd3399d) into main (0818691) will increase coverage by 0.11%.
The diff coverage is 70.00%.

@@             Coverage Diff              @@
##               main    #5861      +/-   ##
============================================
+ Coverage     84.55%   84.66%   +0.11%     
- Complexity     3786     3836      +50     
============================================
  Files           546      549       +3     
  Lines         12933    13065     +132     
  Branches       2274     2305      +31     
============================================
+ Hits          10935    11061     +126     
- Misses          863      868       +5     
- Partials       1135     1136       +1     
Impacted Files Coverage Δ
.../gitlab/arturbosch/detekt/rules/MethodSignature.kt 72.00% <0.00%> (-3.00%) ⬇️
...tekt/libraries/LibraryCodeMustSpecifyReturnType.kt 90.00% <71.42%> (-3.94%) ⬇️
.../io/gitlab/arturbosch/detekt/rules/KtExpression.kt 100.00% <100.00%> (ø)
...rbosch/detekt/rules/bugs/ImplicitUnitReturnType.kt 96.42% <100.00%> (+3.09%) ⬆️

... and 29 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

*
*/
@RequiresTypeResolution
class ExplicitlyDefineReturn(config: Config = Config.empty) : Rule(config) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How is this rule different from LibraryCodeMustSpecifyReturnType?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @cortinico, only one diff that I could find out(in the current impl of LibraryCodeMustSpecifyReturnType) is that it only checks for public API.
If we can add allowOmitUnit and remove Library from the rule the it will be more general. cc @BraisGabin for his inputs as well

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we can add allowOmitUnit

Totally

and remove Library from the rule the it will be more general. cc @BraisGabin for his inputs as well

Maybe here we can add an alias?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good call @cortinico. I didn't know that we have this already implemented.

I'm ok about adding allowOmitUnit there. But I'm not sure if it's worth to rename the rule at all. That would force the current users to rename it from their config file. And the improvement is not big enought.

@cortinico
Copy link
Copy Markdown
Member

What's the agreement here?

@atulgpt
Copy link
Copy Markdown
Contributor Author

atulgpt commented Apr 8, 2023

Hi @cortinico we(me and @BraisGabin) decided to add allowOmitUnit to the existing LibraryCodeMustSpecifyReturnType rule

@atulgpt
Copy link
Copy Markdown
Contributor Author

atulgpt commented Apr 8, 2023

Hi @cortinico we(me and @BraisGabin) decided to add allowOmitUnit to the existing LibraryCodeMustSpecifyReturnType rule

Hi @cortinico / @BraisGabin I have added the allowOmitUnit in the LibraryCodeMustSpecifyReturnType rule.

@cortinico cortinico changed the title Implement ExplicitlyDefineReturn rule Add allowOmitUnit to rule LibraryCodeMustSpecifyReturnType Apr 9, 2023
@cortinico cortinico added this to the 1.23.0 milestone Apr 9, 2023
@cortinico cortinico merged commit b925968 into detekt:main Apr 10, 2023
@atulgpt atulgpt deleted the fixes-5692 branch April 10, 2023 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExplicitlyDefineReturn

3 participants