diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ad40f445e..6cabcbdbb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ For a list of breaking changes, check [here](#breaking-changes). ## Unreleased +- [#2272](https://github.com/clj-kondo/clj-kondo/issues/2272): Report var usage in `if-let` etc condition as always truthy - [#2272](https://github.com/clj-kondo/clj-kondo/issues/2272): Report var usage in `if-not` condition as always truthy - [#2433](https://github.com/clj-kondo/clj-kondo/issues/2433): false positive redundant ignore with hook - Document `:cljc` config option. ([@NoahTheDuke](https://github.com/NoahTheDuke)) diff --git a/src/clj_kondo/impl/analyzer.clj b/src/clj_kondo/impl/analyzer.clj index cc3acc133d..557c6b2d8f 100644 --- a/src/clj_kondo/impl/analyzer.clj +++ b/src/clj_kondo/impl/analyzer.clj @@ -958,7 +958,8 @@ :analyzed))] (lint-two-forms-binding-vector! ctx call bv) (concat (:analyzed bindings) - (analyze-expression** (update ctx :callstack conj [:vector]) condition) + (analyze-expression** (update ctx :callstack conj [:vector]) + (assoc condition :condition true)) (if if? ;; in the case of if, the binding is only valid in the first expression (concat diff --git a/test/clj_kondo/condition_always_true_test.clj b/test/clj_kondo/condition_always_true_test.clj index ce5f08fcdd..108a768a61 100644 --- a/test/clj_kondo/condition_always_true_test.clj +++ b/test/clj_kondo/condition_always_true_test.clj @@ -32,4 +32,12 @@ :level :warning, :message "Condition always true"}] (lint! "(if-not odd? 1 2)" + '{:linters {:condition-always-true {:level :warning}}})) + (assert-submaps2 + [{:file "", + :row 1, + :col 12, + :level :warning, + :message "Condition always true"}] + (lint! "(if-let [a odd?] 1 2)" '{:linters {:condition-always-true {:level :warning}}})))