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

Fix :include-macros error in cljc and cljs #1834

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ For a list of breaking changes, check [here](#breaking-changes).
## Unreleased

- [#1831](https://github.com/clj-kondo/clj-kondo/issues/1831): Add `:redundant-fn-wrapper` support for keyword and binding calls ([@NoahTheDuke](https://github.com/NoahTheDuke))
- [#1830](https://github.com/clj-kondo/clj-kondo/issues/1830): Fix warning on `:include-macros` in cljs and cljc. Make `:unknown-require-option` default to `:off`. ([@NoahTheDuke](https://github.com/NoahTheDuke))

...

Expand Down
21 changes: 21 additions & 0 deletions src/clj_kondo/impl/analyzer/namespace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@
(update :excluded into (set (keys opt)))
;; for :refer it is sufficient to pretend they were never referred
(update :referred set/difference (set (keys opt))))))
:include-macros
(do
(if (#{:cljc :cljs} base-lang)
(when-not (true? opt)
(findings/reg-finding!
ctx
(node->line
filename
child-expr
:syntax
"Require form is invalid: :invalid-macros only accepts true")))
(findings/reg-finding!
ctx
(node->line
filename
child-expr
:unknown-require-option
(format "Unknown require option: %s"
child-k))))
(recur (nnext children)
m))
(do (findings/reg-finding!
ctx
(node->line
Expand Down
2 changes: 1 addition & 1 deletion src/clj_kondo/impl/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
:datalog-syntax {:level :error}
:unbound-destructuring-default {:level :warning}
:used-underscored-binding {:level :off}
:unknown-require-option {:level :warning}
:unknown-require-option {:level :off}
:unused-binding {:level :warning
:exclude-destructured-keys-in-fn-args false
:exclude-destructured-as false
Expand Down
64 changes: 53 additions & 11 deletions test/clj_kondo/unknown_require_option_test.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
(ns clj-kondo.unknown-require-option-test
(:require [clj-kondo.test-utils :refer [lint!]]
(:require [clj-kondo.test-utils :refer [lint! assert-submaps]]
[clojure.test :refer [deftest is]]))

(deftest unknown-require-option-test
(is (= '({:file "<stdin>",
:row 1,
:col 24,
:level :warning,
:message "Unknown require option: :s"})
(lint! "(ns foo (:require [bar :s b]))"
{:linters {:unknown-require-option {:level :warning}}}))))
(assert-submaps
'({:file "<stdin>",
:row 1,
:col 24,
:level :warning,
:message "Unknown require option: :s"})
(lint! "(ns foo (:require [bar :s b]))"
{:linters {:unknown-require-option {:level :warning}}})))

(deftest ignorable-test
(is (= '()
(lint! "(ns foo (:require #_:clj-kondo/ignore [bar :s b]))"
{:linters {:unknown-require-option {:level :warning}}}))))
(is (empty?
(lint! "(ns foo (:require #_:clj-kondo/ignore [bar :s b]))"
{:linters {:unknown-require-option {:level :warning}}}))))

(deftest include-macros-cljs-test
(is (empty?
(lint! "(ns foo (:require [bar :include-macros true]))"
{:linters {:unknown-require-option {:level :warning}}}
"--lang" "cljs")))
(assert-submaps
'({:file "<stdin>",
:row 1,
:col 24,
:level :error,
:message "Require form is invalid: :invalid-macros only accepts true"})
(lint! "(ns foo (:require [bar :include-macros :s]))"
{:linters {:unknown-require-option {:level :warning}}}
"--lang" "cljs")))

(deftest include-macro-clojure-test
(assert-submaps
'({:file "<stdin>",
:row 1,
:col 24,
:level :warning,
:message "Unknown require option: :include-macros"})
(lint! "(ns foo (:require [bar :include-macros true]))"
{:linters {:unknown-require-option {:level :warning}}}
"--lang" "clj")))

(deftest include-macros-cljc-test
(is (empty?
(lint! "(ns foo (:require [bar :include-macros true]))"
{:linters {:unknown-require-option {:level :warning}}}
"--lang" "cljc")))
(assert-submaps
'({:file "<stdin>",
:row 1,
:col 24,
:level :error,
:message "Require form is invalid: :invalid-macros only accepts true"})
(lint! "(ns foo (:require [bar :include-macros :s]))"
{:linters {:unknown-require-option {:level :warning}}}
"--lang" "cljc")))