0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-13 07:21:40 -05:00

Resolve almost all linter issues on common module.

This commit is contained in:
Andrey Antukh 2021-05-31 09:06:14 +02:00 committed by Andrés Moya
parent 548664f6ce
commit 2ec769981a
18 changed files with 86 additions and 89 deletions

View file

@ -1,7 +1,12 @@
{:lint-as {potok.core/reify clojure.core/reify
promesa.core/let clojure.core/let
rumext.alpha/defc clojure.core/defn
app.common.data/export clojure.core/def
app.db/with-atomic clojure.core/with-open}
:hooks
{:analyze-call {app.common.data/export hooks.export/export}}
:output
{:exclude-files ["data_readers.clj"]}

View file

@ -0,0 +1,11 @@
(ns hooks.export
(:require [clj-kondo.hooks-api :as api]))
(defn export
[{:keys [:node]}]
(let [[_ sname] (:children node)
result (api/list-node
[(api/token-node (symbol "def"))
(api/token-node (symbol (name (:value sname))))
sname])]
{:node result}))

View file

@ -10,14 +10,15 @@
#?(:cljs
(:require-macros [app.common.data]))
(:require
[linked.set :as lks]
[app.common.math :as mth]
[clojure.set :as set]
#?(:clj [cljs.analyzer.api :as aapi])
#?(:cljs [cljs.reader :as r]
:clj [clojure.edn :as r])
#?(:cljs [cljs.core :as core]
:clj [clojure.core :as core]))
:clj [clojure.core :as core])
[linked.set :as lks])
#?(:clj
(:import linked.set.LinkedSet)))
@ -482,8 +483,8 @@
"
[m1 m2]
(let [m1ks (keys m1)
m2ks (keys m2)
(let [m1ks (set (keys m1))
m2ks (set (keys m2))
keys (set/union m1ks m2ks)
diff-attr

View file

@ -46,7 +46,7 @@
(assoc-in stack [:items index] value))
(defn undo
[{index :index items :items :as stack}]
[stack]
(update stack :index dec))
(defn redo
@ -56,5 +56,5 @@
(update :index inc)))
(defn size
[{index :index items :items :as stack}]
[{index :index :as stack}]
(inc index))

View file

@ -6,9 +6,9 @@
(ns app.common.geom.align
(:require
[clojure.spec.alpha :as s]
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.common.data :as d]))
[clojure.spec.alpha :as s]))
;; --- Alignment

View file

@ -8,10 +8,8 @@
(:require
#?(:cljs [cljs.pprint :as pp]
:clj [clojure.pprint :as pp])
[cuerdas.core :as str]
[app.common.data :as d]
[app.common.math :as mth]
[app.common.geom.point :as gpt]))
[app.common.geom.point :as gpt]
[app.common.math :as mth]))
;; --- Matrix Impl

View file

@ -7,14 +7,13 @@
(ns app.common.geom.shapes
(:require
[app.common.data :as d]
[app.common.math :as mth]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.intersect :as gin]
[app.common.geom.shapes.path :as gsp]
[app.common.geom.shapes.rect :as gpr]
[app.common.geom.shapes.transforms :as gtr]
[app.common.geom.shapes.intersect :as gin]
[app.common.spec :as us]))

View file

@ -6,9 +6,8 @@
(ns app.common.geom.shapes.intersect
(:require
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as gpp]
[app.common.geom.shapes.rect :as gpr]
[app.common.math :as mth]))
@ -113,11 +112,10 @@
;; Even-odd algorithm
;; Cast a ray from the point in any direction and count the intersections
;; if it's odd the point is inside the polygon
(let []
(->> lines
(filter #(intersect-ray? p %))
(count)
(odd?))))
(->> lines
(filter #(intersect-ray? p %))
(count)
(odd?)))
(defn- next-windup
"Calculates the next windup number for the nonzero algorithm"
@ -173,7 +171,7 @@
(defn overlaps-path?
"Checks if the given rect overlaps with the path in any point"
[shape rect]
(let [;; If paths are too complex the intersection is too expensive
;; we fallback to check its bounding box otherwise the performance penalty
;; is too big
@ -186,7 +184,7 @@
(points->lines (:points shape))
(gpp/path->lines shape))
start-point (-> shape :content (first) :params (gpt/point))]
(or (is-point-inside-nonzero? (first rect-points) path-lines)
(is-point-inside-nonzero? start-point rect-lines)
(intersects-lines? rect-lines path-lines))))
@ -197,14 +195,14 @@
(let [center (gpt/point cx cy)
transform (gmt/transform-in center transform)
{px :x py :y} (gpt/transform point transform)]
;; Ellipse inequality formula
;; https://en.wikipedia.org/wiki/Ellipse#Shifted_ellipse
(let [v (+ (/ (mth/sq (- px cx))
(mth/sq rx))
(/ (mth/sq (- py cy))
(mth/sq ry)))]
(<= v 1))))
{px :x py :y} (gpt/transform point transform)
;; Ellipse inequality formula
;; https://en.wikipedia.org/wiki/Ellipse#Shifted_ellipse
v (+ (/ (mth/sq (- px cx))
(mth/sq rx))
(/ (mth/sq (- py cy))
(mth/sq ry)))]
(<= v 1)))
(defn intersects-line-ellipse?
"Checks wether a single line intersects with the given ellipse"
@ -272,13 +270,13 @@
center (gpt/point (+ x (/ width 2))
(+ y (/ height 2)))
ellipse-data {:cx (:x center)
:cy (:y center)
:rx (/ width 2)
:ry (/ height 2)
:transform (:transform-inverse shape)}]
(or (is-point-inside-evenodd? center rect-lines)
(is-point-inside-ellipse? (first rect-points) ellipse-data)
(intersects-lines-ellipse? rect-lines ellipse-data))))

