Skip to content

Commit

Permalink
Include if-let etc in :condition-always-true linter (clj-kondo#2441)
Browse files Browse the repository at this point in the history
Include if-let, when-let, if-some, when-some, when-first

Adds to functionality of clj-kondo#2272

Co-authored-by: Michiel Borkent <michielborkent@gmail.com>
  • Loading branch information
tomdl89 and borkdude authored Nov 28, 2024
1 parent e439bfd commit 340ad50
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion src/clj_kondo/impl/analyzer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/clj_kondo/condition_always_true_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<stdin>",
:row 1,
:col 12,
:level :warning,
:message "Condition always true"}]
(lint! "(if-let [a odd?] 1 2)"
'{:linters {:condition-always-true {:level :warning}}})))

0 comments on commit 340ad50

Please sign in to comment.