Skip to content

Fix kondo hook dropping handler opts map from analysis#15

Merged
cjbarre merged 1 commit into
ObneyAI:mainfrom
bpringe:fix/kondo-hook-opts-map-analysis
Jun 23, 2026
Merged

Fix kondo hook dropping handler opts map from analysis#15
cjbarre merged 1 commit into
ObneyAI:mainfrom
bpringe:fix/kondo-hook-opts-map-analysis

Conversation

@bpringe

@bpringe bpringe commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #16

Problem

The def-handler-macro clj-kondo hook captures the optional opts map (?opts) that handler macros accept between the name and the arg vector, but never emits it into the synthetic defn. As a result, any var referenced only inside an opts map — e.g. {:authorized? my-ns/authenticated?} on a defcommand — is invisible to clj-kondo, so clojure-lsp reports it as an unused public var.

Fix

Emit ?opts as the first body form of the generated defn so its symbols get resolved:

 (concat
   (when ?docstring [?docstring])
   [args-node]
+  (when ?opts [?opts])
   body)

Affects all five handler macros that share the helper: defcommand, defquery, defreadmodel, defprocessor, defperiodic.

Verification

With the fix applied, a predicate referenced only in a defcommand opts map (e.g. {:authorized? auth/authenticated?}) is now recorded in clj-kondo's var-usages analysis, and clojure-lsp no longer flags the var as unused.

🤖 Generated with Claude Code

The def-handler-macro clj-kondo hook captured the optional opts map
(?opts) that handler macros accept between the name and the arg vector,
but never emitted it into the synthetic defn. As a result, any var
referenced only inside an opts map (e.g. {:authorized? my-ns/foo} on a
defcommand) was invisible to clj-kondo, so clojure-lsp reported it as an
unused public var.

Emit ?opts as the first body form of the generated defn so its symbols
get resolved. Affects defcommand, defquery, defreadmodel, defprocessor,
and defperiodic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cjbarre cjbarre merged commit 7dddb31 into ObneyAI:main Jun 23, 2026
4 of 5 checks passed
@bpringe bpringe deleted the fix/kondo-hook-opts-map-analysis branch June 23, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clojure-lsp reports unused public var for vars used only in grain's def* macro opts maps

2 participants