#!/usr/bin/env bash

mkdir -p /tmp/clj-kondo-diff

cp="$(clojure -Spath -A:cljs)"
read -r -d '' config <<'EOF' || true
{;; :analysis {:keywords true}
 :linters
  {:redundant-fn-wrapper {:level :warning}
   :not-a-function
    {:skip-args [clojure.pprint/defdirectives
                 cljs.pprint/defdirectives
                 clojure.data.json/codepoint-case]}
  :def-fn {:level :warning}
  :redundant-str-call {:level :warning}}
 :output {:langs false}}
EOF

out="/tmp/clj-kondo-diff/branch.txt"

export CLJ_KONDO_DEV=true

echo "Linting and writing output to $out"
rm -rf .clj-kondo/.cache
clojure -M:clj-kondo/dev --lint "$cp" --cache --config "$config" --parallel > "$out"

cd /tmp
rm -rf clj-kondo
git clone https://github.com/clj-kondo/clj-kondo.git
cd clj-kondo

if [ -n "$1" ]; then
    echo "git reset $1 --hard"
    git reset $1 --hard
fi

out="/tmp/clj-kondo-diff/master.txt"

echo "Linting and writing output to $out"
clojure -M:clj-kondo/dev --lint "$cp" --cache --config "$config" --parallel > "$out"

diff /tmp/clj-kondo-diff/branch.txt /tmp/clj-kondo-diff/master.txt
