Skip to content

Commit

Permalink
add clj-kondo linting
Browse files Browse the repository at this point in the history
Upgrade to new version of clj-kondo that allows unused unstructured keys
in function defs. This greatly simplifies script/lint.sh which was doing
work to suppress these warnings.
  • Loading branch information
lread committed Aug 22, 2019
1 parent 52c0986 commit dcf83a1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 64 deletions.
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Expand Up @@ -3,4 +3,5 @@
:lint-as {taoensso.tufte/defnp clojure.core/defn
clojure.core.cache/defcache clojure.core/defrecord
clojure.java.jdbc/with-db-transaction clojure.core/let}
:linters {:unused-binding {:exclude-destructured-keys-in-fn-args true}}
:output {:include-files ["^src" "^test" "^modules"]}}
2 changes: 1 addition & 1 deletion deps.edn
Expand Up @@ -61,7 +61,7 @@
:main-opts ["-m" "kaocha.runner"]}

:clj-kondo
{:extra-deps {clj-kondo {:mvn/version "2019.07.24-alpha"}}
{:extra-deps {clj-kondo {:mvn/version "2019.07.31-alpha"}}
:main-opts ["-m" "clj-kondo.main"]}

:cli
Expand Down
2 changes: 1 addition & 1 deletion modules/analysis-runner/src/cljdoc/analysis/deps.clj
Expand Up @@ -96,7 +96,7 @@
Jsoup document `pom`."
[pom]
{:pre [(pom/jsoup? pom)]}
(let [{:keys [group-id artifact-id version]} (pom/artifact-info pom)
(let [{:keys [group-id artifact-id]} (pom/artifact-info pom)
project (symbol group-id artifact-id)]
(-> (extra-deps pom)
(merge (clj-cljs-deps pom))
Expand Down
2 changes: 1 addition & 1 deletion modules/cli/src/cljdoc/cli.clj
Expand Up @@ -26,7 +26,7 @@
(-> (merge (repositories/local-uris project version) args)
(cset/rename-keys {:git :scm-url, :rev :scm-rev})))))))

