@yegor256/dogent 0.7.6 → 0.7.8

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.6",
43
+ "version": "0.7.8",
44
44
  "dependencies": {
45
45
  "minimist": "^1.2.8"
46
46
  }
package/src/mask.js ADDED
@@ -0,0 +1,18 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: Copyright (c) 2026 Yegor Bugayenko
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ /**
9
+ * Mask.
10
+ *
11
+ * Blanks out inline-code spans inside a prose line so word-scanning
12
+ * rules never match quoted examples or filename templates. Each
13
+ * backtick run becomes equal-length spaces, keeping every column
14
+ * offset intact for the violations that survive.
15
+ */
16
+ const mask = (text) => text.replace(/`[^`]*`/gu, (span) => ' '.repeat(span.length));
17
+
18
+ module.exports = mask;
@@ -12,18 +12,20 @@ const Region = require('../region');
12
12
  * Atomic.
13
13
  *
14
14
  * Demands that every line carry exactly one instruction. A standalone
15
- * checker only spots the loud signs: a sentence terminator sitting
16
- * mid-line with more text after it, or two verb phrases welded together
17
- * with a semicolon, an " and ", or a " then ". The prompt hands the
18
- * subtler clause-counting to the AI oracle, which catches the
19
- * multi-instruction lines that carry no such welding token.
15
+ * checker spots only the unambiguous signs: a sentence terminator
16
+ * sitting mid-line with more text after it, or two clauses welded
17
+ * together by a semicolon. An " and " or " then " is left alone, since
18
+ * no suffix heuristic can tell a second verb from a coordinated object
19
+ * or temporal adverb without reading the word as language. The prompt
20
+ * hands that subtler clause-counting to the AI oracle, which weighs the
21
+ * full sentence before judging a line as multi-instruction.
20
22
  */
21
23
  class Atomic {
22
24
  constructor() {
23
25
  this.id = 'atomic';
24
26
  }
25
27
  prompt() {
26
- return `${this.id}: flag any line that carries more than one instruction, counting distinct clauses even when no semicolon, "and", or "then" welds them together`;
28
+ return `${this.id}: flag any line that carries more than one instruction, counting distinct clauses whether or not a semicolon, "and", or "then" welds them, yet never count a coordinated object or noun phrase trailing "and" or "then" as a second instruction`;
27
29
  }
28
30
  violations(document) {
29
31
  const uri = document.uri();
@@ -37,11 +39,7 @@ class Atomic {
37
39
  }
38
40
  judge(text, line, uri) {
39
41
  const clean = text.replace(/^\s*(?:[-*+]|\d+\.)\s+/u, '').trimEnd();
40
- const weld = /(?<!,)\s(?:and|then)\s+(?<verb>[a-z]+)\s+\S/u.exec(clean);
41
- const welded = weld !== null &&
42
- !/^(?:the|a|an)$/u.test(weld.groups.verb) &&
43
- !/(?:ly|al|ial|ous|ive|less|ic|ary|ory|able|ible|ate)$/u.test(weld.groups.verb);
44
- if (!/[.!?]\s+\S/u.test(clean) && !/;/u.test(clean) && !welded) {
42
+ if (!/[.!?]\s+\S/u.test(clean) && !/;/u.test(clean)) {
45
43
  return [];
46
44
  }
47
45
  return [new Violation(
@@ -7,6 +7,7 @@
7
7
 
8
8
  const Violation = require('../violation');
9
9
  const Region = require('../region');
10
+ const mask = require('../mask');
10
11
 
11
12
  /**
12
13
  * Hedging.
@@ -41,7 +42,8 @@ class Hedging {
41
42
  'when necessary|usually|generally|etc|just|simply|very)\\b',
42
43
  'giu'
43
44
  );
44
- let hit = regex.exec(text);
45
+ const masked = mask(text);
46
+ let hit = regex.exec(masked);
45
47
  while (hit !== null) {
46
48
  found.push(new Violation(
47
49
  this.id,
@@ -49,7 +51,7 @@ class Hedging {
49
51
  `hedge word "${hit[0]}" must be removed`,
50
52
  new Region(uri, line, hit.index + 1)
51
53
  ));
52
- hit = regex.exec(text);
54
+ hit = regex.exec(masked);
53
55
  }
54
56
  return found;
55
57
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  const Violation = require('../violation');
9
9
  const Region = require('../region');
10
+ const mask = require('../mask');
10
11
 
11
12
  /**
12
13
  * NoArticles.
@@ -33,8 +34,9 @@ class NoArticles {
33
34
  }
34
35
  scan(text, line, uri) {
35
36
  const found = [];
37
+ const masked = mask(text);
36
38
  const regex = /\b(?:a|an|the)\b/giu;
37
- let hit = regex.exec(text);
39
+ let hit = regex.exec(masked);
38
40
  while (hit !== null) {
39
41
  found.push(new Violation(
40
42
  this.id,
@@ -42,7 +44,7 @@ class NoArticles {
42
44
  `article "${hit[0]}" must be removed`,
43
45
  new Region(uri, line, hit.index + 1)
44
46
  ));
45
- hit = regex.exec(text);
47
+ hit = regex.exec(masked);
46
48
  }
47
49
  return found;
48
50
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  const Violation = require('../violation');
9
9
  const Region = require('../region');
10
+ const mask = require('../mask');
10
11
 
11
12
  /**
12
13
  * Polite.
@@ -38,7 +39,7 @@ class Polite {
38
39
  }
39
40
  scan(text, line, uri) {
40
41
  const found = [];
41
- const masked = this.mask(text);
42
+ const masked = mask(text);
42
43
  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;
43
44
  let hit = regex.exec(masked);
44
45
  while (hit !== null) {
@@ -52,9 +53,6 @@ class Polite {
52
53
  }
53
54
  return found;
54
55
  }
55
- mask(text) {
56
- return text.replace(/`[^`]*`/gu, (span) => ' '.repeat(span.length));
57
- }
58
56
  }
59
57
 
60
58
  module.exports = Polite;
@@ -7,6 +7,7 @@
7
7
 
8
8
  const Violation = require('../violation');
9
9
  const Region = require('../region');
10
+ const mask = require('../mask');
10
11
 
11
12
  /**
12
13
  * Unfinished.
@@ -44,7 +45,8 @@ class Unfinished {
44
45
  /\.\.\.\s*$/u,
45
46
  /<[^>\n]*>/u
46
47
  ];
47
- if (!markers.some((marker) => marker.test(text))) {
48
+ const masked = mask(text);
49
+ if (!markers.some((marker) => marker.test(masked))) {
48
50
  return [];
49
51
  }
50
52
  return [new Violation(