Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a namespace matches multiple :ns-groups, only :config-in-ns rules for the first are applied #1945

Closed
camsaul opened this issue Jan 14, 2023 · 0 comments
Labels
Projects

Comments

@camsaul
Copy link
Contributor

camsaul commented Jan 14, 2023

version

clj-kondo v2022.12.10

platform

Native

problem

If a namespace matches multiple groups in :ns-groups, only rules for the first matching config for :config-in-ns are applied

repro

Here is a minimal repo.

File src/x/core.clj:

(ns x.core)

(defn x []
  (eval "WOW")
  (println "OK")
  (printf "NICE\n"))

Config version 1:

{:linters
 {:discouraged-var
  {clojure.core/eval {:message "Please don't eval stuff"}}}

 :ns-groups
 [{:pattern "^x\\.core.*$"
   :name    core-namespaces}
  {:pattern "^x\\..*$"
   :name    x-namespaces}]

 :config-in-ns
 {core-namespaces
  {:linters
   {:discouraged-var
    {clojure.core/println {:message "Use log"}}}}

  x-namespaces
  {:linters
   {:discouraged-var
    {clojure.core/printf {:message "Use logf"}}}}}}
$ clj-kondo --lint src/
src/x/core.clj:4:3: warning: Please don't eval stuff
src/x/core.clj:5:3: warning: Use log
linting took 4ms, errors: 0, warnings: 2

Config version 2:

{:linters
 {:discouraged-var
  {clojure.core/eval {:message "Please don't eval stuff"}}}

 :ns-groups
 [{:pattern "^x\\..*$"
   :name    x-namespaces}
  {:pattern "^x\\.core.*$"
   :name    core-namespaces}]

 :config-in-ns
 {core-namespaces
  {:linters
   {:discouraged-var
    {clojure.core/println {:message "Use log"}}}}

  x-namespaces
  {:linters
   {:discouraged-var
    {clojure.core/printf {:message "Use logf"}}}}}}
$ clj-kondo --lint src/
src/x/core.clj:4:3: warning: Please don't eval stuff
src/x/core.clj:6:3: warning: Use logf
linting took 4ms, errors: 0, warnings: 2

Note that neither version provides all three warnings I'd expect; depending on the order of the :ns-groups, we either get the Use log or Use logf warning, but never both

config

See above

expected behavior

The configs from all matching :config-in-ns should be merged together. Failing that, Kondo should issue a warning that a namespace matches multiple groups and it is not supported.

@borkdude borkdude added this to Needs triage in clj-kondo via automation Jan 15, 2023
@borkdude borkdude moved this from Needs triage to Medium priority (new / enhance) in clj-kondo Jan 15, 2023
@borkdude borkdude moved this from Medium priority (new / enhance) to High priority (next release) in clj-kondo Jan 20, 2023
@borkdude borkdude moved this from High priority (next release) to In progress in clj-kondo Jan 20, 2023
borkdude added a commit that referenced this issue Jan 20, 2023
borkdude added a commit that referenced this issue Jan 20, 2023
clj-kondo automation moved this from In progress to Done Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
clj-kondo
  
Done
Development

No branches or pull requests

2 participants