@yegor256/dogent 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/rules/polite.js +6 -2
- package/src/yaml.js +27 -14
package/package.json
CHANGED
package/src/rules/polite.js
CHANGED
|
@@ -38,8 +38,9 @@ class Polite {
|
|
|
38
38
|
}
|
|
39
39
|
scan(text, line, uri) {
|
|
40
40
|
const found = [];
|
|
41
|
+
const masked = this.mask(text);
|
|
41
42
|
const regex = /\b(?:please|kindly|feel free to|make sure to|be sure to|don't forget to|remember to|note that|it is important to)\b/giu;
|
|
42
|
-
let hit = regex.exec(
|
|
43
|
+
let hit = regex.exec(masked);
|
|
43
44
|
while (hit !== null) {
|
|
44
45
|
found.push(new Violation(
|
|
45
46
|
this.id,
|
|
@@ -47,10 +48,13 @@ class Polite {
|
|
|
47
48
|
`courtesy phrase "${hit[0]}" must be removed`,
|
|
48
49
|
new Region(uri, line, hit.index + 1)
|
|
49
50
|
));
|
|
50
|
-
hit = regex.exec(
|
|
51
|
+
hit = regex.exec(masked);
|
|
51
52
|
}
|
|
52
53
|
return found;
|
|
53
54
|
}
|
|
55
|
+
mask(text) {
|
|
56
|
+
return text.replace(/`[^`]*`/gu, (span) => ' '.repeat(span.length));
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
module.exports = Polite;
|
package/src/yaml.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* A frontmatter block read as a flat YAML mapping. Splits itself line by
|
|
12
12
|
* line and emits one pair per top-level "key: value", carrying the key,
|
|
13
|
-
* the value, and the absolute line the key sits on.
|
|
14
|
-
*
|
|
13
|
+
* the value, and the absolute line the key sits on. Folds a block scalar
|
|
14
|
+
* value ("|" or ">") from its indented continuation lines into one value.
|
|
15
|
+
* Nested mappings, blank lines, and comments hold no keys and yield nothing.
|
|
15
16
|
*/
|
|
16
17
|
class Yaml {
|
|
17
18
|
constructor(text, base) {
|
|
@@ -19,18 +20,30 @@ class Yaml {
|
|
|
19
20
|
this.base = base;
|
|
20
21
|
}
|
|
21
22
|
pairs() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.map((line, index) =>
|
|
25
|
-
.filter((
|
|
26
|
-
.map((
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
const lines = this.text.split('\n');
|
|
24
|
+
return lines
|
|
25
|
+
.map((line, index) => index)
|
|
26
|
+
.filter((index) => /^[^\s#][^:]*:/u.test(lines[index]))
|
|
27
|
+
.map((index) => this.pair(lines, index));
|
|
28
|
+
}
|
|
29
|
+
pair(lines, index) {
|
|
30
|
+
const colon = lines[index].indexOf(':');
|
|
31
|
+
const value = lines[index].slice(colon + 1).trim();
|
|
32
|
+
return {
|
|
33
|
+
key: lines[index].slice(0, colon).trim(),
|
|
34
|
+
value: /^[|>][+-]?\d*$/u.test(value) ? Yaml.fold(lines, index) : value,
|
|
35
|
+
row: this.base + index
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
static fold(lines, index) {
|
|
39
|
+
const rest = lines.slice(index + 1);
|
|
40
|
+
const stop = rest.findIndex((line) => line.trim() !== '' && !/^\s/u.test(line));
|
|
41
|
+
const end = stop === -1 ? rest.length : stop;
|
|
42
|
+
return rest
|
|
43
|
+
.slice(0, end)
|
|
44
|
+
.map((line) => line.trim())
|
|
45
|
+
.join(' ')
|
|
46
|
+
.trim();
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
49
|
|