Skip to content

Statically define convenience fns so clj-kondo/cljdoc can see them#15

Open
jsavyasachi wants to merge 2 commits into
clj-commons:masterfrom
jsavyasachi:static-digest-api
Open

Statically define convenience fns so clj-kondo/cljdoc can see them#15
jsavyasachi wants to merge 2 commits into
clj-commons:masterfrom
jsavyasachi:static-digest-api

Conversation

@jsavyasachi

Copy link
Copy Markdown

Closes #14.

Problem

The md5/sha-* convenience fns are interned at load time, so they don't exist statically: cljdoc's API page is empty, and the single-segment digest namespace gives consumers "unresolved symbol" errors. The (comment (declare ...)) hint helped clj-kondo for clj-commons.digest only - not cljdoc (which skips comment forms), and not the legacy namespace.

Change

  • Generate the convenience fns for the standard JCA algorithm set (md2, md5, sha, sha1, sha-1, sha-224/256/384/512, sha3-224/256/384/512) as real defns with docstrings + arglists, via dev/gen.clj, committed into both namespaces between markers. Drop the comment/declare hack.
  • Keep a create-missing-fns! fallback that interns vars for any extra algorithms a JVM exposes at runtime, so (algorithms) coverage is unchanged.
  • Fix utils-test: it used a lazy for, so its ns-resolve assertions never ran; now it actually checks every algorithm has a convenience fn.

Effect

  • Before: clj-kondo --lint src test reports 6 unresolved-symbol errors for the convenience fns; cljdoc shows none of them.
  • After: 0 unresolved-symbol errors - clj-kondo resolves md5/sha-256/… in both namespaces with real docstrings, no comment hack. lein test green (52 assertions, up from 18 once the no-op test actually runs).

Two unrelated, pre-existing clj-kondo findings remain (the byte-array extend-protocol form and the nil impl's unused bindings) - out of scope here.

The generated region is reproducible: bb dev/gen.clj is idempotent.

The md5/sha-* convenience fns were interned at load time, so clj-kondo
and cljdoc could not see them (the cljdoc API page was empty and the
single-segment digest ns produced unresolved-symbol errors). The
(comment (declare ...)) workaround only helped clj-kondo, not cljdoc,
and not the legacy namespace.

Generate the fns for the standard JCA algorithm set as real defns (with
docstrings and arglists) via dev/gen.clj, committed into both source
namespaces. A create-missing-fns! fallback still interns vars for any
additional algorithms a JVM exposes at runtime, so every algorithm in
(algorithms) keeps a matching var. Closes clj-commons#14.
It used a lazy for, so the ns-resolve assertions were never realized.
Switch to doseq and resolve in the source namespace, turning it into a
real check that every algorithm has a convenience fn.
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.

Consider making digest even more amenable to static analysis

1 participant