@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 CHANGED
@@ -40,7 +40,7 @@
40
40
  "lint": "eslint .",
41
41
  "test": "mocha 'test/**/*.js' --timeout 60000"
42
42
  },
43
- "version": "0.7.0",
43
+ "version": "0.7.2",
44
44
  "dependencies": {
45
45
  "minimist": "^1.2.8"
46
46
  }
@@ -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(text);
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(text);
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. Nested mappings,
14
- * blank lines, and comments hold no keys and yield nothing.
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
- return this.text
23
- .split('\n')
24
- .map((line, index) => ({line, row: this.base + index}))
25
- .filter((spot) => /^[^\s#][^:]*:/u.test(spot.line))
26
- .map((spot) => {
27
- const colon = spot.line.indexOf(':');
28
- return {
29
- key: spot.line.slice(0, colon).trim(),
30
- value: spot.line.slice(colon + 1).trim(),
31
- row: spot.row
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