-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_linter.cljs
33 lines (29 loc) · 1.65 KB
/
example_linter.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns
^{:doc "Example Lighttable linter.
The Linter in this namespace is not automatically added to LT; you will need to add it manually to your user behaviors
file, using:
[:editor.markdown :lt.plugins.lt-lint/register-linter [:lt.plugins.example-linter/example-word-linter #{\"maybe\" \"open\" \"text\"}]]"}
lt.plugins.example-linter
(:require [lt.object :as object])
(:require-macros [lt.macros :refer [behavior]]))
(object/object* ::example-word-linter
:behaviors [::lint-words-in-editor]
:linter-name "Example word linter"
:init (fn [this ed words] (object/merge! this {:words words})))
(defn- lint-words
[editor-text words]
(let [words-to-find (set (map clojure.string/lower-case words))]
(apply concat (map-indexed (fn [line-no line]
(keep (fn [w]
(let [found-at (.indexOf (clojure.string/lower-case line) w)]
(when (<= 0 found-at)
{:message (str "You can't say the word " w "!")
:severity "error"
:from [line-no found-at]
:to [line-no (+ found-at (count w))]})))
words-to-find))
(clojure.string/split editor-text #"\n")))))
(behavior ::lint-words-in-editor
:triggers #{:lt.plugins.lt-lint/validate}
:reaction (fn [obj editor-text callback _]
(callback (lint-words editor-text (:words @obj)))))