Skip to content

Commit

Permalink
Merge pull request #139 from leeebai/2.0.0
Browse files Browse the repository at this point in the history
release visualis 2.0.0
  • Loading branch information
leeebai committed Jun 27, 2024
2 parents b7ee967 + 7f9a14b commit 5b89506
Show file tree
Hide file tree
Showing 7,901 changed files with 1,354,316 additions and 219,731 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Empty file added .babel_cache/.gitkeep
Empty file.
27 changes: 27 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"plugins": ["@emotion"],
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"env": {
"development": {
"presets": []
},
"extract": {
"plugins": [
[
"ttag",
{
"extract": {
"output": "locales/metabase-frontend.pot"
},
"discover": ["t", "jt"],
"numberedExpressions": true
}
]
]
}
}
}
903 changes: 903 additions & 0 deletions .circleci/config.yml

Large diffs are not rendered by default.

459 changes: 459 additions & 0 deletions .clj-kondo/config.edn

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions .clj-kondo/hooks/metabase/api/common.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns hooks.metabase.api.common
(:require
[clj-kondo.hooks-api :as api]
[clojure.string :as str]))

(defn route-fn-name
[method route]
(let [route (if (vector? route) (first route) route)]
(-> (str (name method) route)
(str/replace #"/" "_")
symbol)))

(defn defendpoint [{:keys [node]}]
(let [[method route & body] (rest (:children node))]
{:node
(api/list-node [(api/token-node 'do)
;; register usage of compojure core var
(api/token-node (symbol (str "compojure.core")
(str method)))
;; define function with route-fn-name
(api/list-node (list* (api/token-node 'clojure.core/defn)
(route-fn-name (api/sexpr method) (api/sexpr route))
body))])}))
46 changes: 46 additions & 0 deletions .clj-kondo/hooks/metabase/models/setting.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(ns hooks.metabase.models.setting
(:require [clj-kondo.hooks-api :as hooks]))

(defn defsetting
"Rewrite a [[metabase.models.defsetting]] form like
(defsetting my-setting \"Description\" :type :boolean)
as
(let [_ \"Description\"
_ :type
_ :boolean]
(defn my-setting \"Docstring.\" [])
(defn my-setting! \"Docstring.\" [_value-or-nil]))
for linting purposes."
[{:keys [node]}]
(let [[setting-name & args] (rest (:children node))
;; (defn my-setting [] ...)
getter-node (-> (list
(hooks/token-node 'defn)
setting-name
(hooks/string-node "Docstring.")
(hooks/vector-node []))
hooks/list-node
(with-meta (meta setting-name)))
;; (defn my-setting! [_x] ...)
setter-node (-> (list
(hooks/token-node 'defn)
(with-meta
(hooks/token-node (symbol (str (:string-value setting-name) \!)))
(meta setting-name))
(hooks/string-node "Docstring.")
(hooks/vector-node [(hooks/token-node '_value-or-nil)]))
hooks/list-node
(with-meta (meta setting-name)))]
{:node (-> (list
(hooks/token-node 'let)
;; include description and the options map so they can get validated as well.
(hooks/vector-node (vec (interleave (repeat (hooks/token-node '_))
args)))
getter-node
setter-node)
hooks/list-node
(with-meta (meta node)))}))
148 changes: 148 additions & 0 deletions .clj-kondo/hooks/metabase/test/data.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
(ns hooks.metabase.test.data
(:require
[clj-kondo.hooks-api :as hooks]
[clojure.string :as str]
[clojure.walk :as walk]))

(defn- global-dataset-symbols
"Dataset definitions defined in [[metabase.test.data.dataset-definitions]]. This is only populated if clj-kondo has
cached analysis for that namespace -- so it may or may not be populated. If it is populated we can do a bit of extra
linting with that information."
[]
(not-empty (set (keys (:clj (hooks/ns-analysis 'metabase.test.data.dataset-definitions))))))

(defn- dataset-type
"`dataset` can be one of:
- a qualified symbol
- an unqualified symbol referring to a a var in [[metabase.test.data.dataset-definitions]]
- an unqualified symbol (referring to a let-bound value or a var in the current namespace
- some sort of non-symbol form like a function call
We can only determine if an unqualified symbol refers to something in the dataset definitions namespace if there are
cached results available from [[global-dataset-symbols]]."
[dataset]
(let [sexpr (hooks/sexpr dataset)
global-defs (global-dataset-symbols)]
(cond
(not (symbol? sexpr))
:non-symbol

(namespace sexpr)
:qualified

(empty? global-defs)
:unqualified/unknown

(contains? global-defs sexpr)
:unqualified/from-dataset-defs-namespace

;; either something defined in the current namespace or let-bound in the current scope.
:else
:unqualified/local-def)))

(defn dataset
[{{[_ dataset & body] :children} :node}]
(let [body (case (dataset-type dataset)
;; non-symbol, qualified symbols, and unqualified symbols from the current namespace/let-bound can all
;; get converted from something like
;;
;; (dataset whatever
;; ...)
;;
;; to
;;
;; (let [_ whatever]
;; ...)
(:non-symbol :qualified :unqualified/local-def)
(list* (hooks/token-node 'let)
(hooks/vector-node [(hooks/token-node '_) dataset])
body)

;; for ones that came from the dataset defs namespace or ones whose origin is unknown, just ignore them
;; and generate a `do` form:
;;
;; (do ...)
(:unqualified/from-dataset-defs-namespace :unqualified/unknown)
(list* (hooks/token-node 'do)
body))]
{:node (with-meta (hooks/list-node (with-meta body
(meta dataset)))
(meta dataset))}))

(defn- special-token-node?
"Whether this node is one of the special symbols like `$field`."
[node]
(when (hooks/token-node? node)
(let [symb (hooks/sexpr node)]
(and (symbol? symb)
(some (partial str/starts-with? symb)
#{"$" "!" "&" "*" "%"})
;; ignore args like `%` or `%1` inside function literals. $id forms have to be more than one character long,
;; and the first character won't be a number (hopefully -- maybe some DBs allow this -- but we don't use it)
(> (count (str symb)) 1)
(not (re-find #"^%\d+" (str symb)))))))

(defn- replace-$id-special-tokens
"Impl for [[$ids]] and [[mbql-query]]. Walk `form` and look for special tokens like `$field` and replace them with
strings so we don't get unresolved symbol errors. Preserves metadata."
[form]
;; [[walk/postwalk]] seems to preserve its meta so we don't need to do anything special
(walk/postwalk
(fn [node]
(if (special-token-node? node)
(-> (hooks/string-node (str (hooks/sexpr node)))
(with-meta (meta node)))
node))
form))

(defn $ids
[{{[_ & args] :children} :node}]
;; `$ids` accepts either
;;
;; ($ids form)
;;
;; or
;;
;; ($ids table & body)
;;
;; table is only relevant for expanding the special tokens so we can ignore it.
(let [body (if (= (count args) 1)
(first args)
(hooks/list-node
(list*
(hooks/token-node `do)
(rest args))))]
{:node (replace-$id-special-tokens body)}))

(defn mbql-query
[{{[_ & args] :children} :node}]
;; `mbql-query` accepts either
;;
;; (mbql-query table)
;;
;; or
;;
;; (mbql-query table query)
;;
;; and table may be `nil`.
;;
;; table is only relevant for expanding the special tokens so we can ignore it either way.
(let [[table query] (if (= (count args) 1)
[(first args)
(hooks/map-node [])]
args)]
(when-not ((some-fn symbol? nil?) (hooks/sexpr table))
(hooks/reg-finding! (assoc (meta table)
:message "First arg to mbql-query should be either a table name symbol or nil."
:type ::mbql-query-first-arg)))
(let [result (replace-$id-special-tokens query)
;; HACK I'm not sure WHY it works but I ran into https://github.com/clj-kondo/clj-kondo/issues/1773 when
;; trying to get this working -- for some magical reason wrapping the whole thing in a `do` form seems to fix
;; it. Once that bug is resolved we can go ahead and remove this line
result (with-meta (hooks/list-node (with-meta (list
(hooks/token-node 'do)
result)
(meta query)))
(meta query))]
{:node result})))
41 changes: 41 additions & 0 deletions .clj-kondo/hooks/metabase/test/util.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(ns hooks.metabase.test.util
(:require [clj-kondo.hooks-api :as hooks]))

(defn- namespaced-symbol-node? [node]
(when (hooks/token-node? node)
(let [symb (hooks/sexpr node)]
(and (symbol? symb)
(namespace symb)))))

(defn with-temporary-setting-values
"Rewrite a form like
(with-temporary-setting-values [x 1, some.ns/y 2]
...)
as one like
(let [_ 1, _ some.ns/y, _ 2]
...)
for analysis purposes. We only need to 'capture' namespaced Setting bindings with a `_` so Kondo considers their
namespace to be 'used' and to catch undefined var usage."
[{{[_ bindings & body] :children} :node}]
(let [bindings (if (hooks/vector-node? bindings)
(hooks/vector-node (into []
(mapcat (fn [[setting-name v]]
(concat
[(hooks/token-node '_) v]
;; if the setting name is namespace-qualified add a `_`
;; entry for it too.
(when (namespaced-symbol-node? setting-name)
[(hooks/token-node '_) setting-name]))))
(partition 2 (:children bindings))))
bindings)]
{:node (-> (list*
(hooks/token-node 'let)
bindings
body)
(with-meta (meta body))
hooks/list-node
(with-meta (meta body)))}))
24 changes: 24 additions & 0 deletions .clj-kondo/hooks/toucan/util/test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns hooks.toucan.util.test
(:require [clj-kondo.hooks-api :as api]))

(defn- with-temp-inner [body bindings]
(let [binding-infos (for [[model {[binding value] :children}] (partition 2 bindings)]
{:model model
:binding binding
:value (or value
(api/token-node 'nil))})]
(-> (api/vector-node
[(api/vector-node (map :model binding-infos))
(-> (api/list-node (list* (api/token-node `let)
(api/vector-node (mapcat (juxt :binding :value) binding-infos))
body))
(with-meta (meta body)))])
(with-meta (meta body)))))

(defn with-temp [{:keys [node]}]
(let [[_ db-ref binding+opts & body] (:children node)]
{:node (with-temp-inner body [db-ref binding+opts])}))

(defn with-temp* [{:keys [node]}]
(let [[_ bindings & body] (:children node)]
{:node (with-temp-inner body (:children bindings))}))
5 changes: 5 additions & 0 deletions .clj-kondo/macros/metabase/api/common.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns macros.metabase.api.common)

(defmacro define-routes [& args]
`(do (def ~'routes "docstring" nil)
~@args))
6 changes: 6 additions & 0 deletions .clj-kondo/macros/metabase/query_processor/streaming.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns macros.metabase.query-processor.streaming)

(defmacro streaming-response [[x y z] & body]
`(clojure.core/let [~x ~y]
~z
~@body))
20 changes: 20 additions & 0 deletions .clj-kondo/macros/quartz.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns macros.quartz)

(defmacro build-job
[& body]
`(let [jb# (org.quartz.JobBuilder/newJob)]
(clojurewerkz.quartzite.jobs/finalize (-> jb# ~@body))))

(defmacro build-trigger
[& body]
`(let [tb# (org.quartz.TriggerBuilder/newTrigger)]
(clojurewerkz.quartzite.triggers/finalize (-> tb# ~@body))))

(defmacro simple-schedule
[& body]
`(-> {} ~@body))

(defmacro schedule
[& body]
`(let [s# ~(first body)]
(-> s# ~@(rest body))))
6 changes: 6 additions & 0 deletions .clj-kondo/macros/toucan/models.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns macros.toucan.models)

(defmacro defmodel [model-name & _args]
`(do
(def ~model-name "Docstring." nil)
(defrecord ~(symbol (str model-name "Instance")) [])))
10 changes: 10 additions & 0 deletions .clj-kondo/test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns test
(:require [metabase.query-processor.streaming :as streaming]
[toucan.models :as models]))

(models/defmodel Card :foo)

(map->Card {:foo 1})
(map->CardInstance {:foo 1})

(streaming/streaming-response [x 1 (inc x)])
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mcr.microsoft.com/vscode/devcontainers/java:11

RUN apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com\
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends yarn

RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash
RUN apt-get update && apt-get -y install --no-install-recommends nodejs

RUN curl -O https://download.clojure.org/install/linux-install-1.11.0.1100.sh \
&& bash ./linux-install-1.11.0.1100.sh
17 changes: 17 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://aka.ms/vscode-remote/devcontainer.json
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000],

// Comment out the next line to run as root instead.
"remoteUser": "vscode"
}
Loading

0 comments on commit 5b89506

Please sign in to comment.