Repository: detekt/detekt (kotlin)

Issue:
NamedArguments: Exclude Lambdas
The rule or changes you're looking for might have already been suggested!
Please search in the [issues](https://github.com/detekt/detekt/issues) before creating a new one.

## Expected Behavior of the rule
<!-- Explain the rule or changes to existing rules you're suggesting. -->
<!-- Be as detailed as possible and also provide code samples for the code that the rules should flag. -->

When I configure the rule `NamedArguments` with threshold: 1 I start getting warnings for lambda functions as well
`Named arguments are required for function invocation with many parameters.`

```
require(n == 2) {
  "N is not 2"
}
```


## Context
<!--- What are you trying to accomplish with this rule/change? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world. -->
<!--- Please add links to official documentation or best practices such as code style guides if available. -->

Can we have a configuration to ignore lambdas?

Pull request description:
Fixes #4999

Patch:
diff --git a/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArguments.kt b/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArguments.kt
index a6222ece6ee3..2fc021d9fe26 100644
--- a/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArguments.kt
+++ b/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArguments.kt
@@ -42,7 +42,7 @@ class NamedArguments(config: Config = Config.empty) : Rule(config) {
         Debt.FIVE_MINS
     )
 
-    @Configuration("number of parameters that triggers this inspection")
+    @Configuration("number of arguments that triggers this inspection")
     private val threshold: Int by config(defaultValue = 3)
 
     @Configuration("ignores when argument values are the same as the parameter names")
@@ -50,7 +50,7 @@ class NamedArguments(config: Config = Config.empty) : Rule(config) {
 
     override fun visitCallExpression(expression: KtCallExpression) {
         if (bindingContext == BindingContext.EMPTY) return
-        val valueArguments = expression.valueArguments
+        val valueArguments = expression.valueArguments.filterNot { it is KtLambdaArgument }
         if (valueArguments.size > threshold && expression.canNameArguments()) {
             val message = "This function call has ${valueArguments.size} arguments. To call a function with more " +
                 "than $threshold arguments you should set the name of each argument."


Test patch:
diff --git a/detekt-rules-complexity/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArgumentsSpec.kt b/detekt-rules-complexity/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArgumentsSpec.kt
index f3039cda62a4..b077cca74f05 100644
--- a/detekt-rules-complexity/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArgumentsSpec.kt
+++ b/detekt-rules-complexity/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/NamedArgumentsSpec.kt
@@ -196,6 +196,18 @@ class NamedArgumentsSpec(val env: KotlinCoreEnvironment) {
             val findings = subject.compileAndLintWithContext(env, code)
             assertThat(findings).hasSize(1)
         }
+
+        @Test
+        fun `does not count lambda argument`() {
+            val code = """
+            fun test(n: Int) {
+                require(n == 2) { "N is not 2" }
+            }
+        """
+            val subject = NamedArguments(TestConfig(mapOf("threshold" to 1)))
+            val findings = subject.compileAndLintWithContext(env, code)
+            assertThat(findings).hasSize(0)
+        }
     }
 
     @Nested