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

Add .bb file extension for Babashka to Clojure #5931

Merged
merged 10 commits into from Jun 8, 2022
2 changes: 2 additions & 0 deletions lib/linguist/heuristics.yml
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/linguist/languages.yml
Expand Up @@ -1028,6 +1028,7 @@ Clojure:
color: "#db5855"
extensions:
- ".clj"
- ".bb"
- ".boot"
- ".cl2"
- ".cljc"
Expand All @@ -1038,6 +1039,8 @@ Clojure:
- ".hic"
filenames:
- riemann.config
interpreters:
- bb
language_id: 62
Closure Templates:
type: markup
Expand Down
45 changes: 45 additions & 0 deletions samples/Clojure/validate-and-format.bb
@@ -0,0 +1,45 @@
#!/usr/bin/env bb
lildude marked this conversation as resolved.
Show resolved Hide resolved

(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)))))