Skip to content

Commit 186f1c6

Browse files
committed
feat(labdev): Add Vale rule to warn against improper sentence initial chars
1 parent ddb6789 commit 186f1c6

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
extends: script
3+
scope: raw
4+
level: warning
5+
message: "Don't start a sentence with a code literal, lowercase character, or number"
6+
script: SentenceStarters.tengo
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
text := import("text")
2+
3+
matches := []
4+
lines := text.split(scope, "\n")
5+
6+
starts := []
7+
run := 0
8+
i := 0
9+
for i < len(lines) {
10+
line := lines[i]
11+
starts = append(starts, run)
12+
run = run + len(line) + 1
13+
i = i + 1
14+
}
15+
16+
j := 0
17+
inFence := false
18+
atBlockStart := true
19+
for j < len(lines) {
20+
current := text.trim_space(lines[j])
21+
22+
if current == "" {
23+
atBlockStart = true
24+
j = j + 1
25+
continue
26+
}
27+
28+
if text.re_match(`^(-{4,}|\.{4,}|={4,})$`, current) {
29+
inFence = !inFence
30+
atBlockStart = true
31+
j = j + 1
32+
continue
33+
}
34+
35+
if inFence {
36+
j = j + 1
37+
continue
38+
}
39+
40+
if text.re_match(`^\s`, lines[j]) ||
41+
text.re_match(`^include::`, current) ||
42+
text.re_match(`::`, current) {
43+
atBlockStart = false
44+
j = j + 1
45+
continue
46+
}
47+
48+
if text.re_match(`^\[[^\]]+\]$`, current) ||
49+
text.re_match(`^\[[A-Z]+\]$`, current) ||
50+
text.re_match(`^\.[^\s].*$`, current) ||
51+
text.re_match(`^[A-Za-z0-9_.-]+::\[[^\]]*\]$`, current) ||
52+
text.re_match(`^[:/]|^//|^ifdef::|^ifndef::|^endif::|^\||^\s*(?:[*+-]|\d+\.)`, current) {
53+
atBlockStart = false
54+
j = j + 1
55+
continue
56+
}
57+
58+
if !atBlockStart {
59+
j = j + 1
60+
continue
61+
}
62+
63+
normalized := text.re_replace(`^\[\.[^\]]+\]`, current, "")
64+
normalized = text.re_replace(`^pass:\[([^\]]*)\]`, normalized, "$1")
65+
normalized = text.re_replace(`^[*_#]+`, normalized, "")
66+
normalized = text.re_replace(`[*_#]+$`, normalized, "")
67+
normalized = text.trim_space(normalized)
68+
69+
if text.re_match(`^(?:` + "`[^`]+`" + `|[a-z0-9])`, normalized) {
70+
begin := starts[j] + text.index(lines[j], current)
71+
end := begin + len(current)
72+
matches = append(matches, {"begin": begin, "end": end})
73+
}
74+
75+
atBlockStart = false
76+
j = j + 1
77+
}

0 commit comments

Comments
 (0)