From d12949482cc7123b1e3ae941bcfa3c23a18d5c7c Mon Sep 17 00:00:00 2001 From: iain Date: Fri, 3 Mar 2023 13:00:20 +0700 Subject: [PATCH] Add a clj-kondo hook so lsp lints 'images' and 'images->' correctly --- .clj-kondo/config.edn | 3 +++ .clj-kondo/hooks/images.clj | 30 ++++++++++++++++++++++++++ .gitignore | 1 + src/image_search/command_line.clj | 8 +++---- src/image_search/core.clj | 3 --- src/image_search/play.clj | 10 +++++---- src/image_search/search.clj | 36 ------------------------------- 7 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 .clj-kondo/config.edn create mode 100644 .clj-kondo/hooks/images.clj delete mode 100644 src/image_search/search.clj diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 0000000..e5b5bce --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,3 @@ +{:hooks {:analyze-call {image-search.core/images hooks.images/images + image-search.core/images-> hooks.images/images}}} + diff --git a/.clj-kondo/hooks/images.clj b/.clj-kondo/hooks/images.clj new file mode 100644 index 0000000..2b34a4f --- /dev/null +++ b/.clj-kondo/hooks/images.clj @@ -0,0 +1,30 @@ +(ns hooks.images + (:require [clj-kondo.hooks-api :as api])) + +(defn images + [{:keys [node]}] + (let [forms (rest (:children node)) + new-node (api/list-node + (list* + (api/token-node '->) + [{:a 1}] + forms + ))] + {:node new-node})) + +(comment + (images (in :Keywords "Ceratosoma trilobatum") + (image-paths) + (write "/tmp/ceratasoma.txt")) + (list* (api/token-node '->) + (list* {:a 1}) + (in :Keywords "Ceratosoma trilobatum") + (image-paths) + (write "/tmp/ceratasoma.txt") + ) + (list* + (api/token-node '->) + [{:a 1}] + "forms" + ) + ) diff --git a/.gitignore b/.gitignore index 14be325..45c64ee 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pom.xml.asc .hg/ .#* .tmux +.clj-kondo/.cache diff --git a/src/image_search/command_line.clj b/src/image_search/command_line.clj index 448ffd1..bf139e4 100644 --- a/src/image_search/command_line.clj +++ b/src/image_search/command_line.clj @@ -1,9 +1,9 @@ (ns image-search.command-line (:refer-clojure :exclude [or and]) - (:require [image-search.core :refer [open all-images]] - [image-lib.search :refer [eq in]] + (:require [clojure.tools.cli :refer [parse-opts]] [image-lib.helper :refer [image-paths]] - [clojure.tools.cli :refer :all]) + [image-lib.search :refer [eq in]] + [image-search.core :refer [open all-images]]) (:gen-class)) (def cli-options @@ -41,7 +41,7 @@ (defn -main "Searches for image details from a mongo database" [& args] - (let [{:keys [options arguments errors summary]} (parse-opts args cli-options) + (let [{:keys [options summary]} (parse-opts args cli-options) output-function (cond (:count options) print-count diff --git a/src/image_search/core.clj b/src/image_search/core.clj index 966c868..f798369 100644 --- a/src/image_search/core.clj +++ b/src/image_search/core.clj @@ -1,10 +1,7 @@ (ns image-search.core (:refer-clojure :exclude [or and]) (:require [monger [collection :as mc] [core :as mg]] - [clojure.string :as str] - [clojure.java.shell :refer [sh]] [image-lib.preferences :refer [preference]] - [image-lib.helper :refer [image-path]] [image-lib.images :refer [open-images]]) (:gen-class)) diff --git a/src/image_search/play.clj b/src/image_search/play.clj index dfaa323..6a20fcd 100644 --- a/src/image_search/play.clj +++ b/src/image_search/play.clj @@ -13,6 +13,7 @@ db fullsize image-collection + images-> images keyword-collection large @@ -38,7 +39,7 @@ (map :Project (find-images db image-collection "ISO-Speed-Ratings" "640")) ;; In the case of :Project, it is probably more useful to turn the - ;; sequence into a set: + ;; sequence into a set (careful, project names may not be unique): (set (map :Project (find-images db image-collection "ISO-Speed-Ratings" "640"))) ;; We can also use the eq ge lt etc functions to filter a list of images @@ -86,11 +87,12 @@ (-> all-images (or (in :Model "phone") - (and (in :Model "Nik") + (and + (in :Model "Nik") (eq :Year 2016))) count) - ;; images can be used instead of -> all-images + ;; images or images-> can be used instead of -> all-images (images (and (in :Model "Nik") (eq :ISO-Speed-Ratings 640)) @@ -100,7 +102,7 @@ ;; emptied first, up to you to rm it, if thats what you want. This example also uses ;; paths, which just outputs the path of each pic - (images + (images-> (in :Model "phone") (image-paths) (write "/tmp/phone-pics")) diff --git a/src/image_search/search.clj b/src/image_search/search.clj deleted file mode 100644 index 9201161..0000000 --- a/src/image_search/search.clj +++ /dev/null @@ -1,36 +0,0 @@ -(ns image-search.search - (:refer-clojure :exclude [and or]) - (:require [image-lib.images :refer [find-images find-all-images]] - [image-lib.core :refer [best-image]] - [image-lib.keywords :refer [find-sub-keywords]] - [image-lib.helper :refer [image-path image-paths]] - [image-lib.preferences :refer [preference preferences preference!]] - [image-lib.search :refer [in eq lt le gt ge - or and]] - [image-search.core :refer [open - images - database - image-collection - keyword-collection - db - all-images - thumbnail - medium - large - fullsize]])) -;; Being a collection of useful searches. Start up cider and hit C-c C-c - -(comment - (map image-path (images - (eq :ISO-Speed-Ratings 640))) - - (images - (in :Model "phone") - (eq :Year 2015) - (image-paths)) - - (images - (in :Model "phone") - (eq :Year 2015) - (open medium)) - )