View file

@ -6,10 +6,10 @@
(ns app.common.geom.shapes.path
(:require
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.rect :as gpr]
[app.common.math :as mth]
[app.common.data :as d]))
[app.common.math :as mth]))
(defn content->points [content]
(->> content
@ -79,7 +79,7 @@
;; When the term a is close to zero we have a linear equation
[(/ (- c) b)]
;; If a is not close to zero return the two roots for a cuadratic
;; If a is not close to zero return the two roots for a cuadratic
(not (mth/almost-zero? a))
[(/ (+ (- b) sqrt-b2-4ac)
(* 2 a))
@ -267,7 +267,7 @@
(and (< (d ht) (d t1)) (< (d ht) (d t2)))
[ht1 ht2]
(< (d t1) (d t2))
[t1 ht]
@ -324,7 +324,7 @@
(if (and (some? acc) (or (not cur) (<= min-dist cur-dist)))
[min-p min-dist]
[cur-p cur-dist]))]
(->> (:content shape)
(d/with-prev)
(map point+distance)

View file

@ -7,13 +7,13 @@
(ns app.common.geom.shapes.transforms
(:require
[app.common.attrs :as attrs]
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.path :as gpa]
[app.common.geom.shapes.rect :as gpr]
[app.common.math :as mth]
[app.common.data :as d]
[app.common.text :as txt]))
;; --- Relative Movement
@ -58,12 +58,6 @@
dy (- (d/check-num y) (-> shape :selrect :y))]
(move shape (gpt/point dx dy))))
(defn- modif-rotation [shape]
(let [cur-rotation (d/check-num (:rotation shape))
delta-angle (d/check-num (get-in shape [:modifiers :rotation]))]
(mod (+ cur-rotation delta-angle) 360)))
(defn transform-matrix
"Returns a transformation matrix without changing the shape properties.
The result should be used in a `transform` attribute in svg"
@ -86,14 +80,13 @@
(gpt/point 0 0))]
(inverse-transform-matrix shape shape-center)))
([{:keys [flip-x flip-y] :as shape} center]
(let []
(-> (gmt/matrix)
(gmt/translate center)
(cond->
flip-x (gmt/scale (gpt/point -1 1))
flip-y (gmt/scale (gpt/point 1 -1)))
(gmt/multiply (:transform-inverse shape (gmt/matrix)))
(gmt/translate (gpt/negate center))))))
(-> (gmt/matrix)
(gmt/translate center)
(cond->
flip-x (gmt/scale (gpt/point -1 1))
flip-y (gmt/scale (gpt/point 1 -1)))
(gmt/multiply (:transform-inverse shape (gmt/matrix)))
(gmt/translate (gpt/negate center)))))
(defn transform-point-center
"Transform a point around the shape center"
@ -333,8 +326,9 @@
(dissoc :modifiers))))
shape)))
;; TODO: looks like orig-shape is useless argument
(defn apply-text-resize
[shape orig-shape modifiers]
[shape _orig-shape modifiers]
(if (and (= (:type shape) :text)
(:resize-scale-text modifiers))
(let [merge-attrs (fn [attrs]
@ -376,7 +370,7 @@
:y (- (:y new-selrect 0) (:y selrect 0))
:width (- (:width new-selrect 1) (:width selrect 1))
:height (- (:height new-selrect 1) (:height selrect 1))}]
(cond-> group
(and (some? svg-viewbox) (some? selrect) (some? new-selrect))
(update :svg-viewbox
@ -388,9 +382,6 @@
(defn update-group-selrect [group children]
(let [shape-center (gco/center-shape group)
transform (:transform group (gmt/matrix))
transform-inverse (:transform-inverse group (gmt/matrix))
;; Points for every shape inside the group
points (->> children (mapcat :points))

View file

@ -9,12 +9,11 @@
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.pages.spec :as ps]
[app.common.spec :as us]
[app.common.pages.common :refer [component-sync-attrs]]
[app.common.pages.helpers :as cph]
[app.common.pages.init :as init]
[app.common.pages.spec :as spec]))
[app.common.pages.spec :as spec]
[app.common.spec :as us]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Page Transformation Changes
@ -33,7 +32,7 @@
(when verify?
(us/assert ::spec/changes items))
(let [pages (into #{} (map :page-id) items)
(let [pages (into #{} (map :page-id) items)
result (->> items
(reduce #(or (process-change %1 %2) %1) data))]
@ -42,7 +41,7 @@
(doseq [page-id pages]
(let [page (get-in result [:pages-index page-id])]
(doseq [[id shape] (:objects page)]
(if-not (= shape (get-in data [:pages-index page-id :objects id]))
(when-not (= shape (get-in data [:pages-index page-id :objects id]))
;; If object has change verify is correct
(us/verify ::spec/shape shape))))))

View file

@ -10,7 +10,6 @@
[app.common.geom.shapes :as gsh]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[clojure.set :as set]
[cuerdas.core :as str]))
(defn walk-pages
@ -119,14 +118,14 @@
(conj! pending current)
(first children)
(rest children))
[result pending]))]
[result pending]))
;; If we have still pending, advance the iterator
(let [length (count pending)]
(if (pos? length)
(let [next (get pending (dec length))]
(recur result (pop! pending) next))
(persistent! result))))))
;; If we have still pending, advance the iterator
length (count pending)]
(if (pos? length)
(let [next (get pending (dec length))]
(recur result (pop! pending) next))
(persistent! result)))))
(defn get-children-objects
"Retrieve all children objects recursively for a given object"
@ -403,14 +402,14 @@
[objects shape-id]
(let [shape (get objects shape-id)
parent (get objects (:parent-id shape))
[parent-idx _] (d/seek (fn [[idx child-id]] (= child-id shape-id))
[parent-idx _] (d/seek (fn [[_idx child-id]] (= child-id shape-id))
(d/enumerate (:shapes parent)))]
parent-idx))
(defn split-path
[path]
"Decompose a string in the form 'one / two / three' into
an array of strings, normalizing spaces."
[path]
(->> (str/split path "/")
(map str/trim)
(remove str/empty?)))

View file

@ -7,7 +7,6 @@
(ns app.common.pages.indices
(:require
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as helpers]
[app.common.uuid :as uuid]
[clojure.set :as set]))
@ -100,7 +99,8 @@
"Retrieves the mask information for an object"
[objects parents-index]
(let [retrieve-masks
(fn [id parents]
(fn [_ parents]
;; TODO: use transducers?
(->> parents
(map #(get objects %))
(filter #(:masked-group? %))

View file

@ -7,9 +7,9 @@
(ns app.common.pages.init
(:require
[app.common.data :as d]
[app.common.uuid :as uuid]
[app.common.exceptions :as ex]
[app.common.pages.common :refer [file-version default-color]]))
[app.common.pages.common :refer [file-version default-color]]
[app.common.uuid :as uuid]))
(def root uuid/zero)

View file

@ -6,13 +6,13 @@
(ns app.common.pages.migrations
(:require
[app.common.pages :as cp]
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp]
[app.common.geom.matrix :as gmt]
[app.common.math :as mth]
[app.common.uuid :as uuid]
[app.common.data :as d]))
[app.common.pages :as cp]
[app.common.uuid :as uuid]))
;; TODO: revisit this and rename to file-migrations
@ -94,7 +94,7 @@
(= :curve (:type object))
(assoc :type :path)
(or (#{:curve :path} (:type object)))
(#{:curve :path} (:type object))
(migrate-path)
(= :frame (:type object))

View file

@ -11,11 +11,9 @@
(:require
#?(:clj [clojure.spec.alpha :as s]
:cljs [cljs.spec.alpha :as s])
[expound.alpha :as expound]
[app.common.uuid :as uuid]
[app.common.exceptions :as ex]
[app.common.geom.point :as gpt]
[app.common.uuid :as uuid]
[cuerdas.core :as str]))
(s/check-asserts true)

View file

@ -6,8 +6,6 @@
(ns app.common.text
(:require
[app.common.attrs :as attrs]
[app.common.uuid :as uuid]
[app.common.data :as d]
[app.common.transit :as t]
[clojure.walk :as walk]

View file

@ -212,5 +212,5 @@
[v]
(try
(-> v decode-str nil? not)
(catch #?(:cljs js/SyntaxError :clj Exception) e
(catch #?(:cljs js/SyntaxError :clj Exception) _e
false)))