forked from clj-commons/etaoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlights: - found 1 bug - `etaoin.ide.api` `:storeTitle` command was calling `etaoin.api/get-title` with wrong number of args. Fixed. - found an invalid symbol `num-.` from https://clojure.org/reference/reader: "Symbols beginning or ending with '.' are reserved by Clojure" Left as is, but will likely follow up with a name change. Of note: - Etaoin uses, and might encourage, the use of `:refer :all` for its api. Ignoring for now. We can decide how we want to do at some later date. Other - Missing require for `clojure.set` added - An `if` without else converted to `when`. I like this convention, to me it conveys that an `if` did not accidentally omit an else condition. - Unused bindings/paramers prefixed with underscore, unless part of public API and the unuse is an implementation detail. I find this convention helpful when glancing at fn signatures, I can quickly tell what is being used. Mostly left these in as I think they typically conveyed an interface of sorts, but another option is to omit unused bindings. - Unused requires, imports and private vars turfed - Taught clj-kondo about slingshot macros by bringing in existing clj-kondo slingshot export config - Taught clj-kondo about etaoin macros we are using (there are quite a few!) via `:macroexpand` `:hook`. This is a good first pass, we'll likely swing around again and create proper clj-kondo hooks in an clj-kondo export config for fine grained reporting for our users. Closes clj-commons#390
- Loading branch information
Showing
17 changed files
with
217 additions
and
98 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
.clj-kondo/clj-kondo/slingshot/clj_kondo/slingshot/try_plus.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns clj-kondo.slingshot.try-plus | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn expand-catch [catch-node] | ||
(let [[catch catchee & exprs] (:children catch-node) | ||
catchee-sexpr (api/sexpr catchee)] | ||
(cond (vector? catchee-sexpr) | ||
(let [[selector & exprs] exprs] | ||
(api/list-node | ||
[catch (api/token-node 'Exception) (api/token-node '_e#) | ||
(api/list-node | ||
(list* (api/token-node 'let) | ||
(api/vector-node [selector (api/token-node nil)]) | ||
exprs))])) | ||
:else catch-node))) | ||
|
||
(defn try+ [{:keys [node]}] | ||
(let [children (rest (:children node)) | ||
[body catches] | ||
(loop [body children | ||
body-exprs [] | ||
catches []] | ||
(if (seq body) | ||
(let [f (first body) | ||
f-sexpr (api/sexpr f)] | ||
(if (and (seq? f-sexpr) (= 'catch (first f-sexpr))) | ||
(recur (rest body) | ||
body-exprs | ||
(conj catches (expand-catch f))) | ||
(recur (rest body) | ||
(conj body-exprs f) | ||
catches))) | ||
[body-exprs catches])) | ||
new-node (api/list-node | ||
[(api/token-node 'let) | ||
(api/vector-node | ||
[(api/token-node '&throw-context) (api/token-node nil)]) | ||
(api/token-node '&throw-context) ;; use throw-context to avoid warning | ||
(with-meta (api/list-node (list* (api/token-node 'try) | ||
(concat body catches))) | ||
(meta node))])] | ||
;; (prn (api/sexpr new-node)) | ||
{:node new-node})) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:hooks | ||
{:analyze-call {slingshot.slingshot/try+ clj-kondo.slingshot.try-plus/try+}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{:config-paths ^:replace [] ;; don't adopt any user preferences | ||
|
||
:hooks | ||
;; for now we'll use the simple macroexpand, can move to hooks for finer grained errors later | ||
{:macroexpand | ||
{etaoin.util/defmethods etaoin.util/defmethods | ||
etaoin.util/with-tmp-dir etaoin.util/with-tmp-dir | ||
etaoin.util/with-tmp-file etaoin.util/with-tmp-file | ||
|
||
etaoin.api/with-key-down etaoin.api/with-key-down | ||
etaoin.api/with-pointer-btn-down etaoin.api/with-pointer-btn-down | ||
etaoin.api/with-pointer-left-btn-down etaoin.api/with-pointer-left-btn-down | ||
etaoin.api/with-driver etaoin.api/with-driver | ||
etaoin.api/with-chrome etaoin.api/with-chrome | ||
etaoin.api/with-firefox etaoin.api/with-firefox}} | ||
|
||
:linters | ||
;; etaoin is dsl-ish and does make use of :refer :all, can decide if we like that at some later date | ||
{:refer-all {:level :off}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns etaoin.api) | ||
|
||
(defmacro with-key-down | ||
[input key & body] | ||
`(-> ~input | ||
(add-key-down ~key) | ||
~@body | ||
(add-key-up ~key))) | ||
|
||
(defmacro with-pointer-btn-down | ||
[input button & body] | ||
`(-> ~input | ||
(add-pointer-down ~button) | ||
~@body | ||
(add-pointer-up ~button))) | ||
|
||
(defmacro with-pointer-left-btn-down | ||
[input & body] | ||
`(-> ~input | ||
add-pointer-down | ||
~@body | ||
add-pointer-up)) | ||
|
||
;; simplified to remove with-pool which is of no consequence to linting | ||
(defmacro with-driver | ||
[type opt bind & body] | ||
`(let [~bind (boot-driver ~type ~opt)] | ||
(try | ||
~@body | ||
(finally | ||
(quit ~bind))))) | ||
|
||
(defmacro with-firefox | ||
[opt bind & body] | ||
`(with-driver :firefox ~opt ~bind | ||
~@body)) | ||
|
||
(defmacro with-chrome | ||
[opt bind & body] | ||
`(with-driver :chrome ~opt ~bind | ||
~@body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns etaoin.util) | ||
|
||
(defmacro defmethods | ||
"Declares multimethods in batch. For each dispatch value from | ||
dispatch-vals, creates a new method." | ||
[multifn dispatch-vals & fn-tail] | ||
`(doseq [dispatch-val# ~dispatch-vals] | ||
(defmethod ~multifn dispatch-val# ~@fn-tail))) | ||
|
||
;; essence only for linting | ||
(defmacro with-tmp-file [prefix suffix bind & body] | ||
`(let [~bind "somepath"] | ||
~@body)) | ||
|
||
;; essence only for linting | ||
(defmacro with-tmp-dir [prefix bind & body] | ||
`(let [~bind "somepath"] | ||
~@body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
#_{:clj-kondo/ignore [:use]} | ||
(use 'etaoin.api) | ||
(require '[etaoin.keys :as k]) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.