mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
fix for KtNamedFunction.isMainFunction() (#3641)
* fix for KtNamedFunction.isMainFunction()
This commit is contained in:
committed by
GitHub
parent
ed1ee8f15e
commit
90d5efc0f1
@@ -223,6 +223,7 @@ If you contributed to detekt but your name is not in the list, please feel free
|
||||
- [Adam Kobor](https://github.com/adamkobor) - New rule: MultilineLambdaItParameter
|
||||
- [Slawomir Czerwinski](https://github.com/sczerwinski) - Rule improvement: FunctionOnlyReturningConstant
|
||||
- [Ivo Smid](https://github.com/bedla) - Fix Local development on Windows
|
||||
- [Krzysztof Kruczynski](https://github.com/krzykrucz) - Rule fix: ThrowingExceptionInMain, ExitOutsideMain
|
||||
|
||||
### Mentions
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ private fun KtNamedFunction.hasMainSignature() =
|
||||
this.name == "main" && this.isPublicNotOverridden() && this.hasMainParameter()
|
||||
|
||||
private fun KtNamedFunction.hasMainParameter() =
|
||||
valueParameters.isEmpty() || valueParameters.size == 1 && valueParameters[0].typeReference?.text == "Array<String>"
|
||||
valueParameters.isEmpty() ||
|
||||
(valueParameters.size == 1 && valueParameters[0].typeReference?.text == "Array<String>") ||
|
||||
(valueParameters.size == 1 && valueParameters[0].isVarArg && valueParameters[0].typeReference?.text == "String")
|
||||
|
||||
private fun KtNamedFunction.isMainInsideObject() =
|
||||
this.name == "main" &&
|
||||
|
||||
@@ -14,9 +14,10 @@ class ThrowingExceptionInMainSpec : Spek({
|
||||
it("reports a runnable main function which throws an exception") {
|
||||
val code = """
|
||||
fun main(args: Array<String>) { throw IllegalArgumentException() }
|
||||
fun main(vararg args: String) { throw IllegalArgumentException() }
|
||||
fun main() { throw IllegalArgumentException() }
|
||||
"""
|
||||
assertThat(subject.compileAndLint(code)).hasSize(2)
|
||||
assertThat(subject.compileAndLint(code)).hasSize(3)
|
||||
}
|
||||
|
||||
it("reports runnable main functions with @JvmStatic annotation which throw an exception") {
|
||||
|
||||
Reference in New Issue
Block a user