Skip to content

Commit

Permalink
Add a clj-kondo hook so lsp lints 'images' and 'images->' correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
soulflyer committed Mar 3, 2023
1 parent 4a12418 commit d129494
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{:hooks {:analyze-call {image-search.core/images hooks.images/images
image-search.core/images-> hooks.images/images}}}

30 changes: 30 additions & 0 deletions .clj-kondo/hooks/images.clj
Original file line number Diff line number Diff line change
@@ -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"
)
)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pom.xml.asc
.hg/
.#*
.tmux
.clj-kondo/.cache
8 changes: 4 additions & 4 deletions src/image_search/command_line.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/image_search/core.clj
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
10 changes: 6 additions & 4 deletions src/image_search/play.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
db
fullsize
image-collection
images->
images
keyword-collection
large
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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"))
Expand Down
36 changes: 0 additions & 36 deletions src/image_search/search.clj

This file was deleted.

0 comments on commit d129494

Please sign in to comment.