Fix kondo hook dropping handler opts map from analysis#15
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16
Problem
The
def-handler-macroclj-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 syntheticdefn. As a result, any var referenced only inside an opts map — e.g.{:authorized? my-ns/authenticated?}on adefcommand— is invisible to clj-kondo, so clojure-lsp reports it as an unused public var.Fix
Emit
?optsas the first body form of the generateddefnso its symbols get resolved: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
defcommandopts map (e.g.{:authorized? auth/authenticated?}) is now recorded in clj-kondo'svar-usagesanalysis, and clojure-lsp no longer flags the var as unused.🤖 Generated with Claude Code