blob: 4525ff79975ea25f3c49f9650756f2da49b139cd (
plain)
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
34
35
36
|
(ns clarktown.correctors.list-block
(:require
[clojure.string :as string]
[clarktown.matchers.list-block :as matcher]))
(defn newline-above?
"Determines whether there's a need for an empty new line
above the `line` at the current `index`. In the list block
case that's when the above line is not a newline and is not
a list block line."
[lines line index]
(and (matcher/match? line)
(> index 0)
(nil? (-> (nth lines (- index 1))
string/trim
matcher/match?))
(not (= (-> (nth lines (- index 1))
string/trim)
""))))
(defn newline-below?
"Determines whether there's a need for an empty new line
above the `line` at the current `index`. In the list block
case that's when the below line is not a newline and is not
a list block line."
[lines line index]
(and (matcher/match? line)
(> (- (count lines) 1) index)
(nil? (-> (nth lines (+ index 1))
string/trim
matcher/match?))
(not (= (-> (nth lines (+ index 1))
string/trim)
""))))
|