(defn offline-bundle [{:keys [project version output] :as args}]
(defn offline-bundle [{:keys [project version output] :as _args}]
(let [sys (select-keys (system/system-config (config/config))
[:cljdoc/storage :cljdoc/sqlite])
sys (ig/init sys)
Expand Down
2 changes: 1 addition & 1 deletion modules/shared-utils/src/cljdoc/util.clj
Expand Up @@ -69,7 +69,7 @@
(defn git-dir [project version]
(str "git-repos/" (group-id project) "/" (artifact-id project) "/" version "/"))

(defn clojars-id [{:keys [group-id artifact-id] :as artifact-entity}]
(defn clojars-id [{:keys [group-id artifact-id] :as _artifact-entity}]
(if (= group-id artifact-id)
artifact-id
(str group-id "/" artifact-id)))
Expand Down
57 changes: 3 additions & 54 deletions script/lint.sh
@@ -1,37 +1,12 @@
#!/usr/bin/env bash

#
# We can turf this script (or at least get more raw) when either of the following is true:
# 1) We decide to stop employing unused destructured keys as documentation
# 2) clj-kondo supports ignoring this specific use of unused bindings
#
# Reasonable shortcut:
# cljdocs has a few small sub-projects under modules, we could lint those separately but
# instead we are linting all cljdoc source at once.

set -eou pipefail

function line_at() {
local filename=$1
local line_num=$2
cat ${filename} | head -${line_num} | tail -1
}

function is_unused_destructured_key_warning() {
local lint_line=$@
local result="false"
IFS=: read filename line_num col_num level msg <<< ${lint_line}
if [[ ${level} =~ [[:space:]]*warning ]] && [[ ${msg} =~ [[:space:]]*unused[[:space:]]binding ]]; then
local file_line=$(line_at $filename $line_num)
if [[ ${file_line} =~ :keys ]]; then
result="true"
fi
fi
echo $result
}

function lint() {
local out_file=$1
local lint_args
if [ ! -d .clj-kondo/.cache ]; then
echo "--[linting and building cache]--"
Expand All @@ -45,39 +20,13 @@ function lint() {
lint_args="src test modules"
fi
set +e
clojure -A:clj-kondo --lint ${lint_args} &> ${out_file}
clojure -A:clj-kondo --lint ${lint_args}
local exit_code=$?
set -e
if [ ${exit_code} -ne 0 ] && [ ${exit_code} -ne 2 ] && [ ${exit_code} -ne 3 ]; then
cat ${out_file}
echo "** clj-kondo exited with unexpected exit code: ${exit_code}"
exit ${exit_code}
fi
exit ${exit_code}
}

SCRATCH_DIR=$(mktemp -d -t clj-kondo.out.XXXXXXXXXX)
function cleanup() {
rm -rf $SCRATCH_DIR
}
trap cleanup EXIT

EXIT_CODE=0
SUPPRESSED_COUNT=0

lint $SCRATCH_DIR/lint.out
while read lint_line; do
if [[ $lint_line =~ ^linting[[:space:]]took ]]; then
echo $lint_line
elif [ "$(is_unused_destructured_key_warning ${lint_line})" == "true" ]; then
SUPPRESSED_COUNT=$((SUPPRESSED_COUNT+1))
else
EXIT_CODE=1
echo $lint_line
fi
done < $SCRATCH_DIR/lint.out

if [ ${SUPPRESSED_COUNT} -gt 0 ]; then
echo "(suppressed ${SUPPRESSED_COUNT} unused descructured key warnings)"
fi

exit ${EXIT_CODE}
lint
2 changes: 1 addition & 1 deletion src/cljdoc/server/api.clj
Expand Up @@ -65,7 +65,7 @@
(storage/import-doc storage (util/version-entity project version) {})
;; Git analysis may derive the revision via tags but a URL is always required.
(if scm-url
(let [{:keys [error scm-url commit] :as git-result}
(let [{:keys [error] :as git-result}
(ingest/ingest-git! storage {:project project
:version version
:scm-url scm-url
Expand Down
2 changes: 1 addition & 1 deletion src/cljdoc/server/ingest.clj
Expand Up @@ -37,7 +37,7 @@

(defn ingest-git!
"Analyze the git repository `repo` and store the result in `storage`"
[storage {:keys [project version scm-url local-scm pom-revision] :as repo}]
[storage {:keys [project version scm-url local-scm pom-revision] :as _repo}]
{:pre [(string? scm-url)]}
(let [git-analysis (ana-git/analyze-git-repo project version (or local-scm scm-url) pom-revision)]
(if (:error git-analysis)
Expand Down
2 changes: 1 addition & 1 deletion src/cljdoc/server/pedestal.clj
Expand Up @@ -280,7 +280,7 @@
{:name ::badge
:leave (fn badge [ctx]
(log/info "Badge req headers" (-> ctx :request :headers))
(let [{:keys [group-id artifact-id version]} (-> ctx :request :path-params)
(let [{:keys [version]} (-> ctx :request :path-params)
last-build (::last-build ctx)
[status color] (cond
(and last-build (not (build-log/api-import-successful? last-build)))
Expand Down
2 changes: 1 addition & 1 deletion src/cljdoc/server/release_monitor.clj
Expand Up @@ -46,7 +46,7 @@
build-id))

(defn exclude?
[{:keys [group_id artifact_id version] :as build}]
[{:keys [group_id artifact_id version] :as _build}]
(or (= "cljsjs" group_id)
(.endsWith version "-SNAPSHOT")
(and (= "org.akvo.flow" group_id)
Expand Down
4 changes: 2 additions & 2 deletions src/cljdoc/util/fixref.clj
Expand Up @@ -47,7 +47,7 @@

(defn fix-link
"Return the cljdoc location for a given URL or it's page on GitHub/GitLab etc."
[file-path href {:keys [scm-base uri-map] :as opts}]
[file-path href {:keys [scm-base uri-map] :as _opts}]
(let [root-relative (if (.startsWith href "/")
(subs href 1)
(rebase file-path href))
Expand All @@ -69,7 +69,7 @@
;; Below, a `nofollow` attribute is added to external links for SEO purposes.

(defn fix
[file-path html-str {:keys [git-ls scm uri-map] :as fix-opts}]
[file-path html-str {:keys [git-ls scm uri-map] :as _fix-opts}]
;; (def fp file-path)
;; (def hs html-str)
;; (def fo fix-opts)
Expand Down

0 comments on commit dcf83a1

Please sign in to comment.