Skip to content

Commit

Permalink
Fix clj-kondo#2154: :exclude option for :deprecated-namespace option (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored and lambdank committed Sep 6, 2023
1 parent 1c1189e commit 5afba85
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ For a list of breaking changes, check [here](#breaking-changes).
- [#2170](https://github.com/clj-kondo/clj-kondo/issues/2170): `:keyword-binding` linter should ignore auto-resolved keywords
- [#2172](https://github.com/clj-kondo/clj-kondo/issues/2172): detect invalid amount of args and invalid argument type for `throw`
- [#2164](https://github.com/clj-kondo/clj-kondo/issues/2164): deftest inside let triggers :unused-value
- #2154: add `:exclude` option to `:deprecated-namespace` linter

## 2023.07.13

Expand Down
8 changes: 8 additions & 0 deletions doc/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ A regex is also permitted, e.g. to exclude all test namespaces:

Example warning: `Namespace foo is deprecated.`.

*Config:*

To exclude warnings about specific namespaces, use:

``` clojure
{:linters {:deprecated-namespace {:exclude [the-deprecated.namespace]}}}
```

### Deps.edn

*Keyword:* `:deps.edn`
Expand Down
8 changes: 8 additions & 0 deletions src/clj_kondo/impl/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,14 @@
x))
coll))

(let [delayed-config (fn [config]
(let [excluded (get-in config [:linters :deprecated-namespace :exclude])]
(set excluded)))
delayed-cfg (memoize delayed-config)]
(defn deprecated-namespace-excluded? [config required]
(let [cfg (delayed-cfg config)]
(contains? cfg required))))

;; (defn ns-group-1 [m full-ns-name]
;; (when-let [r (:regex m)]
;; (if (re-matches (re-pattern r) (str full-ns-name))
Expand Down
19 changes: 10 additions & 9 deletions src/clj_kondo/impl/linters.clj
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,16 @@
ctx (assoc ctx :lang (:lang ns) :base-lang (:base-lang ns))]]
(doseq [required required]
(when-let [depr (:deprecated (utils/resolve-ns idacs (:base-lang ns) (:lang ns) required))]
(let [filename (:filename (meta required))]
(findings/reg-finding!
ctx
(node->line filename required :deprecated-namespace
(format "Namespace %s is deprecated%s."
(str required)
(if (string? depr)
(str " since " depr)
"")))))))
(when-not (config/deprecated-namespace-excluded? config required)
(let [filename (:filename (meta required))]
(findings/reg-finding!
ctx
(node->line filename required :deprecated-namespace
(format "Namespace %s is deprecated%s."
(str required)
(if (string? depr)
(str " since " depr)
""))))))))
(doseq [ns-sym unused]
(let [ns-meta (meta ns-sym)]
(when-not (or (config/unused-namespace-excluded config ns-sym)
Expand Down
5 changes: 4 additions & 1 deletion test/clj_kondo/main_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,10 @@ foo"))))

(deftest deprecated-namespace-test
(assert-submaps '({:file "<stdin>", :row 1, :col 58, :level :warning, :message "Namespace foo is deprecated."})
(lint! "(ns foo {:deprecated true}) (def x 1) (ns bar (:require [foo]))")))
(lint! "(ns foo {:deprecated true}) (def x 1) (ns bar (:require [foo]))"))
(is (empty?
(lint! "(ns foo {:deprecated true}) (def x 1) (ns bar (:require [foo]))"
'{:linters {:deprecated-namespace {:exclude [foo]}}}))))

(deftest unused-referred-var-test
(assert-submaps
Expand Down

0 comments on commit 5afba85

Please sign in to comment.