-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clj-kondo support for cljd.flutter.alpha/widget #29
Conversation
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn widget [{:keys [:node]}] | ||
(let [[state-key binding-vec & body] (rest (:children node)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: also support :key, :watch and :context done
|
(seq unknown-keys) | ||
(error (str "Unknown keys " (str/join " " unknown-keys))) | ||
|
||
(not= 1 (- (count args) bindings-count)) ;; body is the one that remains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
body length can be anything, even if it will be most of the time 1, it may be more in case of side-effects, a length of 0 would be most certainly an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will see what else could be done, today evening
(error (str "Unknown values")) | ||
|
||
:else | ||
(let [check-symbols #{:watch :key} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what's this function must return. There seems to be keywords in binding position in the generated let.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it returns something like:
(let [context-name-user-provided identity ; if user privides context
state-name state-value ; if user provides a state
]
;; need it to check if these symbols exist
watch ; could be nil
key ; could be nil
(widget. (body. (creation. )))
33b6b39
to
f19217c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could add the symbol check on state name, merge all state checks in one single branch that would be perfect and I would merge.
I also provided variants to your messages.
Thanks!
#{:state :key :watch :context})] | ||
|
||
(cond | ||
(and (seq (filter api/keyword-node? args)) ; has top keywords |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could raise some false positive but it's so unlikely and useless that's ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and state (not (api/vector-node? state))) | ||
(error "State should be a vector [name initial-value]") | ||
|
||
(and state (not= (count (:children state)) 2)) | ||
(error "State should contain only one name-value pair") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these two branches should be merged and the error message should read ":state should be a vector [name initial-value]"
. Btw you should also check in that branch that name is a simple symbol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(error "State should contain only one name-value pair") | ||
|
||
(seq unknown-keys) | ||
(error (str "Unknown keys " (str/join " " unknown-keys))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unsupported option keys: "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(error (str "Unknown first form " (api/sexpr (first args)))) | ||
|
||
(and state watch) | ||
(error "State and watch keys are mutually exclusive") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
":state and :watch option keys are mutually exclusive."
But doesn’t the let allow for destructuring too?
Christophe Grand
Le 21 avr. 2022 à 09:28, Artur Dumchev ***@***.***> a écrit :
@Liverm0r commented on this pull request.
--------------------------------
In resources/clj-kondo.exports/tensegritics/clojuredart/hooks/flutter.clj <#29 (comment)> :
+ (and state (not (api/vector-node? state)))
+ (error "State should be a vector [name initial-value]")
+
+ (and state (not= (count (:children state)) 2))
+ (error "State should contain only one name-value pair")
Ok, I will merge them.
As for symbol name — it's already checked by the let form:
—
Reply to this email directly, view it on GitHub <#29 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAALPMKVFIJTE3DBCQT5KVTVGD7QZANCNFSM5TZTSSYQ> .
You are receiving this because your review was requested. <https://github.com/notifications/beacon/AAALPMMRD6HDHD5P243FR2LVGD7QZA5CNFSM5TZTSSY2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOHCB7QYQ.gif> Message ID: ***@***.***>
|
I see, didn't think about destructuring. I will fix it too. |
I decided to use /hooks as a directory inside
clj-kondo.exports/<your-org>/<your-libname>/
somewhat like sicmutils does.
Why is .git ignore changed?
Without it there would be generated files:
![image](https://user-images.githubusercontent.com/14236531/164066438-0c26e775-e9c4-41fc-8ebc-6dcc47484fbd.png)
It doesn't depend on my implementation, I checked better-cond, there is the same problem after opening it's files with lsp running:
![image](https://user-images.githubusercontent.com/14236531/164066922-a463f9df-4cd3-4bad-b8ee-1355ce37591a.png)
Where does it started?
https://clojurians.slack.com/archives/C03A6GE8D32/p1650354879575349
Links to check