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.
Export config uses call hooks for better error reporting for users of our public API. Still using macro expand hooks for internal only macros. Using the brand spanking new `.clj_kondo` extension for hook source. This is nice to keep tooling less confused, but also keeps my brain less confused. Etaoin has a relatively large number of macros. I think I hit the important ones. But some macros are not under test and not verified by me as clj-kondo friendly. We'll add in support for any uncovered macros as needed. Ran a lint and turfed an unused var. Also added a sanity test for an etaoin.api2 macro. Added the lint task as a job to our CI build matrix. This helps to verify our clj-kondo config. Closes clj-commons#413
- Loading branch information
Showing
12 changed files
with
134 additions
and
70 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{:hooks | ||
{:analyze-call | ||
{etaoin.api/with-chrome etaoin.api/with-browser | ||
etaoin.api/with-firefox etaoin.api/with-browser | ||
etaoin.api/with-chrome-headless etaoin.api/with-browser | ||
etaoin.api/with-edge etaoin.api/with-browser | ||
etaoin.api/with-edge-headless etaoin.api/with-browser | ||
etaoin.api/with-phantom etaoin.api/with-browser | ||
etaoin.api/with-safari etaoin.api/with-browser | ||
|
||
etaoin.api/with-driver etaoin.api/with-driver | ||
etaoin.api/with-key-down etaoin.api/with-key-down | ||
etaoin.api/with-pointer-btn-down etaoin.api/with-pointer-btn-down | ||
|
||
;; api2 moves to a more conventional let-ish vector syntax | ||
etaoin.api2/with-chrome etaoin.api2/with-browser | ||
etaoin.api2/with-chrome-headless etaoin.api2/with-browser | ||
etaoin.api2/with-edge etaoin.api2/with-browser | ||
etaoin.api2/with-edge-headless etaoin.api2/with-browser | ||
etaoin.api2/with-firefox etaoin.api2/with-browser | ||
etaoin.api2/with-firefox-headless etaoin.api2/with-browser | ||
etaoin.api2/with-phantom etaoin.api2/with-browser | ||
etaoin.api2/with-safari etaoin.api2/with-browser}} | ||
:lint-as | ||
{etaoin.api/with-pointer-left-btn-down clojure.core/->}} |
53 changes: 53 additions & 0 deletions
53
resources/clj-kondo.exports/etaoin/etaoin/etaoin/api.clj_kondo
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,53 @@ | ||
(ns etaoin.api | ||
(:require [clj-kondo.hooks-api :as api] | ||
[etaoin.hooks-util :as h])) | ||
|
||
(defn- with-bound-arg [node bound-arg-ndx] | ||
(let [macro-args (rest (:children node)) | ||
binding-sym (nth macro-args bound-arg-ndx nil)] | ||
(if-not (h/symbol-node? binding-sym) | ||
;; could use clj-kondo findings, but I think this is good for now | ||
(throw (ex-info (format "Expected binding symbol as %s arg" | ||
;; use words instead of numbers to avoid ambiguity | ||
(case 1 "second" | ||
2 "third")) {})) | ||
(let [leading-args (take bound-arg-ndx macro-args) | ||
body (drop (inc bound-arg-ndx) macro-args)] | ||
{:node (api/list-node | ||
(list* | ||
(api/token-node 'let) | ||
;; simulate the effect, macro is creating a new thing (driver for example) | ||
;; via binding it. I don't think the bound value matters for the linting process | ||
(api/vector-node [binding-sym (api/map-node [])]) | ||
;; reference the other args so that they are not linted as unused | ||
(api/vector-node leading-args) | ||
body))})))) | ||
|
||
(defn- with-x-down [node] | ||
(let [macro-args (rest (:children node)) | ||
[leading-args body] (split-at 2 macro-args)] | ||
{:node (api/list-node | ||
(list* | ||
(api/token-node 'do) | ||
;; dump the body | ||
(api/list-node (list* body)) | ||
;; reference the other args so that they are not linted as unused (if they happen to be symbols) | ||
(api/vector-node leading-args)))})) | ||
|
||
(defn with-browser | ||
"Covers etaoin.api/with-chrome and all its variants | ||
[opt bind & body]" | ||
[{:keys [node]}] | ||
(with-bound-arg node 1)) | ||
|
||
(defn with-driver | ||
"Very similar to with-browser but bound arg is 1 deeper | ||
[type opt bind & body]" | ||
[{:keys [node]}] | ||
(with-bound-arg node 2)) | ||
|
||
(defn with-key-down [{:keys [node]}] | ||
(with-x-down node)) | ||
|
||
(defn with-pointer-btn-down [{:keys [node]}] | ||
(with-x-down node)) |
27 changes: 27 additions & 0 deletions
27
resources/clj-kondo.exports/etaoin/etaoin/etaoin/api2.clj_kondo
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,27 @@ | ||
(ns etaoin.api2 | ||
(:require [clj-kondo.hooks-api :as api] | ||
[etaoin.hooks-util :as h])) | ||
|
||
(defn with-browser | ||
"Newer variants for api2 | ||
[[bind & [options]] & body]" | ||
[{:keys [node]}] | ||
(let [macro-args (rest (:children node)) | ||
binding-like-vector (first macro-args)] | ||
(if-not (api/vector-node? binding-like-vector) | ||
;; could use clj-kondo findings, but I think this is good for now | ||
(throw (ex-info "Expected vector for first arg" {})) | ||
(let [binding-sym (-> binding-like-vector :children first)] | ||
(if-not (h/symbol-node? binding-sym) | ||
(throw (ex-info "Expected binding symbol for first arg in vector" {})) | ||
(let [other-args (rest binding-like-vector) | ||
body (rest macro-args)] | ||
{:node (api/list-node | ||
(list* | ||
(api/token-node 'let) | ||
;; simulate the effect, macro is creating a new thing (driver for example) | ||
;; via binding it. I don't think the bound value matters for the linting process | ||
(api/vector-node [binding-sym (api/map-node [])]) | ||
;; reference the other args so that they are not linted as unused | ||
(api/vector-node other-args) | ||
body))})))))) |
6 changes: 6 additions & 0 deletions
6
resources/clj-kondo.exports/etaoin/etaoin/etaoin/hooks_util.clj_kondo
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,6 @@ | ||
(ns etaoin.hooks-util | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn symbol-node? [node] | ||
(and (api/token-node? node) | ||
(symbol? (api/sexpr 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
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