From e8f0a6f448ae316e92564dccbe3cb892cc87ab47 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 1 Nov 2024 15:46:52 +0100 Subject: [PATCH] Fix #1786: support gen-interface (#2418) * Add test * Fix #1786: support gen-interface --- CHANGELOG.md | 1 + src/clj_kondo/impl/analyzer.clj | 7 +++++++ test/clj_kondo/main_test.clj | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aef4c4786..a8880b5fc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ For a list of breaking changes, check [here](#breaking-changes). - [#1784](https://github.com/clj-kondo/clj-kondo/issues/1784): detect `:redundant-do` in `catch` - [#2410](https://github.com/clj-kondo/clj-kondo/issues/2410): add `--report-level` flag - [#2416](https://github.com/clj-kondo/clj-kondo/issues/2416): detect empty `require` and `:require` forms ([@NoahTheDuke](https://github.com/NoahTheDuke)) +- [#1786](https://github.com/clj-kondo/clj-kondo/issues/1786): Support `gen-interface` (by suppressing unresolved symbols) ## 2024.09.27 diff --git a/src/clj_kondo/impl/analyzer.clj b/src/clj_kondo/impl/analyzer.clj index bd8a707583..f87ddf221d 100644 --- a/src/clj_kondo/impl/analyzer.clj +++ b/src/clj_kondo/impl/analyzer.clj @@ -2062,6 +2062,12 @@ (swap! (:namespaces ctx) assoc-in [base-lang lang current-ns :gen-class] true) nil) +(defn analyze-gen-interface [ctx expr] + ;; for now we just ignore the form to not cause false positives + ;; we can add more sophisticated linting, e.g. causing -init to be used + (let [ctx (utils/ctx-with-linter-disabled ctx :unresolved-symbol)] + (analyze-children ctx expr))) + (defn analyze-extend-type-children "Used for analyzing children of extend-protocol, extend-type, reify and specify! " [ctx children defined-by defined-by->lint-as] @@ -2484,6 +2490,7 @@ (analyze-hof ctx expr resolved-as-name resolved-namespace resolved-name) (ns-unmap) (analyze-ns-unmap ctx base-lang lang ns-name expr) (gen-class) (analyze-gen-class ctx expr base-lang lang ns-name) + (gen-interface) (analyze-gen-interface ctx expr) (exists?) (analyze-cljs-exists? ctx expr) (with-precision) (analyze-with-precision ctx expr children) (var) (analyze-var ctx expr children) diff --git a/test/clj_kondo/main_test.clj b/test/clj_kondo/main_test.clj index bc1bc48c2c..904928ecf1 100644 --- a/test/clj_kondo/main_test.clj +++ b/test/clj_kondo/main_test.clj @@ -1969,7 +1969,12 @@ foo/foo ;; this does use the private var {:linters {:unresolved-symbol {:level :error}}} "--lang" "cljs"))) (is (empty? (lint! "(def Vec 1)" - {:linters {:redefined-var {:level :error}}})))) + {:linters {:redefined-var {:level :error}}}))) + (is (empty? (lint! "(ns a.b.c) +(gen-interface + :name a.b.c.Foo + :methods [[bar [String] Object]])" + {:linters {:unresolved-symbol {:level :error}}})))) (deftest tagged-literal-test (is (empty?