-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.cpcache | ||
.lsp/.cache | ||
.clj-kondo/.cache | ||
.clj-kondo/* | ||
!.clj-kondo/config.edn | ||
.clojuredart | ||
.dart_tool | ||
.packages | ||
|
1 change: 1 addition & 0 deletions
1
resources/clj-kondo.exports/tensegritics/clojuredart/config.edn
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 @@ | ||
{:hooks {:analyze-call {cljd.flutter.alpha/widget hooks.flutter/widget}}} |
53 changes: 53 additions & 0 deletions
53
resources/clj-kondo.exports/tensegritics/clojuredart/hooks/flutter.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,53 @@ | ||
(ns hooks.flutter | ||
(:require [clj-kondo.hooks-api :as api] | ||
[clojure.set :as set] | ||
[clojure.string :as str])) | ||
|
||
(defn widget | ||
"Hook for cljd.flutter.alpha/widget macro" | ||
[{:keys [:node]}] | ||
(let [args (rest (:children node)) | ||
opts-nodes (take-while (comp api/keyword-node? first) (partition 2 args)) | ||
pairs->value (fn [k] (first (filter #(-> % first (api/sexpr) (= k)) opts-nodes))) | ||
[_ state] (pairs->value :state) | ||
[_ context] (pairs->value :context) | ||
[_ watch] (pairs->value :watch) | ||
[_ key] (pairs->value :key) | ||
|
||
bindings-count (* 2 (count opts-nodes)) | ||
body (drop bindings-count args) | ||
error (fn [msg] (throw (ex-info msg {}))) | ||
unknown-keys (set/difference | ||
(into #{} (map (comp api/sexpr first) opts-nodes)) | ||
#{:state :key :watch :context})] | ||
|
||
(cond | ||
(and (seq (filter api/keyword-node? args)) ; has top keywords | ||
(not (api/keyword-node? (first args)))) ; but first form is not a keyword | ||
(error (str "Unknown first form " (api/sexpr (first args)))) | ||
|
||
(and state watch) | ||
(error ":state and :watch option keys are mutually exclusive") | ||
|
||
(and state (or (not (api/vector-node? state)) | ||
(not= (count (:children state)) 2) | ||
(not (-> state :children first api/token-node?)))) | ||
(error ":state should be a vector [name initial-value]") | ||
|
||
(seq unknown-keys) | ||
(error (str "Unsupported option keys " (str/join " " unknown-keys))) | ||
|
||
(= 0 (- (count args) bindings-count)) | ||
(error (str "No body provided")) | ||
|
||
:else | ||
{:node (api/list-node | ||
(list | ||
(api/token-node 'let) | ||
(api/vector-node (concat (if context | ||
[context (api/token-node 'identity)] | ||
[]) | ||
(:children state))) | ||
watch ;; to lint 'watch and 'key | ||
key | ||
body))}))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What examples do you think may become a false positive?
![image](https://user-images.githubusercontent.com/14236531/164402263-593d7724-ea3a-46e2-a125-4432d6960133.png)
Only when there is a key-word pair, it raises an exception