@mark1russell7/ste-lint 0.0.0-stage → 0.1.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.
Files changed (253) hide show
  1. package/README.md +246 -2
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +9 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config-core.d.ts +92 -0
  8. package/dist/config-core.d.ts.map +1 -0
  9. package/dist/config-core.js +198 -0
  10. package/dist/config-core.js.map +1 -0
  11. package/dist/config.d.ts +29 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +68 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/core.d.ts +16 -0
  16. package/dist/core.d.ts.map +1 -0
  17. package/dist/core.js +16 -0
  18. package/dist/core.js.map +1 -0
  19. package/dist/dictionary-core.d.ts +72 -0
  20. package/dist/dictionary-core.d.ts.map +1 -0
  21. package/dist/dictionary-core.js +150 -0
  22. package/dist/dictionary-core.js.map +1 -0
  23. package/dist/dictionary.d.ts +9 -0
  24. package/dist/dictionary.d.ts.map +1 -0
  25. package/dist/dictionary.js +26 -0
  26. package/dist/dictionary.js.map +1 -0
  27. package/dist/engine.d.ts +44 -0
  28. package/dist/engine.d.ts.map +1 -0
  29. package/dist/engine.js +122 -0
  30. package/dist/engine.js.map +1 -0
  31. package/dist/files.d.ts +35 -0
  32. package/dist/files.d.ts.map +1 -0
  33. package/dist/files.js +181 -0
  34. package/dist/files.js.map +1 -0
  35. package/dist/format.d.ts +21 -0
  36. package/dist/format.d.ts.map +1 -0
  37. package/dist/format.js +61 -0
  38. package/dist/format.js.map +1 -0
  39. package/dist/index.d.ts +19 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +19 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/lexicon.d.ts +33 -0
  44. package/dist/lexicon.d.ts.map +1 -0
  45. package/dist/lexicon.js +71 -0
  46. package/dist/lexicon.js.map +1 -0
  47. package/dist/lint.d.ts +18 -0
  48. package/dist/lint.d.ts.map +1 -0
  49. package/dist/lint.js +23 -0
  50. package/dist/lint.js.map +1 -0
  51. package/dist/rules/about-quantity.d.ts +3 -0
  52. package/dist/rules/about-quantity.d.ts.map +1 -0
  53. package/dist/rules/about-quantity.js +34 -0
  54. package/dist/rules/about-quantity.js.map +1 -0
  55. package/dist/rules/index.d.ts +8 -0
  56. package/dist/rules/index.d.ts.map +1 -0
  57. package/dist/rules/index.js +35 -0
  58. package/dist/rules/index.js.map +1 -0
  59. package/dist/rules/ing-verb.d.ts +9 -0
  60. package/dist/rules/ing-verb.d.ts.map +1 -0
  61. package/dist/rules/ing-verb.js +60 -0
  62. package/dist/rules/ing-verb.js.map +1 -0
  63. package/dist/rules/latin-abbreviation.d.ts +3 -0
  64. package/dist/rules/latin-abbreviation.d.ts.map +1 -0
  65. package/dist/rules/latin-abbreviation.js +48 -0
  66. package/dist/rules/latin-abbreviation.js.map +1 -0
  67. package/dist/rules/missing-subject.d.ts +16 -0
  68. package/dist/rules/missing-subject.d.ts.map +1 -0
  69. package/dist/rules/missing-subject.js +138 -0
  70. package/dist/rules/missing-subject.js.map +1 -0
  71. package/dist/rules/modal-verb.d.ts +3 -0
  72. package/dist/rules/modal-verb.d.ts.map +1 -0
  73. package/dist/rules/modal-verb.js +72 -0
  74. package/dist/rules/modal-verb.js.map +1 -0
  75. package/dist/rules/noun-cluster.d.ts +17 -0
  76. package/dist/rules/noun-cluster.d.ts.map +1 -0
  77. package/dist/rules/noun-cluster.js +83 -0
  78. package/dist/rules/noun-cluster.js.map +1 -0
  79. package/dist/rules/paragraph-length.d.ts +3 -0
  80. package/dist/rules/paragraph-length.d.ts.map +1 -0
  81. package/dist/rules/paragraph-length.js +19 -0
  82. package/dist/rules/paragraph-length.js.map +1 -0
  83. package/dist/rules/passive-instruction.d.ts +15 -0
  84. package/dist/rules/passive-instruction.d.ts.map +1 -0
  85. package/dist/rules/passive-instruction.js +38 -0
  86. package/dist/rules/passive-instruction.js.map +1 -0
  87. package/dist/rules/pronouns.d.ts +4 -0
  88. package/dist/rules/pronouns.d.ts.map +1 -0
  89. package/dist/rules/pronouns.js +57 -0
  90. package/dist/rules/pronouns.js.map +1 -0
  91. package/dist/rules/rule.d.ts +46 -0
  92. package/dist/rules/rule.d.ts.map +1 -0
  93. package/dist/rules/rule.js +31 -0
  94. package/dist/rules/rule.js.map +1 -0
  95. package/dist/rules/semicolon.d.ts +3 -0
  96. package/dist/rules/semicolon.d.ts.map +1 -0
  97. package/dist/rules/semicolon.js +20 -0
  98. package/dist/rules/semicolon.js.map +1 -0
  99. package/dist/rules/sentence-length.d.ts +3 -0
  100. package/dist/rules/sentence-length.d.ts.map +1 -0
  101. package/dist/rules/sentence-length.js +31 -0
  102. package/dist/rules/sentence-length.js.map +1 -0
  103. package/dist/rules/unknown-word.d.ts +9 -0
  104. package/dist/rules/unknown-word.d.ts.map +1 -0
  105. package/dist/rules/unknown-word.js +49 -0
  106. package/dist/rules/unknown-word.js.map +1 -0
  107. package/dist/rules/word-list-matcher.d.ts +25 -0
  108. package/dist/rules/word-list-matcher.d.ts.map +1 -0
  109. package/dist/rules/word-list-matcher.js +60 -0
  110. package/dist/rules/word-list-matcher.js.map +1 -0
  111. package/dist/rules/word-list.d.ts +3 -0
  112. package/dist/rules/word-list.d.ts.map +1 -0
  113. package/dist/rules/word-list.js +26 -0
  114. package/dist/rules/word-list.js.map +1 -0
  115. package/dist/run-cli.d.ts +27 -0
  116. package/dist/run-cli.d.ts.map +1 -0
  117. package/dist/run-cli.js +176 -0
  118. package/dist/run-cli.js.map +1 -0
  119. package/dist/source/blocks.d.ts +55 -0
  120. package/dist/source/blocks.d.ts.map +1 -0
  121. package/dist/source/blocks.js +464 -0
  122. package/dist/source/blocks.js.map +1 -0
  123. package/dist/source/code.d.ts +9 -0
  124. package/dist/source/code.d.ts.map +1 -0
  125. package/dist/source/code.js +16 -0
  126. package/dist/source/code.js.map +1 -0
  127. package/dist/source/inline.d.ts +42 -0
  128. package/dist/source/inline.d.ts.map +1 -0
  129. package/dist/source/inline.js +396 -0
  130. package/dist/source/inline.js.map +1 -0
  131. package/dist/source/jsx.d.ts +18 -0
  132. package/dist/source/jsx.d.ts.map +1 -0
  133. package/dist/source/jsx.js +137 -0
  134. package/dist/source/jsx.js.map +1 -0
  135. package/dist/source/lines.d.ts +34 -0
  136. package/dist/source/lines.d.ts.map +1 -0
  137. package/dist/source/lines.js +83 -0
  138. package/dist/source/lines.js.map +1 -0
  139. package/dist/source/markdown.d.ts +23 -0
  140. package/dist/source/markdown.d.ts.map +1 -0
  141. package/dist/source/markdown.js +42 -0
  142. package/dist/source/markdown.js.map +1 -0
  143. package/dist/source/suppressions.d.ts +38 -0
  144. package/dist/source/suppressions.d.ts.map +1 -0
  145. package/dist/source/suppressions.js +69 -0
  146. package/dist/source/suppressions.js.map +1 -0
  147. package/dist/source/tsdoc.d.ts +40 -0
  148. package/dist/source/tsdoc.d.ts.map +1 -0
  149. package/dist/source/tsdoc.js +176 -0
  150. package/dist/source/tsdoc.js.map +1 -0
  151. package/dist/text/grammar.d.ts +91 -0
  152. package/dist/text/grammar.d.ts.map +1 -0
  153. package/dist/text/grammar.js +289 -0
  154. package/dist/text/grammar.js.map +1 -0
  155. package/dist/text/phrases.d.ts +30 -0
  156. package/dist/text/phrases.d.ts.map +1 -0
  157. package/dist/text/phrases.js +65 -0
  158. package/dist/text/phrases.js.map +1 -0
  159. package/dist/text/sentences.d.ts +45 -0
  160. package/dist/text/sentences.d.ts.map +1 -0
  161. package/dist/text/sentences.js +141 -0
  162. package/dist/text/sentences.js.map +1 -0
  163. package/dist/text/tokens.d.ts +35 -0
  164. package/dist/text/tokens.d.ts.map +1 -0
  165. package/dist/text/tokens.js +113 -0
  166. package/dist/text/tokens.js.map +1 -0
  167. package/dist/text/words.d.ts +58 -0
  168. package/dist/text/words.d.ts.map +1 -0
  169. package/dist/text/words.js +159 -0
  170. package/dist/text/words.js.map +1 -0
  171. package/dist/types.d.ts +18 -0
  172. package/dist/types.d.ts.map +1 -0
  173. package/dist/types.js +20 -0
  174. package/dist/types.js.map +1 -0
  175. package/dist/units.d.ts +47 -0
  176. package/dist/units.d.ts.map +1 -0
  177. package/dist/units.js +42 -0
  178. package/dist/units.js.map +1 -0
  179. package/dist/word-list.d.ts +34 -0
  180. package/dist/word-list.d.ts.map +1 -0
  181. package/dist/word-list.js +90 -0
  182. package/dist/word-list.js.map +1 -0
  183. package/package.json +54 -3
  184. package/src/cli.ts +9 -0
  185. package/src/config-core.ts +258 -0
  186. package/src/config.test.ts +188 -0
  187. package/src/config.ts +83 -0
  188. package/src/core.test.ts +87 -0
  189. package/src/core.ts +32 -0
  190. package/src/dictionary-core.ts +158 -0
  191. package/src/dictionary.test.ts +82 -0
  192. package/src/dictionary.ts +26 -0
  193. package/src/engine.ts +138 -0
  194. package/src/files.test.ts +107 -0
  195. package/src/files.ts +191 -0
  196. package/src/format.ts +78 -0
  197. package/src/index.test.ts +28 -0
  198. package/src/index.ts +38 -0
  199. package/src/lexicon.ts +92 -0
  200. package/src/lint.test.ts +182 -0
  201. package/src/lint.ts +30 -0
  202. package/src/rules/about-quantity.ts +33 -0
  203. package/src/rules/index.ts +40 -0
  204. package/src/rules/ing-verb.test.ts +48 -0
  205. package/src/rules/ing-verb.ts +54 -0
  206. package/src/rules/latin-abbreviation.ts +46 -0
  207. package/src/rules/missing-subject.test.ts +53 -0
  208. package/src/rules/missing-subject.ts +129 -0
  209. package/src/rules/modal-verb.test.ts +45 -0
  210. package/src/rules/modal-verb.ts +72 -0
  211. package/src/rules/noun-cluster.test.ts +49 -0
  212. package/src/rules/noun-cluster.ts +82 -0
  213. package/src/rules/paragraph-length.test.ts +30 -0
  214. package/src/rules/paragraph-length.ts +19 -0
  215. package/src/rules/passive-instruction.test.ts +38 -0
  216. package/src/rules/passive-instruction.ts +37 -0
  217. package/src/rules/pronouns.test.ts +38 -0
  218. package/src/rules/pronouns.ts +54 -0
  219. package/src/rules/punctuation.test.ts +59 -0
  220. package/src/rules/rule.ts +73 -0
  221. package/src/rules/semicolon.ts +19 -0
  222. package/src/rules/sentence-length.test.ts +52 -0
  223. package/src/rules/sentence-length.ts +32 -0
  224. package/src/rules/unknown-word.test.ts +81 -0
  225. package/src/rules/unknown-word.ts +43 -0
  226. package/src/rules/word-list-matcher.ts +68 -0
  227. package/src/rules/word-list.test.ts +110 -0
  228. package/src/rules/word-list.ts +25 -0
  229. package/src/run-cli.test.ts +189 -0
  230. package/src/run-cli.ts +193 -0
  231. package/src/source/blocks.ts +534 -0
  232. package/src/source/code.ts +17 -0
  233. package/src/source/inline.test.ts +92 -0
  234. package/src/source/inline.ts +416 -0
  235. package/src/source/jsx.test.ts +46 -0
  236. package/src/source/jsx.ts +147 -0
  237. package/src/source/lines.test.ts +51 -0
  238. package/src/source/lines.ts +91 -0
  239. package/src/source/markdown.test.ts +210 -0
  240. package/src/source/markdown.ts +49 -0
  241. package/src/source/suppressions.ts +79 -0
  242. package/src/source/tsdoc.test.ts +137 -0
  243. package/src/source/tsdoc.ts +189 -0
  244. package/src/text/grammar.ts +304 -0
  245. package/src/text/phrases.ts +72 -0
  246. package/src/text/sentences.ts +148 -0
  247. package/src/text/text.test.ts +262 -0
  248. package/src/text/tokens.ts +135 -0
  249. package/src/text/words.ts +183 -0
  250. package/src/types.ts +39 -0
  251. package/src/units.ts +86 -0
  252. package/src/word-list.ts +128 -0
  253. package/ste.config.schema.json +87 -0
