diff --git a/lib/linguist/heuristics.yml b/lib/linguist/heuristics.yml index 6a269e7101..202e183058 100644 --- a/lib/linguist/heuristics.yml +++ b/lib/linguist/heuristics.yml @@ -94,6 +94,8 @@ disambiguations: pattern: '(<^\s*; |End Function)' - language: BitBake pattern: '^\s*(# |include|require)\b' + - language: Clojure + pattern: '\((def|defn|defmacro|let)\s' - extensions: ['.bi'] rules: - language: FreeBasic diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0a01488d00..27ed9abcf0 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1028,6 +1028,7 @@ Clojure: color: "#db5855" extensions: - ".clj" + - ".bb" - ".boot" - ".cl2" - ".cljc" @@ -1038,6 +1039,8 @@ Clojure: - ".hic" filenames: - riemann.config + interpreters: + - bb language_id: 62 Closure Templates: type: markup diff --git a/samples/Clojure/validate-and-format.bb b/samples/Clojure/validate-and-format.bb new file mode 100644 index 0000000000..05a5d746e0 --- /dev/null +++ b/samples/Clojure/validate-and-format.bb @@ -0,0 +1,45 @@ +#!/usr/bin/env bb + +(def filter-regex "\\.(clj\\|cljs\\|cljc)$") + +(defn clojure-source? [path] + (re-find #"\.(clj|cljs|cljc)$" path)) + +(defn modified-files [] + (-> (shell/sh "git" "diff" "--cached" "--name-only" "--diff-filter=ACMR") + :out + (str/split #"\n"))) + +(defn lint-valid? [paths] + (apply shell/sh "clj-kondo" "--lint" paths)) + +(defn native-cljstyle? [] + (-> (shell/sh "which" "cljstyle") :exit zero?)) + +(defn format-files [paths] + (if (native-cljstyle?) + (do + (println "Using native cljstyle...") + (apply shell/sh "cljstyle" "fix" paths)) + (do + (println "Using cljstyle from clojure deps...") + (apply shell/sh "clojure" "-A:format" "fix" paths)))) + +(defn update-file-index + "Add unstaged modifications to git, so they get to be part of the current commit." + [path] + (let [hash (:out (shell/sh "git" "hash-object" "-w" path))] + (shell/sh "git" "update-index" "--add" "--cacheinfo" "100644" hash path))) + +(let [paths (->> (modified-files) + (filter clojure-source?))] + (when (seq paths) + (format-files paths) + + (doseq [path paths] + (update-file-index path)) + + (let [{:keys [exit out]} (lint-valid? paths)] + (when-not (= 0 exit) + (println "Lint failed.\n" out) + (System/exit 1)))))