Skip to content

Commit

Permalink
small code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Feb 25, 2024
1 parent 6cf28d9 commit b195bb8
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/stencil/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)

(defn ^PreparedTemplate prepare
(defn prepare
"Creates a prepared template instance from an input document."
[input]
^PreparedTemplate [input]
(cond
(instance? PreparedTemplate input) input
(nil? input) (throw (ex-info "Template is missing!" {}))
:else (API/prepare (io/file input))))


(defn- ^TemplateData make-template-data [x]
(defn- make-template-data ^TemplateData [x]
(if (map? x)
(TemplateData/fromMap ^Map (stringify-keys x))
(throw (ex-info (str "Unsupported template data type " (type x) "!")
{:template-data x}))))


(defn ^PreparedFragment fragment
(defn fragment
"Converts input to a fragment instance"
[f]
^PreparedFragment [f]
(cond
(instance? PreparedFragment f) f
(nil? f) (throw (ex-info "Fragment can not be null!" {}))
Expand Down
1 change: 1 addition & 0 deletions src/stencil/eval.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

(set! *warn-on-reflection* true)

#_{:clj-kondo/ignore [:unused-binding]}
(defmulti eval-step (fn [function data item] (:cmd item)))

(defmethod eval-step :default [_ _ item] [item])
Expand Down
1 change: 1 addition & 0 deletions src/stencil/functions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

(set! *warn-on-reflection* true)

#_{:clj-kondo/ignore [:unused-binding]}
(defmulti call-fn
"Extend this multimethod to make additional functions available from the template files.
The first argument is the lowercase function name which is used for dispatching the calls.
Expand Down
3 changes: 2 additions & 1 deletion src/stencil/grammar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

;; left-associative chained infix expression
(defn- chained [reader reader* reducer]
(fn [tokens] chained
(fn [tokens]
(when-let [[result tokens] (reader tokens)]
(loop [tokens tokens
result result]
Expand Down Expand Up @@ -58,6 +58,7 @@
(defn- optional [reader] ;; always matches
(fn [t] (or (reader t) [nil t])))

#_{:clj-kondo/ignore [:unresolved-symbol]}
(def testlang
(grammar [val (some-fn iden-or-fncall
(parenthesed expression)
Expand Down
2 changes: 1 addition & 1 deletion src/stencil/infix.clj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
(defmethod eval-tree :fncall [[_ f & args]]
(let [args (mapv eval-tree args)]
(try (apply call-fn (name f) args)
(catch clojure.lang.ArityException e
(catch clojure.lang.ArityException _
(throw (ex-info (format "Function '%s' was called with a wrong number of arguments (%d)" f (count args))
{:fn f :args args}))))))

Expand Down
2 changes: 1 addition & 1 deletion src/stencil/postprocess/fragments.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:import [stencil.types FragmentInvoke])
(:require [clojure.zip :as zip]
[clojure.data.xml :as xml]
[stencil.types :refer :all]
[stencil.types :refer [->FragmentInvoke control?]]
[stencil.ooxml :as ooxml]
[stencil.functions :refer [call-fn]]
[stencil.util :refer :all]))
Expand Down
2 changes: 1 addition & 1 deletion src/stencil/postprocess/html.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[stencil.functions :refer [call-fn]]
[stencil.postprocess.fragments :as fragments]
[stencil.types :refer [ControlMarker]]
[stencil.util :refer :all]
[stencil.util :refer [find-first dfs-walk-xml dfs-walk-xml-node]]
[stencil.ooxml :as ooxml]))

(set! *warn-on-reflection* true)
Expand Down
9 changes: 5 additions & 4 deletions src/stencil/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:import [java.io File])
(:require [clojure.spec.alpha :as s]
[stencil.model :as m]
[stencil.model.relations :as relations]
[stencil.process]))


Expand All @@ -13,10 +14,10 @@
(s/def ::data map?)

;; other types are also possible
(s/def :stencil.model/type #{stencil.model/rel-type-footer
stencil.model/rel-type-header
stencil.model/rel-type-main
stencil.model/rel-type-slide})
(s/def :stencil.model/type #{relations/rel-type-footer
relations/rel-type-header
relations/rel-type-main
relations/rel-type-slide})

(s/def :stencil.model/path (s/and string? not-empty #(not (.startsWith ^String % "/"))))

Expand Down
1 change: 1 addition & 0 deletions src/stencil/types.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

(def column-resize-modes #{:resize-first :resize-last :rational :cut})

#_{:clj-kondo/ignore [:redefined-var]}
(defn ->HideTableColumnMarker
([] (HideTableColumnMarker. :cut))
([x] (assert (column-resize-modes x))
Expand Down
4 changes: 2 additions & 2 deletions src/stencil/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(defn iterations [f elem] (eduction (take-while some?) (iterate f elem)))

;; same as (first (filter pred xs))
(defn find-first [pred xs] (reduce (fn [_ x] (if (pred x) (reduced x))) nil xs))
(defn find-first [pred xs] (reduce (fn [_ x] (when (pred x) (reduced x))) nil xs))
(defn find-last [pred xs] (reduce (fn [a x] (if (pred x) x a)) nil xs))

(def xml-zip
Expand Down Expand Up @@ -139,7 +139,7 @@
(defn whitespace? [c] (whitespace?? c))

;; like clojure.string/trim but supports a wider range of whitespace characters
(defn ^String trim [^CharSequence s]
(defn trim ^String [^CharSequence s]
(loop [right-idx (.length s)]
(if (zero? right-idx)
""
Expand Down

0 comments on commit b195bb8

Please sign in to comment.