Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clj-kondo/imports/babashka/ffi/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:hooks {:analyze-call {babashka.ffi/defcfn hooks.babashka.ffi/defcfn}}}
88 changes: 88 additions & 0 deletions .clj-kondo/imports/babashka/ffi/hooks/babashka/ffi.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(ns hooks.babashka.ffi
(:require [clj-kondo.hooks-api :as api]))

(def ^:private layout-kinds
;; Keep in sync with babashka.ffi/layout-kinds.
#{:struct :array :union})

(defn- layout-vector?
[n]
(and (api/vector-node? n)
(contains? layout-kinds (some-> n :children first api/sexpr))))

(defn defcfn
"Rewrites defcfn forms for linting."
[{:keys [node]}]
(let [[nm & args] (rest (:children node))
anchor (first (keep-indexed (fn [i n]
(when (and (api/vector-node? n)
(not (layout-vector? n)))
i))
args))
anchored? (and anchor (pos? anchor))
prefix (if anchored? (take (dec anchor) args) (drop-last 3 args))
docstring (first (filter api/string-node? prefix))
attr-map (first (filter api/map-node? prefix))
sym-node (when anchored? (nth args (dec anchor)))
argtypes (when anchor (nth args anchor))
rettype (when (and anchor (> (count args) (inc anchor)))
(nth args (inc anchor)))
wrapper (when (and anchor (> (count args) (+ anchor 2)))
(drop (+ anchor 2) args))
head (cond-> [(api/token-node 'clojure.core/defn) nm]
docstring (conj docstring)
attr-map (conj attr-map))
;; Lint signature expressions.
extras (remove nil? [sym-node argtypes rettype])
wrap-do (fn [n]
(if (seq extras)
(api/list-node (concat [(api/token-node 'do)] extras [n]))
n))
;; The C return value has no static type.
opaque-value (fn []
(api/list-node
[(api/token-node 'clojure.core/deref)
(api/list-node [(api/token-node 'clojure.core/atom)
(api/token-node nil)])]))
;; Match fixed and variadic C arities.
arg-params (fn []
(let [types (:children argtypes)
variadic? (= :& (some-> (last types) api/sexpr))
fixed (if variadic? (butlast types) types)]
(api/vector-node
(cond-> (mapv (fn [i] (api/token-node (symbol (str "_arg" i))))
(range (count fixed)))
variadic? (conj (api/token-node '&)
(api/token-node '_rest))))))]
{:node
(cond
(seq wrapper)
;; Use the same raw-binding scope as the macro.
(let [raw (first wrapper)
tail (rest wrapper)
arities (if (api/vector-node? (first tail))
[tail]
(map :children tail))
arity-node (fn [children] (api/list-node children))]
(wrap-do
(api/list-node
[(api/token-node 'clojure.core/let)
(api/vector-node
[raw (api/list-node
[(api/token-node 'clojure.core/fn)
(arg-params)
(opaque-value)])])
(api/list-node (into head (map arity-node arities)))])))

;; Model literal argtypes as a fixed or variadic arity.
anchor
(wrap-do (api/list-node (conj head
(arg-params)
(opaque-value))))

;; Dynamic argtypes have no static arity.
:else
(api/list-node
(conj head
(api/vector-node [(api/token-node '&) (api/token-node '_args)])
(api/list-node (list* (api/token-node 'do) (take-last 3 args))))))}))
2 changes: 2 additions & 0 deletions .clj-kondo/imports/hiccup/hiccup/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:lint-as {hiccup.def/defhtml clojure.core/defn}
:hooks {:analyze-call {hiccup.def/defelem hiccup.hooks/defelem}}}
38 changes: 38 additions & 0 deletions .clj-kondo/imports/hiccup/hiccup/hiccup/hooks.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(ns hiccup.hooks
(:require [clj-kondo.hooks-api :as api]
[clojure.set :as set]))

;; See https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md

(defn- parse-defn [elems]
(let [[fhead fbody] (split-with #(not (or (api/vector-node? %)
(api/list-node? %)))
elems)
arities (if (api/vector-node? (first fbody))
(list (api/list-node fbody))
fbody)]
[fhead arities]))

(defn- count-args [arity]
(let [args (first (api/sexpr arity))]
(if (= '& (fnext (reverse args)))
true ; unbounded args
(count args))))

(defn- dummy-arity [arg-count]
(api/list-node
(list
(api/vector-node
(vec (repeat arg-count (api/token-node '_)))))))

(defn defelem [{:keys [node]}]
(let [[_ & rest] (:children node)
[fhead arities] (parse-defn rest)
arg-counts (set (filter number? (map count-args arities)))
dummy-arg-counts (set/difference (set (map inc arg-counts)) arg-counts)
dummy-arities (for [n dummy-arg-counts] (dummy-arity n))]
{:node
(api/list-node
(list*
(api/token-node 'clojure.core/defn)
(concat fhead arities dummy-arities)))}))
2 changes: 2 additions & 0 deletions .clj-kondo/imports/instaparse/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:lint-as {instaparse.macros/defclone clojure.core/def
instaparse.macros/set-global-var! clojure.core/set!}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: 'shared setup'
description: 'Composite action for common setup steps'
inputs:
jdk:
description: 'jdk version'
Expand Down Expand Up @@ -31,7 +32,7 @@ runs:
if: inputs.jdk != 'skip'

- name: Install Clojure Tools
uses: DeLaGuardo/setup-clojure@13.6.1
uses: DeLaGuardo/setup-clojure@13.7.0
with:
cli: 'latest'
bb: 'latest'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nvd_scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
java-version: 21

- name: Install Clojure Tools
uses: DeLaGuardo/setup-clojure@13.6.1
uses: DeLaGuardo/setup-clojure@13.7.0
with:
cli: 'latest'
bb: 'latest'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: publish
on:
push:
tags:
- 'v\d+.*'
- 'v[0-9]+.*'

jobs:
test:
Expand All @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup
uses: ./.github/workflows/shared-setup
uses: ./.github/actions/shared-setup
with:
jdk: '8'

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup
uses: ./.github/workflows/shared-setup
uses: ./.github/actions/shared-setup
with:
jdk: '11'

Expand All @@ -31,7 +31,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup
uses: ./.github/workflows/shared-setup
uses: ./.github/actions/shared-setup
with:
jdk: '25'

Expand All @@ -44,7 +44,7 @@ jobs:
fail-fast: false
matrix:
os: [{name: 'windows', shell: 'pwsh'}, {name: 'ubuntu', shell: 'bash'}]
jdk: ['8', '11', '17', '21', '25', '26']
jdk: ['8', '11', '17', '21', '25', '27']

name: ${{matrix.os.name}} jdk ${{ matrix.jdk }}

Expand All @@ -53,7 +53,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup
uses: ./.github/workflows/shared-setup
uses: ./.github/actions/shared-setup
with:
jdk: ${{ matrix.jdk }}
shell: ${{ matrix.os.shell }}
Expand All @@ -74,7 +74,7 @@ jobs:
- { name: 'graalvm', short-name: 'graal' }
- { name: 'graalvm-community', short-name: 'graalce' }
version:
- '25.3.4.1'
- '25.5'
clojure-version: [ '1.12', '1.13' ]

name: ${{matrix.os.name}} ${{matrix.distribution.short-name}}${{matrix.version}} clj${{ matrix.clojure-version }}
Expand All @@ -84,7 +84,7 @@ jobs:
uses: actions/checkout@v7

- name: Setup
uses: ./.github/workflows/shared-setup
uses: ./.github/actions/shared-setup
with:
jdk: skip
shell: ${{ matrix.os.shell }}
Expand Down
5 changes: 3 additions & 2 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
:paths ["script" "build"]
:deps {lread/status-line {:git/url "https://github.com/lread/status-line.git"
:sha "eace48e2e0fcc65a3986d696fb0b910fa5790a1c"}
io.github.babashka/neil {:git/tag "v0.3.70" :git/sha "2cdd7c6"}
io.github.babashka/neil {:git/tag "v0.3.71" :git/sha "78e11f7"}
version-clj/version-clj {:mvn/version "2.0.3"}
wevre/natural-compare {:mvn/version "0.0.10"}}
wevre/natural-compare {:mvn/version "0.0.10"}
com.github.liquidz/antq {:git/sha "252bc297b7cb15807c63dbea0ac7214e47ac9aef"}}
:tasks {;; setup
:requires ([babashka.fs :as fs]
[clojure.string :as string]
Expand Down
16 changes: 0 additions & 16 deletions build.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns build
(:require [babashka.fs :as fs]
[build-shared]
[clojure.edn :as edn]
[clojure.java.shell :as shell]
[clojure.tools.build.api :as b]))

Expand Down Expand Up @@ -98,18 +97,3 @@
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
opts))
opts)

(defn download-deps
"Download all deps for all aliases"
[_]
(let [aliases (->> "deps.edn"
slurp
edn/read-string
:aliases
keys)]
;; one at a time because aliases with :replace-deps will... well... you know.
(println "Bring down default deps")
(b/create-basis {})
(doseq [a (sort aliases)]
(println "Bring down deps for alias" a)
(b/create-basis {:aliases [a]}))))
11 changes: 3 additions & 8 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
:clojure-1.10 {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}}
:clojure-1.11 {:override-deps {org.clojure/clojure {:mvn/version "1.11.4"}}}
:clojure-1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.6"}}}
:clojure-pre-1.13 {:override-deps {org.clojure/clojure {:mvn/version "1.13.0-alpha6"}}}
:clojure-pre-1.13 {:override-deps {org.clojure/clojure {:mvn/version "1.13.0-alpha11"}}}

:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
Expand All @@ -38,15 +38,10 @@
babashka/fs {:mvn/version "0.5.34"}}
:ns-default build}
;; for consistent linting we use a specific version of clj-kondo through the jvm
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2026.08.04"}}
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2026.10.26"}}
:override-deps {org.clojure/clojure {:mvn/version "1.12.5"}}
:main-opts ["-m" "clj-kondo.main"]}
:eastwood {:extra-deps {jonase/eastwood {:mvn/version "1.4.3"}}
:main-opts ["-m" "eastwood.lint" {:source-paths ["src/clojure"]
:test-paths ["test"]
:add-linters [:performance]}]}
:outdated {:extra-deps {com.github.liquidz/antq {:mvn/version "2.11.1276"}
org.clojure/clojure {:mvn/version "1.12.5"}
org.slf4j/slf4j-simple {:mvn/version "2.0.19"} ;; to rid ourselves of logger warnings
}
:main-opts ["-m" "antq.core"]}}}
:add-linters [:performance]}]}}}
25 changes: 17 additions & 8 deletions script/download_deps.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
(ns download-deps
(:require [babashka.tasks :as t]))
(:require
[clojure.edn :as edn]
[clojure.tools.build.api :as b]
[lread.status-line :as status]))

;; clojure has a -P command, but to bring down all deps we need to specify all aliases
;; bb deps will be brought down just from running bb (which assumedly is how this code is run)

(defn task
[_opts]
;; do all the work from build.clj to avoid repeated JVM launch costs
(t/clojure "-T:build download-deps"))
(defn task [_opts]
(status/line :head "Downloading deps")
(let [aliases (->> "deps.edn"
slurp
edn/read-string
:aliases
keys)]
;; one at a time because aliases with :replace-deps will... well... you know.
(println "Bring down default deps")
(b/create-basis {})
(doseq [a (sort aliases)]
(println "Bring down deps for alias" a)
(b/create-basis {:aliases [a]}))))
7 changes: 4 additions & 3 deletions script/outdated.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns outdated
(:require [helper.shell :as shell]))
(:require [antq.core :as antq]
[lread.status-line :as status]))

(defn task [_opts]
(shell/clojure {:continue true}
"-M:outdated --directory=.:nvd_check_helper_project"))
(status/line :head "Checking Clojure deps & Github Actions")
(antq/-main))
Loading