Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup clj-kondo as linter #134

Merged
merged 3 commits into from
Jan 24, 2025
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
14 changes: 10 additions & 4 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4.5.0
uses: actions/setup-java@v4.6.0
with:
java-version: '11'
distribution: 'corretto'

- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@13.0
uses: DeLaGuardo/setup-clojure@13.1
with:
cli: 1.11.2.1446
cli: 1.12.0.1495

- name: Cache clojure dependencies
uses: actions/cache@v4
Expand All @@ -38,8 +38,14 @@ jobs:
# List all files containing dependencies:
key: cljdeps-${{ hashFiles('deps.edn') }}

- name: Run tests (current, Clojure 1.11)
- name: Run tests (current, Clojure 1.12)
run: clojure -X:test

- name: Run tests (Clojure 1.11
run: clojure -X:1.11:test

- name: Run tests (Clojure 1.10)
run: clojure -X:1.10:test

- name: Lint
run: clojure -M:lint
19 changes: 14 additions & 5 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.11.3"}}
:deps {org.clojure/clojure {:mvn/version "1.12.0"}}

:aliases
{:test
;; clj -X:test
{:extra-paths ["test"]
:extra-deps {criterium/criterium {:mvn/version "0.4.6"}
org.clojure/core.async {:mvn/version "1.6.681"}
org.clojure/core.async {:mvn/version "1.7.701"}
nubank/matcher-combinators {:mvn/version "3.9.1"}
io.github.tonsky/clj-reload {:mvn/version "0.7.1"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1"
Expand All @@ -20,8 +20,11 @@
{:git/tag "0.10.2" :git/sha "3c446e4"}}
:ns-default build}

:1.11
{:override-deps {org.clojure/clojure {:mvn/version "1.11.4"}}}

:1.10
{:override-deps {org.clojure/clojure {:mvn/version "1.11.2"}}}
{:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}}

;; clj -M:test:demo
:demo
Expand All @@ -30,9 +33,15 @@
:disable-colors
{:jvm-opts ["-Dclj-commons.ansi.enabled=false"]}

;; clj -M:lint

:lint
{:deps {clj-kondo/clj-kondo {:mvn/version "2025.01.16"}}
:main-opts ["-m" "clj-kondo.main" "--lint" "src"]}

:nrepl
{:extra-deps {nrepl/nrepl {:mvn/version "1.3.0"}}
:main-opts ["-m" "nrepl.cmdline" ]}
{:extra-deps {nrepl/nrepl {:mvn/version "1.3.1"}}
:main-opts ["-m" "nrepl.cmdline"]}

:repl
{:main-opts ["-m" "clj-commons.pretty.repl"]}}
Expand Down
6 changes: 0 additions & 6 deletions src/clj_commons/ansi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@
(keyword (str "bright-" color-name "-bg")) [:background (str (+ 100 index))]})
["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"])))

(defn- delta
[active current k]
(let [current-value (get current k)]
(when (not= (get active k) current-value)
current-value)))

(defn- compose-font
"Uses values in current to build a font string that will reset all fonts characteristics then,
as necessary, add back needed font characteristics."
Expand Down
2 changes: 2 additions & 0 deletions src/clj_commons/format/binary.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
(data-length [this] "The total number of bytes available.")
^byte (byte-at [this index] "The byte value at a specific offset."))

;; This is problematic for clj-kondo, but valid.
#_:clj-kondo/ignore
(extend-type (Class/forName "[B")
BinaryData
(data-length [ary] (alength (bytes ary)))
Expand Down
10 changes: 5 additions & 5 deletions src/clj_commons/format/exceptions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
;;; could change at any time.

(def ^:private clojure->java
(->> (Compiler/CHAR_MAP)
(->> Compiler/CHAR_MAP
set/map-invert
(sort-by #(-> % first length))
reverse))
Expand Down Expand Up @@ -534,8 +534,8 @@

;; Shadow Clojure 1.11's version, while keeping operational in 1.10.
(defn- -update-keys
[m f]
"Builds a map where f has been applied to each key in m."
[m f]
(reduce-kv (fn [m k v]
(assoc m (f k) v))
{}
Expand Down Expand Up @@ -693,7 +693,7 @@
(compose
(render-exception exception-stack options)))

(defn ^String format-exception
(defn format-exception
"Formats an exception, returning a single large string.

By default, includes the stack trace, with no frame limit.
Expand Down Expand Up @@ -747,9 +747,9 @@

The `*fonts*` var contains a map from output element names (as :exception or :clojure-frame) to
a font def used with [[compose]]; this allows easy customization of the output."
([exception]
(^String [exception]
(format-exception exception nil))
([exception options]
(^String [exception options]
(format-exception* (analyze-exception exception options) options)))

(defn print-exception
Expand Down
12 changes: 6 additions & 6 deletions src/clj_commons/format/table.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; Copyright 2024 Nubank NA
; Copyright 2024-2025 Nubank NA
;
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0)
Expand All @@ -19,7 +19,7 @@
Specs are in [[clj-commons.format.table.specs]]."
{:added "2.3"}
(:require [clojure.string :as string]
[clj-commons.ansi :refer [pcompose]]))
[clj-commons.ansi :refer [pout]]))

(defn- make-bar
[width s]
Expand Down Expand Up @@ -175,15 +175,15 @@
:last? (= last-column-index (:index col))
:bar (make-bar (:width col) hbar)))))]
(when header?
(pcompose
(pout
header-left
(for [{:keys [last? bar]} columns']
(list bar
(when-not last?
header-sep)))
header-right))

(pcompose
(pout
row-left
(for [{:keys [width title title-pad last?]} columns']
(list [{:width width
Expand All @@ -193,7 +193,7 @@
row-sep)))
row-right)

(pcompose
(pout
divider-left
(for [{:keys [bar last?]} columns']
(list bar
Expand All @@ -204,7 +204,7 @@
(when (seq rows)
(loop [[row & more-rows] rows
row-index 0]
(pcompose
(pout
row-left
(for [{:keys [width key decorator last? pad]} columns'
:let [value (key row)
Expand Down
Loading