-
-
Notifications
You must be signed in to change notification settings - Fork 797
Fix rule LibraryCodeMustSpecifyReturnType #3155
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
Conversation
False positive: Members without visibility modifiers in an internal class should not be reported. False negative: Members with protected modifiers in a public class should be reported.
Note that there is an error at LibraryCodeMustSpecifyReturnTypeSpec:99 Please let me know if this is okay to ignore.
|
Codecov Report
@@ Coverage Diff @@
## master #3155 +/- ##
============================================
- Coverage 79.52% 79.49% -0.03%
- Complexity 2592 2595 +3
============================================
Files 437 437
Lines 7852 7876 +24
Branches 1495 1500 +5
============================================
+ Hits 6244 6261 +17
- Misses 817 819 +2
- Partials 791 796 +5
Continue to review full report at Codecov.
|
Hi, thanks for the PR, it looks good. fun BaseRule.lintWithContext(
environment: KotlinCoreEnvironment,
@Language("kotlin") content: String,
@Language("kotlin") vararg additionalContents: String,
): List<Finding> {
val ktFile = compileContentForTest(content.trimIndent())
val additionalKtFiles = additionalContents.mapIndexed { index, additionalContent ->
compileContentForTest(additionalContent.trimIndent(), "AdditionalTest$index.kt")
}
val bindingContext = getContextForPaths(environment, listOf(ktFile) + additionalKtFiles)
val languageVersionSettings = environment.configuration.languageVersionSettings
@Suppress("DEPRECATION")
val dataFlowValueFactory = DataFlowValueFactoryImpl(languageVersionSettings)
val compilerResources = CompilerResources(languageVersionSettings, dataFlowValueFactory)
return findingsAfterVisit(ktFile, bindingContext, compilerResources)
}
fun BaseRule.compileAndLintWithContext(
environment: KotlinCoreEnvironment,
@Language("kotlin") content: String,
@Language("kotlin") vararg additionalContents: String,
): List<Finding> {
if (shouldCompileTestSnippets && additionalContents.isEmpty()) {
KotlinScriptEngine.compile(content)
}
return lintWithContext(environment, content, *additionalContents)
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
That is a great suggestion! I have made the changes and all the checks passed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add @requiresTypeResolution
to the documentation?
.../test/kotlin/io/gitlab/arturbosch/detekt/rules/style/LibraryCodeMustSpecifyReturnTypeSpec.kt
Show resolved
Hide resolved
Were you referring to create a new @OptIn annotation class? |
.../src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/LibraryCodeMustSpecifyReturnType.kt
Show resolved
Hide resolved
.../src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/LibraryCodeMustSpecifyReturnType.kt
Show resolved
Hide resolved
detekt-test/src/main/kotlin/io/gitlab/arturbosch/detekt/test/RuleExtensions.kt
Show resolved
Hide resolved
* Fix rule LibraryCodeMustSpecifyReturnType False positive: Members without visibility modifiers in an internal class should not be reported. False negative: Members with protected modifiers in a public class should be reported. * Create BaseRule.lintWithContext to skip KotlinScriptEngine compilation * Add comment back * Add @requiresTypeResolution and binding context check * Complete the javadoc and build
* Fix rule LibraryCodeMustSpecifyReturnType False positive: Members without visibility modifiers in an internal class should not be reported. False negative: Members with protected modifiers in a public class should be reported. * Create BaseRule.lintWithContext to skip KotlinScriptEngine compilation * Add comment back * Add @requiresTypeResolution and binding context check * Complete the javadoc and build
* Fix rule LibraryCodeMustSpecifyReturnType False positive: Members without visibility modifiers in an internal class should not be reported. False negative: Members with protected modifiers in a public class should be reported. * Create BaseRule.lintWithContext to skip KotlinScriptEngine compilation * Add comment back * Add @requiresTypeResolution and binding context check * Complete the javadoc and build
False-positive: Members without visibility modifiers in an internal class should not be reported.
False-negative: Members with protected modifiers in a public class should be reported.
This PR changes the underlying implementation of LibraryCodeMustSpecifyReturnType to Kotlin Compiler's explicit API mode, which was introduced in Kotlin 1.4
See https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors
This is actually blocking my company's repositories to enable
LibraryCodeMustSpecifyReturnType
rule because of tons of false positives.