diff --git a/src/clj_kondo/impl/config.clj b/src/clj_kondo/impl/config.clj index 91bb9d8e44..7bd1ff6d95 100644 --- a/src/clj_kondo/impl/config.clj +++ b/src/clj_kondo/impl/config.clj @@ -107,6 +107,7 @@ :unused-import {:level :warning} :single-operand-comparison {:level :warning} :single-logical-operand {:level :warning} + :redundant-nesting {:level :warning} :single-key-in {:level :off} :missing-clause-in-try {:level :warning} :missing-body-in-when {:level :warning} diff --git a/src/clj_kondo/impl/core.clj b/src/clj_kondo/impl/core.clj index 6064dce211..c4f9b27c94 100644 --- a/src/clj_kondo/impl/core.clj +++ b/src/clj_kondo/impl/core.clj @@ -658,7 +658,8 @@ (and (not= :redundant-do type) (not= :redundant-call type) (not= :redundant-let type) - (not= :single-logical-operand type)) + (not= :single-logical-operand type) + (not= :redundant-nesting type)) ;; but if we get here, then the amount of findings has to be bigger than 1 (> (count findings) 1)) f (collapse-cljc-findings findings) diff --git a/src/clj_kondo/impl/linters.clj b/src/clj_kondo/impl/linters.clj index 84a114284b..16dcf81c3c 100644 --- a/src/clj_kondo/impl/linters.clj +++ b/src/clj_kondo/impl/linters.clj @@ -207,6 +207,20 @@ :single-logical-operand (format "Single arg use of %s always returns the arg itself" call-name)))))) +(defn lint-redundant-nesting + "Lints calls of variadic functions/macros when nested." + [call] + (let [[[call-ns call-name] parent] (:callstack call)] + (when (and (utils/one-of call-ns [clojure.core cljs.core]) + (utils/one-of call-name [* *' + +' and comp concat every-pred + lazy-cat max merge min or some-fn str]) + (= [call-ns call-name] parent)) + (node->line + (:filename call) + (:expr call) + :redundant-nesting + (format "Nested use of %s is redunant" call-name) )))) + #_(require 'clojure.pprint) (defn lint-var-usage @@ -394,7 +408,11 @@ single-logical-operand-error (and call? (not (utils/linter-disabled? call :single-logical-operand)) - (lint-single-logical-operand call))]] + (lint-single-logical-operand call)) + redundant-nesting-error + (and call? + (not (utils/linter-disabled? call :redundant-nesting)) + (lint-redundant-nesting call))]] (when (and (not call?) (identical? :fn (:type called-fn))) (when (:condition call) @@ -415,6 +433,9 @@ (when single-logical-operand-error (findings/reg-finding! ctx single-logical-operand-error)) + (when redundant-nesting-error + (findings/reg-finding! ctx + redundant-nesting-error)) (when (and (:private called-fn) (not= caller-ns-sym fn-ns)