@@ -0,0 +1,25 @@
1
+ import { type Token } from "../text/tokens.js";
2
+ import type { WordListEntry } from "../word-list.js";
3
+ export type WordListMatch = {
4
+ readonly entry: WordListEntry;
5
+ readonly from: number;
6
+ readonly to: number;
7
+ };
8
+ /** True when "see" at `index` tells the reader to look at other text, not to see with the eyes. */
9
+ export declare function isReferenceSee(tokens: readonly Token[], index: number): boolean;
10
+ /** This class finds the entries of the word list in a sentence. */
11
+ export declare class WordListMatcher {
12
+ private readonly phrases;
13
+ /** The single words of the list. Other rules skip these words, so that a word gets one finding. */
14
+ readonly words: ReadonlySet<string>;
15
+ constructor(entries: readonly WordListEntry[]);
16
+ /**
17
+ * The matches in `tokens`. The longest phrase wins. `skipWord` tells the
18
+ * matcher to ignore a single word, for example a glossary term.
19
+ */
20
+ find(tokens: readonly Token[], options: {
21
+ readonly verbs: ReadonlySet<string>;
22
+ readonly skipWord: (word: string) => boolean;
23
+ }): WordListMatch[];
24
+ }
25
+ //# sourceMappingURL=word-list-matcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"word-list-matcher.d.ts","sourceRoot":"","sources":["../../src/rules/word-list-matcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAG,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;CACxB,CAAC;AAMF,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,MAAM,EAAG,SAAS,KAAK,EAAE,EAAE,KAAK,EAAG,MAAM,GAAI,OAAO,CAKlF;AAED,mEAAmE;AACnE,qBAAa,eAAe;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAC9D,mGAAmG;IACnG,QAAQ,CAAC,KAAK,EAAG,WAAW,CAAC,MAAM,CAAC,CAAC;gBAEzB,OAAO,EAAG,SAAS,aAAa,EAAE;IAY9C;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAG,SAAS,KAAK,EAAE,EAAE,OAAO,EAAG;QAAE,QAAQ,CAAC,KAAK,EAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAG,CAAC,IAAI,EAAG,MAAM,KAAK,OAAO,CAAA;KAAE,GAAI,aAAa,EAAE;CAsBxJ"}
@@ -0,0 +1,60 @@
1
+ import { isClauseStart, isVerbUse } from "../text/grammar.js";
2
+ import { PhraseMatcher, splitPhrase } from "../text/phrases.js";
3
+ import { isWord } from "../text/tokens.js";
4
+ /** Words before "see" that show the meaning "refer to": "(see X)", "For details, see X", "See also X". */
5
+ const REFERENCE_BEFORE = new Set(["also", "please", "and", "or", "then"]);
6
+ const REFERENCE_PUNCTUATION = new Set(["(", ",", ":", ";", "—", "–", "-"]);
7
+ /** True when "see" at `index` tells the reader to look at other text, not to see with the eyes. */
8
+ export function isReferenceSee(tokens, index) {
9
+ const previous = tokens[index - 1];
10
+ if (previous === undefined || isClauseStart(tokens, index))
11
+ return true;
12
+ if (previous.kind === "punct")
13
+ return REFERENCE_PUNCTUATION.has(previous.text);
14
+ return isWord(previous) && REFERENCE_BEFORE.has(previous.lower);
15
+ }
16
+ /** This class finds the entries of the word list in a sentence. */
17
+ export class WordListMatcher {
18
+ phrases = new PhraseMatcher();
19
+ /** The single words of the list. Other rules skip these words, so that a word gets one finding. */
20
+ words;
21
+ constructor(entries) {
22
+ const words = new Set();
23
+ for (const entry of entries) {
24
+ for (const match of entry.match) {
25
+ this.phrases.add(match, entry);
26
+ const parts = splitPhrase(match);
27
+ if (parts.length === 1)
28
+ words.add(parts[0]);
29
+ }
30
+ }
31
+ this.words = words;
32
+ }
33
+ /**
34
+ * The matches in `tokens`. The longest phrase wins. `skipWord` tells the
35
+ * matcher to ignore a single word, for example a glossary term.
36
+ */
37
+ find(tokens, options) {
38
+ const matches = [];
39
+ let i = 0;
40
+ while (i < tokens.length) {
41
+ const match = this.phrases.match(tokens, i);
42
+ if (match === null) {
43
+ i++;
44
+ continue;
45
+ }
46
+ const entry = match.value;
47
+ const skip = (match.length === 1 && options.skipWord(tokens[i].lower))
48
+ || (entry.verbOnly && !isVerbUse(tokens, i, { verbs: options.verbs }))
49
+ || (entry.context === "reference" && !isReferenceSee(tokens, i));
50
+ if (skip) {
51
+ i++;
52
+ continue;
53
+ }
54
+ matches.push({ entry, from: i, to: i + match.length });
55
+ i += match.length;
56
+ }
57
+ return matches;
58
+ }
59
+ }
60
+ //# sourceMappingURL=word-list-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"word-list-matcher.js","sourceRoot":"","sources":["../../src/rules/word-list-matcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAc,MAAM,mBAAmB,CAAC;AASvD,0GAA0G;AAC1G,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1E,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAE3E,mGAAmG;AACnG,MAAM,UAAU,cAAc,CAAC,MAAyB,EAAE,KAAc;IACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACnC,IAAI,QAAQ,KAAK,SAAS,IAAI,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACxE,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/E,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,mEAAmE;AACnE,MAAM,OAAO,eAAe;IACP,OA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EAAE,CAAC,CAAC;mBACpE,CAAC,KAAK,CAAC,OAAO,KAAK,WAAW,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;YACrE,IAAI,IAAI,EAAE,CAAC;gBACP,CAAC,EAAE,CAAC;gBACJ,SAAS;YACb,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAG,CAAC,EAAE,EAAE,EAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YACzD,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC;QACtB,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ import { type Rule } from "./rule.js";
2
+ export declare const wordList: Rule;
3
+ //# sourceMappingURL=word-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"word-list.d.ts","sourceRoot":"","sources":["../../src/rules/word-list.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3D,eAAO,MAAM,QAAQ,EAAG,IAqBvB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { isGlossaryWord } from "../lexicon.js";
2
+ import { surface, tokenRange } from "./rule.js";
3
+ export const wordList = {
4
+ id: "word-list",
5
+ description: "Find the words and phrases of the project word list, and give the plain-language words to use instead.",
6
+ ste: "1.1, 9.1",
7
+ defaultSeverity: "error",
8
+ scope: "word",
9
+ check(unit, context) {
10
+ for (const sentence of unit.sentences) {
11
+ const matches = context.wordList.find(sentence.tokens, {
12
+ verbs: context.lexicon.verbs,
13
+ skipWord: (word) => isGlossaryWord(word, context.lexicon),
14
+ });
15
+ for (const match of matches) {
16
+ const found = surface(sentence.tokens, match.from, match.to);
17
+ const { entry } = match;
18
+ let message = entry.suggest === null ? `Remove "${found}".` : `Write ${entry.suggest}, not "${found}".`;
19
+ if (entry.note !== null)
20
+ message += ` ${entry.note}`;
21
+ context.report({ ...tokenRange(sentence.tokens, match.from, match.to), message, severity: entry.severity });
22
+ }
23
+ }
24
+ },
25
+ };
26
+ //# sourceMappingURL=word-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"word-list.js","sourceRoot":"","sources":["../../src/rules/word-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAa,MAAM,WAAW,CAAC;AAE3D,MAAM,CAAC,MAAM,QAAQ,GAAU;IAC3B,EAAE,EAAG,WAAW;IAChB,WAAW,EAAG,wGAAwG;IACtH,GAAG,EAAG,UAAU;IAChB,eAAe,EAAG,OAAO;IACzB,KAAK,EAAG,MAAM;IACd,KAAK,CAAC,IAAI,EAAE,OAAO;QACf,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;gBACnD,KAAK,EAAG,OAAO,CAAC,OAAO,CAAC,KAAK;gBAC7B,QAAQ,EAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC;aAC7D,CAAC,CAAC;YACH,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;gBAC7D,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;gBACxB,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,UAAU,KAAK,IAAI,CAAC;gBACxG,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;oBAAE,OAAO,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBACrD,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjH,CAAC;QACL,CAAC;IACL,CAAC;CACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The command-line interface. `runCli` does not use `process` directly, so
3
+ * the tests can give it arguments, an environment and output functions.
4
+ */
5
+ export type CliIo = {
6
+ readonly cwd: string;
7
+ readonly env: Readonly<Record<string, string | undefined>>;
8
+ readonly stdout: (text: string) => void;
9
+ readonly stderr: (text: string) => void;
10
+ };
11
+ export type CliOptions = {
12
+ readonly patterns: readonly string[];
13
+ readonly format: "text" | "json";
14
+ readonly maxWarnings: number | null;
15
+ readonly configPath: string | null;
16
+ readonly help: boolean;
17
+ };
18
+ /** An incorrect command line. */
19
+ export declare class UsageError extends Error {
20
+ readonly name: string;
21
+ }
22
+ export declare const USAGE: string;
23
+ /** This function reads the command-line arguments. */
24
+ export declare function parseArgs(argv: readonly string[]): CliOptions;
25
+ /** This function starts the linter with command-line arguments. The result is the exit code. */
26
+ export declare function runCli(argv: readonly string[], io: CliIo): number;
27
+ //# sourceMappingURL=run-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-cli.d.ts","sourceRoot":"","sources":["../src/run-cli.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,MAAM,MAAM,KAAK,GAAG;IAChB,QAAQ,CAAC,GAAG,EAAG,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,MAAM,EAAG,CAAC,IAAI,EAAG,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAG,CAAC,IAAI,EAAG,MAAM,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,QAAQ,CAAC,QAAQ,EAAG,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAG,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAG,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAG,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAC;CAC3B,CAAC;AAEF,iCAAiC;AACjC,qBAAa,UAAW,SAAQ,KAAK;IACjC,SAAkB,IAAI,EAAG,MAAM,CAAgB;CAClD;AAED,eAAO,MAAM,KAAK,EAAG,MAwBpB,CAAC;AAQF,sDAAsD;AACtD,wBAAgB,SAAS,CAAC,IAAI,EAAG,SAAS,MAAM,EAAE,GAAI,UAAU,CA0C/D;AAiBD,gGAAgG;AAChG,wBAAgB,MAAM,CAAC,IAAI,EAAG,SAAS,MAAM,EAAE,EAAE,EAAE,EAAG,KAAK,GAAI,MAAM,CAgEpE"}
@@ -0,0 +1,176 @@
1
+ /**
2
+ * The command-line interface. `runCli` does not use `process` directly, so
3
+ * the tests can give it arguments, an environment and output functions.
4
+ */
5
+ import { existsSync } from "node:fs";
6
+ import { relative, resolve, sep } from "node:path";
7
+ import { ConfigError, DICTIONARY_ENV, loadConfig } from "./config.js";
8
+ import { DictionaryError, loadDictionary } from "./dictionary.js";
9
+ import { findFiles } from "./files.js";
10
+ import { formatJson, formatText, summarize } from "./format.js";
11
+ import { buildLexicon } from "./lexicon.js";
12
+ import { fileKind, Linter } from "./lint.js";
13
+ /** An incorrect command line. */
14
+ export class UsageError extends Error {
15
+ name = "UsageError";
16
+ }
17
+ export const USAGE = `Usage: ste-lint [options] [patterns...]
18
+
19
+ ste-lint examines the prose in Markdown files, MDX files and TypeScript doc
20
+ comments. It finds text that does not obey the writing rules of ASD-STE100
21
+ Simplified Technical English. The tool is an automated approximation of
22
+ these rules. It does not certify that a text obeys the standard.
23
+
24
+ Without patterns, ste-lint uses the "include" patterns of ste.config.json,
25
+ or the default patterns. Patterns are relative to the working directory.
26
+
27
+ Options:
28
+ --format <text|json> The output format. The default is "text".
29
+ --max-warnings <n> Exit with code 1 when there are more than n warnings.
30
+ --config <path> Use this configuration file.
31
+ -h, --help Show this help.
32
+
33
+ Exit codes:
34
+ 0 No errors, and not more warnings than the maximum.
35
+ 1 One or more errors, or more warnings than the maximum.
36
+ 2 An incorrect command line or configuration, or no files.
37
+
38
+ Environment:
39
+ ${DICTIONARY_ENV} The path of a local dictionary file. This path has
40
+ priority over "dictionaryPath" in ste.config.json.
41
+ `;
42
+ function optionValue(argv, index, name) {
43
+ const value = argv[index + 1];
44
+ if (value === undefined || value.startsWith("--"))
45
+ throw new UsageError(`The option ${name} needs a value.`);
46
+ return value;
47
+ }
48
+ /** This function reads the command-line arguments. */
49
+ export function parseArgs(argv) {
50
+ const patterns = [];
51
+ let format = "text";
52
+ let maxWarnings = null;
53
+ let configPath = null;
54
+ let help = false;
55
+ for (let i = 0; i < argv.length; i++) {
56
+ const argument = argv[i];
57
+ const [name, inline] = argument.startsWith("--") && argument.includes("=") ? [argument.slice(0, argument.indexOf("=")), argument.slice(argument.indexOf("=") + 1)] : [argument, undefined];
58
+ const value = () => {
59
+ if (inline !== undefined)
60
+ return inline;
61
+ const next = optionValue(argv, i, name);
62
+ i++;
63
+ return next;
64
+ };
65
+ switch (name) {
66
+ case "-h":
67
+ case "--help":
68
+ help = true;
69
+ break;
70
+ case "--format": {
71
+ const text = value();
72
+ if (text !== "text" && text !== "json")
73
+ throw new UsageError(`The format must be "text" or "json", not "${text}".`);
74
+ format = text;
75
+ break;
76
+ }
77
+ case "--max-warnings": {
78
+ const text = value();
79
+ const count = Number(text);
80
+ if (!/^\d+$/.test(text) || !Number.isSafeInteger(count))
81
+ throw new UsageError(`--max-warnings must be an integer of 0 or more, not "${text}".`);
82
+ maxWarnings = count;
83
+ break;
84
+ }
85
+ case "--config":
86
+ configPath = value();
87
+ break;
88
+ default:
89
+ if (argument.startsWith("-") && argument !== "-")
90
+ throw new UsageError(`"${argument}" is not a known option. Use --help to show the options.`);
91
+ patterns.push(argument);
92
+ }
93
+ }
94
+ return { patterns, format, maxWarnings, configPath, help };
95
+ }
96
+ function displayPath(path, cwd) {
97
+ const shown = relative(cwd, path);
98
+ return (shown.length > 0 && !shown.startsWith("..") ? shown : path).split(sep).join("/");
99
+ }
100
+ function loadOptionalDictionary(config, io) {
101
+ if (config.dictionaryPath === null)
102
+ return null;
103
+ if (!existsSync(config.dictionaryPath)) {
104
+ const from = config.dictionarySource === "env" ? DICTIONARY_ENV : "dictionaryPath";
105
+ io.stderr(`ste-lint: the dictionary file ${config.dictionaryPath} (from ${from}) does not exist. The unknown-word rule is off.\n`);
106
+ return null;
107
+ }
108
+ return loadDictionary(config.dictionaryPath);
109
+ }
110
+ /** This function starts the linter with command-line arguments. The result is the exit code. */
111
+ export function runCli(argv, io) {
112
+ let options;
113
+ try {
114
+ options = parseArgs(argv);
115
+ }
116
+ catch (error) {
117
+ io.stderr(`ste-lint: ${error.message}\n`);
118
+ return 2;
119
+ }
120
+ if (options.help) {
121
+ io.stdout(USAGE);
122
+ return 0;
123
+ }
124
+ let config;
125
+ let dictionary;
126
+ try {
127
+ config = loadConfig({ cwd: io.cwd, env: io.env, ...(options.configPath === null ? {} : { configPath: options.configPath }) });
128
+ dictionary = loadOptionalDictionary(config, io);
129
+ }
130
+ catch (error) {
131
+ if (error instanceof ConfigError || error instanceof DictionaryError) {
132
+ io.stderr(`ste-lint: ${error.message}\n`);
133
+ return 2;
134
+ }
135
+ throw error;
136
+ }
137
+ const explicit = options.patterns.length > 0;
138
+ let files;
139
+ try {
140
+ // The patterns of the command line are relative to the working directory. The ignore patterns are relative to the configuration.
141
+ files = (explicit
142
+ ? findFiles({ root: io.cwd, include: options.patterns, ignore: config.ignore, ignoreRoot: config.root })
143
+ : findFiles({ root: config.root, include: config.include, ignore: config.ignore })).filter((file) => fileKind(file) !== null);
144
+ }
145
+ catch (error) {
146
+ // For example, a directory that the user cannot read (EACCES)
147
+ io.stderr(`ste-lint: cannot read the files: ${error.message}\n`);
148
+ return 2;
149
+ }
150
+ if (files.length === 0) {
151
+ io.stderr(explicit ? "ste-lint: no files match the patterns.\n" : "ste-lint: no files to examine.\n");
152
+ return explicit ? 2 : 0;
153
+ }
154
+ const linter = new Linter(config, buildLexicon(config, dictionary));
155
+ const findings = [];
156
+ let failed = false;
157
+ for (const file of files) {
158
+ try {
159
+ findings.push(...linter.lintFile(file, displayPath(file, resolve(io.cwd))));
160
+ }
161
+ catch (error) {
162
+ io.stderr(`ste-lint: cannot examine ${file}: ${error.message}\n`);
163
+ failed = true;
164
+ }
165
+ }
166
+ const summary = summarize(findings, files.length);
167
+ io.stdout(options.format === "json" ? formatJson(findings, summary) : formatText(findings, summary));
168
+ const tooManyWarnings = options.maxWarnings !== null && summary.warnings > options.maxWarnings;
169
+ if (tooManyWarnings && options.format === "text") {
170
+ io.stderr(`ste-lint: ${summary.warnings} warnings. The maximum is ${options.maxWarnings}.\n`);
171
+ }
172
+ if (failed)
173
+ return 2;
174
+ return summary.errors > 0 || tooManyWarnings ? 1 : 0;
175
+ }
176
+ //# sourceMappingURL=run-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-cli.js","sourceRoot":"","sources":["../src/run-cli.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,cAAc,EAAmB,M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AC,OAAO,KAAK,EAAE,CAAC;YACb,EAAE,CAAC,MAAM,CAAC,4BAA4B,IAAI,KAAM,KAAe,CAAC,OAAO,IAAI,CAAC,CAAC;YAC7E,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAClD,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACrG,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW,KAAK,IAAI,IAAI,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAC/F,IAAI,eAAe,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC/C,EAAE,CAAC,MAAM,CAAC,aAAa,OAAO,CAAC,QAAQ,6BAA6B,OAAO,CAAC,WAAW,KAAK,CAAC,CAAC;IAClG,CAAC;IACD,IAAI,MAAM;QAAE,OAAO,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * A block parser for the part of Markdown, GFM and MDX that has prose in it.
3
+ *
4
+ * The parser keeps paragraphs, headings, list items, block quotes and table
5
+ * cells. It removes fenced and indented code, HTML blocks, JSX tags, MDX
6
+ * import and export lines, MDX expressions, link reference definitions and
7
+ * thematic breaks. The TSDoc extractor uses the same parser for the text in
8
+ * a doc comment.
9
+ *
10
+ * The parser does not build a full CommonMark tree. It knows only the
11
+ * structure that the lint rules use. That is where a block starts and
12
+ * stops, and if the block is a heading, a table cell or text in a list item.
13
+ */
14
+ import { type Line } from "./lines.js";
15
+ export type ListContext = {
16
+ readonly ordered: boolean;
17
+ };
18
+ /** A block of prose that the lint rules examine. */
19
+ export type ProseBlock = {
20
+ readonly kind: "paragraph" | "heading" | "table-cell";
21
+ /** The text lines of the block, without Markdown block syntax. */
22
+ readonly lines: readonly Line[];
23
+ /** The innermost list that contains the block, or null. */
24
+ readonly list: ListContext | null;
25
+ readonly quote: boolean;
26
+ /** 1 to 6 for a heading, 0 for other blocks. */
27
+ readonly headingDepth: number;
28
+ /** True for the cells of a table header row. */
29
+ readonly tableHeader: boolean;
30
+ };
31
+ export type DirectiveCommand = "disable" | "enable" | "disable-next";
32
+ /** A `ste-disable`, `ste-enable` or `ste-disable-next` comment. */
33
+ export type Directive = {
34
+ readonly kind: "directive";
35
+ readonly command: DirectiveCommand;
36
+ /** The rule IDs. An empty list means all rules. */
37
+ readonly rules: readonly string[];
38
+ readonly offset: number;
39
+ };
40
+ export type Block = ProseBlock | Directive;
41
+ export type BlockOptions = {
42
+ /** Parse JSX tags, ESM lines and `{...}` expressions as MDX does. */
43
+ readonly mdx: boolean;
44
+ };
45
+ /** This function parses `lines` into prose blocks and directive comments. */
46
+ export declare function parseBlocks(lines: readonly Line[], options: BlockOptions): Block[];
47
+ /** The directive in the text of a comment, or null. */
48
+ export declare function parseDirective(commentText: string, offset: number): Directive | null;
49
+ /** True for a GFM table delimiter row, for example `| --- | :-: |`. */
50
+ export declare function isDelimiterRow(text: string): boolean;
51
+ /** This function divides a table row into cells. A `|` in a code span or after `\` does not divide cells. */
52
+ export declare function splitCells(row: Line): Line[];
53
+ /** The index of the next run of exactly `length` backticks at or after `from`, or -1. */
54
+ export declare function findBacktickRun(text: string, from: number, length: number): number;
55
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/source/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAgD,KA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