Show More
Commit Description:
Tweak warning levels and remove .java-version, which was misleading.
Commit Description:
Tweak warning levels and remove .java-version, which was misleading.
References:
File last commit:
Show/Diff file:
Action:
src/project_checkup/core.clj
158 lines | 5.8 KiB | text/x-clojure | ClojureLexer
158 lines | 5.8 KiB | text/x-clojure | ClojureLexer
r0 | #!/usr/bin/env lumo | |||
(ns project-checkup.core | ||||
(:gen-class) | ||||
(:require [clojure.java.shell :as shell] | ||||
r14 | [clojure.string :as string])) | |||
r0 | ||||
r14 | (defn get-extension [path] | |||
r8 | "Extracts the extension of a path. | |||
r14 | Returns the extension with the period, e.g., '.txt' because that's the format | |||
r8 | people are used to seeing extensions in." | |||
(re-find #"\.[a-zA-Z0-9]+$" path)) | ||||
r0 | ||||
r14 | (defn gather-untracked | |||
r10 | [vcs-systems] | |||
"Gather untracked files in Git or Mercurial." | ||||
(reduce into [ | ||||
(if (contains? vcs-systems ".hg") | ||||
(string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) | ||||
(if (contains? vcs-systems ".git") | ||||
r14 | (string/split (:out (shell/sh "git" "ls-files" "--others" | |||
r10 | "--exclude-standard")) #"\n"))] | |||
) | ||||
) | ||||
r0 | (defn gather-project-info | |||
r10 | "Creates a dictionary of project information." | |||
r0 | [] | |||
r14 | (let [all-files (map str (file-seq (clojure.java.io/file "."))) | |||
r4 | ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") | |||
r10 | ||||
files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) | ||||
r13 | ; file-set (set files) | |||
r10 | ;note that using some here means that if both are present, hg is | |||
;ignored: | ||||
vcs-systems (set (vector (some #{".git" ".hg"} files))) ] | ||||
r14 | {:files files | |||
r0 | :extensions (frequencies (map get-extension files )) | |||
r6 | :path (System/getProperty "user.dir") | |||
r14 | :untracked-files (gather-untracked vcs-systems) | |||
:readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") | ||||
r6 | }) ) | |||
r0 | ||||
(defn color [color string] | ||||
(let [color-sequence (case color | ||||
:green "\u001B[32m" | ||||
:yellow "\u001B[33m" | ||||
:blue "\u001B[34m" | ||||
r4 | :red "\u001B[31m" | |||
:cyan "\u001B[36m" | ||||
:magenta "\u001B[35m" | ||||
r0 | ) | |||
reset "\u001B[m" ] | ||||
(str color-sequence string reset)) ) | ||||
(defn check-vcs [project] | ||||
(let [{files :files } project] | ||||
r4 | (boolean (some #{".git" ".hg"} files)) )) | |||
r0 | ||||
(defn check-readme [project] | ||||
(let [{files :files } project] | ||||
r7 | (boolean (some #{"README.md" "README.txt" "README.mkd" "README"} files)) )) | |||
r0 | ||||
r27 | (defn check-changelog [project] | |||
(let [{files :files } project] | ||||
(boolean (some #{"CHANGELOG.md" "CHANGELOG.txt" "CHANGELOG.mkd" "CHANGELOG"} files)) )) | ||||
r0 | (defn check-untracked [project] | |||
(let [{untracked :untracked-files } project] | ||||
(= (count untracked) 0)) ) | ||||
(defn check-taskpaper [project] | ||||
r4 | (let [{extensions :extensions files :files } project] | |||
r27 | (or (>= (get extensions ".taskpaper" 0) 1) | |||
r14 | (some #{"TODO" "TODO.txt" } files)))) | |||
r4 | ||||
(defn check-readme-placeholders [project] | ||||
r7 | (= (count (re-find #"(FIXME|TODO)" (:readme project) )) 0)) | |||
r4 | ||||
r0 | ||||
r15 | (defn check-license [project] | |||
(let [{files :files } project] | ||||
r16 | (boolean (some #{"LICENSE" "LICENSE.txt" "LICENSE.md" "LICENSE.mkd"} files)))) | |||
r15 | ||||
r13 | (def checks [{:name "Project is checked into revision control" | |||
r0 | :description "" | |||
:function check-vcs | ||||
r14 | :level :error | |||
r0 | :follow-up "Initialize a repository." } | |||
{:name "Always True" | ||||
:function #(or true %) | ||||
:level :error | ||||
:follow-up "This is a bug." } | ||||
r13 | {:name "All files are tracked or ignored" | |||
r0 | :description "" | |||
:function check-untracked | ||||
:level :warning | ||||
r10 | :follow-up "Commit or ignore files from 'hg st -u' or 'git ls-files --others --exclude-standard'." } | |||
r13 | {:name "Project has a todo file" | |||
r0 | :function check-taskpaper | |||
:description "" | ||||
:level :suggestion | ||||
r14 | :follow-up "Add a todo file using Taskpaper." } | |||
r15 | {:name "Project has a README" | |||
r0 | :function check-readme | |||
:description "Readme exists" | ||||
r28 | :level :warning | |||
r4 | :follow-up "Add a README." } | |||
r27 | {:name "Project has a CHANGELOG" | |||
:function check-changelog | ||||
:description "Changelog exists" | ||||
r28 | :level :warning | |||
:follow-up "Add a CHANGELOG. Consider refering to keepachangelog.com for guidance." } | ||||
r4 | {:name "README has no placeholders" | |||
:function check-readme-placeholders | ||||
:description "No placeholders in README" | ||||
:level :error | ||||
:follow-up "Address placeholders or convert them to tasks." | ||||
r15 | } | |||
{ :name "Project has a license" | ||||
:function check-license | ||||
:description "Project has a LICENSE file." | ||||
:level :warning ;going with warning because a project might not have a license before release. | ||||
r28 | :follow-up "Add a license to LICENSE. Consider using https://choosealicense.com/ for guidance." }]) | |||
r0 | ||||
(defn perform-check [check project] | ||||
(let [{check-name :name function :function follow-up :follow-up | ||||
level :level } check | ||||
result (function project) | ||||
false-color (case level | ||||
:suggestion :blue | ||||
:warning :yellow | ||||
:error :red | ||||
r14 | :red) | |||
r13 | prefix (case level | |||
r15 | :suggestion "Suggested " | |||
:warning "Recommended " | ||||
:error "Required " | ||||
r14 | "Follow-up" )] | |||
r0 | {:name check-name | |||
:result result | ||||
r14 | :output (if result | |||
(color :green (str "✔" check-name "…passed!")) | ||||
(str (color false-color (str "❌" check-name "…failed!")) "\n\t" prefix " Follow up: " follow-up))})) | ||||
r0 | ||||
(defn -main | ||||
r4 | "Run checks." | |||
r0 | [& args] | |||
r14 | (try | |||
(let [project-info (gather-project-info)] | ||||
(doseq [check checks] | ||||
(println (:output (perform-check check project-info ))))) | ||||
(catch Exception ex | ||||
(.printStackTrace ex) | ||||
(str "caught exception: " (.getMessage ex))) | ||||
r15 | (finally (shutdown-agents)))) | |||