@mark1russell7/ste-lint 0.1.1 → 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 (49) hide show
  1. package/README.md +26 -5
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/config-core.d.ts +92 -0
  4. package/dist/config-core.d.ts.map +1 -0
  5. package/dist/config-core.js +198 -0
  6. package/dist/config-core.js.map +1 -0
  7. package/dist/config.d.ts +2 -76
  8. package/dist/config.d.ts.map +1 -1
  9. package/dist/config.js +3 -186
  10. package/dist/config.js.map +1 -1
  11. package/dist/core.d.ts +16 -0
  12. package/dist/core.d.ts.map +1 -0
  13. package/dist/core.js +16 -0
  14. package/dist/core.js.map +1 -0
  15. package/dist/dictionary-core.d.ts +72 -0
  16. package/dist/dictionary-core.d.ts.map +1 -0
  17. package/dist/dictionary-core.js +150 -0
  18. package/dist/dictionary-core.js.map +1 -0
  19. package/dist/dictionary.d.ts +4 -69
  20. package/dist/dictionary.d.ts.map +1 -1
  21. package/dist/dictionary.js +4 -147
  22. package/dist/dictionary.js.map +1 -1
  23. package/dist/engine.d.ts +44 -0
  24. package/dist/engine.d.ts.map +1 -0
  25. package/dist/engine.js +122 -0
  26. package/dist/engine.js.map +1 -0
  27. package/dist/index.d.ts +3 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +3 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/lint.d.ts +6 -16
  32. package/dist/lint.d.ts.map +1 -1
  33. package/dist/lint.js +7 -116
  34. package/dist/lint.js.map +1 -1
  35. package/dist/source/code.d.ts +9 -0
  36. package/dist/source/code.d.ts.map +1 -0
  37. package/dist/source/code.js +16 -0
  38. package/dist/source/code.js.map +1 -0
  39. package/package.json +10 -2
  40. package/src/config-core.ts +258 -0
  41. package/src/config.ts +3 -238
  42. package/src/core.test.ts +87 -0
  43. package/src/core.ts +32 -0
  44. package/src/dictionary-core.ts +158 -0
  45. package/src/dictionary.ts +4 -155
  46. package/src/engine.ts +138 -0
  47. package/src/index.ts +4 -0
  48. package/src/lint.ts +10 -115
  49. package/src/source/code.ts +17 -0
package/dist/engine.js ADDED
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The lint engine without a file system. It extracts the prose of a text,
3
+ * runs the rules on each prose unit, and gives the findings with their lines
4
+ * and columns. A browser can use this module.
5
+ */
6
+ import { buildLexicon } from "./lexicon.js";
7
+ import { RULES } from "./rules/index.js";
8
+ import { WordListMatcher } from "./rules/word-list-matcher.js";
9
+ import { LineIndex } from "./source/lines.js";
10
+ import { extractMarkdown } from "./source/markdown.js";
11
+ import { isSuppressed } from "./source/suppressions.js";
12
+ import { buildUnit } from "./units.js";
13
+ /** The kind of a file, from its extension, or null when the linter cannot read it. */
14
+ export function fileKind(path) {
15
+ const lower = path.toLowerCase();
16
+ if (lower.endsWith(".mdx"))
17
+ return "mdx";
18
+ if (lower.endsWith(".md") || lower.endsWith(".markdown"))
19
+ return "markdown";
20
+ if (/\.(?:[mc]?ts|tsx|[mc]?js|jsx)$/.test(lower) && !lower.endsWith(".d.ts"))
21
+ return "typescript";
22
+ return null;
23
+ }
24
+ /**
25
+ * A linter for one configuration, for text in memory. It makes the lexicon
26
+ * and the word list matcher one time. It reads no file.
27
+ */
28
+ export class ProseLinter {
29
+ config;
30
+ lexicon;
31
+ wordList;
32
+ rules;
33
+ extractCode;
34
+ constructor(config, lexicon, options = {}) {
35
+ this.config = config;
36
+ this.lexicon = lexicon ?? buildLexicon(config);
37
+ this.wordList = new WordListMatcher(config.wordList);
38
+ this.extractCode = options.extractCode ?? null;
39
+ this.rules = RULES.flatMap((rule) => {
40
+ const setting = config.rules[rule.id];
41
+ if (setting === "off")
42
+ return [];
43
+ if (rule.id === "unknown-word" && this.lexicon.dictionary === null)
44
+ return [];
45
+ return [{ rule, override: setting ?? null }];
46
+ });
47
+ }
48
+ /** The prose units of a file. */
49
+ units(text, path) {
50
+ return this.extract(text, path).blocks.flatMap((block) => buildUnit(block, this.lexicon) ?? []);
51
+ }
52
+ /** The findings in `text`. `path` gives the kind of file, and it is the file name in the findings. */
53
+ lintText(text, path) {
54
+ const extraction = this.extract(text, path);
55
+ const lineIndex = new LineIndex(text);
56
+ const raw = [];
57
+ for (const block of extraction.blocks) {
58
+ const unit = buildUnit(block, this.lexicon);
59
+ if (unit === null)
60
+ continue;
61
+ const wordOnly = unit.kind !== "paragraph";
62
+ for (const { rule, override } of this.rules) {
63
+ if (wordOnly && rule.scope !== "word")
64
+ continue;
65
+ rule.check(unit, {
66
+ config: this.config,
67
+ lexicon: this.lexicon,
68
+ wordList: this.wordList,
69
+ report: (report) => {
70
+ raw.push({
71
+ ruleId: rule.id,
72
+ severity: override ?? report.severity ?? rule.defaultSeverity,
73
+ start: report.start,
74
+ end: report.end,
75
+ message: report.message,
76
+ eachWord: reportsEachWord(rule),
77
+ });
78
+ },
79
+ });
80
+ }
81
+ }
82
+ // An unknown word that another rule reports already gets no second finding. A finding for a
83
+ // sentence, a paragraph or a noun cluster does not report each word in it.
84
+ const others = raw.filter((finding) => finding.ruleId !== "unknown-word" && finding.eachWord);
85
+ const kept = raw.filter((finding) => finding.ruleId !== "unknown-word"
86
+ || !others.some((other) => other.start < finding.end && finding.start < other.end));
87
+ return kept
88
+ .filter((finding) => !isSuppressed(extraction.suppressions, finding.ruleId, finding.start))
89
+ .sort((a, b) => a.start - b.start || a.end - b.end || a.ruleId.localeCompare(b.ruleId))
90
+ .map((finding) => {
91
+ const start = lineIndex.position(finding.start);
92
+ const end = lineIndex.position(Math.max(finding.start, finding.end));
93
+ return {
94
+ file: path,
95
+ line: start.line,
96
+ column: start.column,
97
+ endLine: end.line,
98
+ endColumn: end.column,
99
+ ruleId: finding.ruleId,
100
+ severity: finding.severity,
101
+ message: finding.message,
102
+ };
103
+ });
104
+ }
105
+ extract(text, path) {
106
+ const kind = fileKind(path);
107
+ if (kind === "typescript")
108
+ return this.extractCode === null ? { blocks: [], suppressions: [] } : this.extractCode(text, path);
109
+ if (kind === null)
110
+ return { blocks: [], suppressions: [] };
111
+ return extractMarkdown(text, { mdx: kind === "mdx" });
112
+ }
113
+ }
114
+ /**
115
+ * True when a finding of the rule is about each word in its range. A word rule reports a word or a
116
+ * phrase, for example a modal verb or a word list phrase. The noun-cluster rule reports a group of
117
+ * nouns, and the sentence and paragraph rules report a full sentence or paragraph.
118
+ */
119
+ function reportsEachWord(rule) {
120
+ return rule.scope === "word" && rule.id !== "noun-cluster";
121
+ }
122
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAgB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AAIvD,sFAAsF;AACtF,MAAM,UAAU,QAAQ,CAAC,IAAa;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5E,IAAI,gCAAgC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,YAAY,CAAC;IAClG,OAAO,IAAI,CAAC;AAChB,CAA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AQ;gBAC3B,OAAO,EAAG,OAAO,CAAC,OAAO;aAC5B,CAAC;QACN,CAAC,CAAC,CAAC;IACX,CAAC;IAEO,OAAO,CAAC,IAAa,EAAE,IAAa;QACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,IAAI,KAAK,YAAY;YAAE,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAG,EAAE,EAAE,YAAY,EAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,EAAE,MAAM,EAAG,EAAE,EAAE,YAAY,EAAG,EAAE,EAAE,CAAC;QAC7D,OAAO,eAAe,CAAC,IAAI,EAAE,EAAE,GAAG,EAAG,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;IAC3D,CAAC;CACJ;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAW;IAChC,OAAO,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,KAAK,cAAc,CAAC;AAC/D,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,12 +4,14 @@
4
4
  * ASD-STE100 Simplified Technical English. It does not certify that a text
5
5
  * obeys the standard.
6
6
  */
7
- export { CONFIG_FILE_NAME, ConfigError, DEFAULT_IGNORE, DEFAULT_INCLUDE, DEFAULT_LIMITS, DICTIONARY_ENV, findConfigFile, loadConfig, mergeWordList, resolveConfig, validateConfig, type Limits, type LimitsConfig, type ResolvedConfig, type SteConfigFile, type WordListEntryConfig, } from "./config.js";
7
+ export { baseConfig, CONFIG_FILE_NAME, ConfigError, DEFAULT_IGNORE, DEFAULT_INCLUDE, DEFAULT_LIMITS, DICTIONARY_ENV, findConfigFile, loadConfig, mergeWordList, resolveConfig, validateConfig, type BaseConfigOptions, type Limits, type LimitsConfig, type ResolvedConfig, type SteConfigFile, type WordListEntryConfig, } from "./config.js";
8
8
  export { Dictionary, DICTIONARY_FORMAT, DictionaryError, loadDictionary, parseDictionary, type DictionaryEntry, type DictionaryLookup } from "./dictionary.js";
9
9
  export { findFiles, globToRegExp } from "./files.js";
10
10
  export { formatJson, formatText, summarize, type RuleCount, type Summary } from "./format.js";
11
11
  export { buildLexicon, type Lexicon } from "./lexicon.js";
12
+ export { ProseLinter, type CodeExtractor, type ProseLinterOptions } from "./engine.js";
12
13
  export { fileKind, Linter, lintText, type FileKind } from "./lint.js";
14
+ export { extractCode } from "./source/code.js";
13
15
  export { getRule, RULES, type Rule } from "./rules/index.js";
14
16
  export { parseArgs, runCli, USAGE, type CliIo, type CliOptions } from "./run-cli.js";
15
17
  export { isRuleId, RULE_IDS, type Finding, type RuleId, type RuleSetting, type Severity } from "./types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC/J,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,KAAK,OAAO,EAAE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AAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -4,12 +4,14 @@
4
4
  * ASD-STE100 Simplified Technical English. It does not certify that a text
5
5
  * obeys the standard.
6
6
  */
7
- export { CONFIG_FILE_NAME, ConfigError, DEFAULT_IGNORE, DEFAULT_INCLUDE, DEFAULT_LIMITS, DICTIONARY_ENV, findConfigFile, loadConfig, mergeWordList, resolveConfig, validateConfig, } from "./config.js";
7
+ export { baseConfig, CONFIG_FILE_NAME, ConfigError, DEFAULT_IGNORE, DEFAULT_INCLUDE, DEFAULT_LIMITS, DICTIONARY_ENV, findConfigFile, loadConfig, mergeWordList, resolveConfig, validateConfig, } from "./config.js";
8
8
  export { Dictionary, DICTIONARY_FORMAT, DictionaryError, loadDictionary, parseDictionary } from "./dictionary.js";
9
9
  export { findFiles, globToRegExp } from "./files.js";
10
10
  export { formatJson, formatText, summarize } from "./format.js";
11
11
  export { buildLexicon } from "./lexicon.js";
12
+ export { ProseLinter } from "./engine.js";
12
13
  export { fileKind, Linter, lintText } from "./lint.js";
14
+ export { extractCode } from "./source/code.js";
13
15
  export { getRule, RULES } from "./rules/index.js";
14
16
  export { parseArgs, runCli, USAGE } from "./run-cli.js";
15
17
  export { isRuleId, RULE_IDS } from "./types.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,GAMjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAA+C,MAAM,iBAAiB,CAAC;AAC/J,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAgC,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAgB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAiB,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAA+B,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAA8D,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,GAOjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAA+C,MAAM,iBAAiB,CAAC;AAC/J,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAgC,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAgB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAA+C,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAiB,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAA+B,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAA8D,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC"}
package/dist/lint.d.ts CHANGED
@@ -1,25 +1,15 @@
1
1
  /**
2
- * The lint engine. It extracts the prose of a file, runs the rules on each
3
- * prose unit, and gives the findings with their lines and columns.
2
+ * The linter for files: the engine of `engine.ts`, with the extractor of
3
+ * TypeScript doc comments and the file system.
4
4
  */
5
5
  import type { ResolvedConfig } from "./config.js";
6
- import { type Lexicon } from "./lexicon.js";
6
+ import { ProseLinter } from "./engine.js";
7
+ import type { Lexicon } from "./lexicon.js";
7
8
  import type { Finding } from "./types.js";
8
- import { type ProseUnit } from "./units.js";
9
- export type FileKind = "markdown" | "mdx" | "typescript";
10
- /** The kind of a file, from its extension, or null when the linter cannot read it. */
11
- export declare function fileKind(path: string): FileKind | null;
9
+ export { fileKind, type FileKind } from "./engine.js";
12
10
  /** A linter for one configuration. It makes the lexicon and the word list matcher one time. */
13
- export declare class Linter {
14
- readonly config: ResolvedConfig;
15
- readonly lexicon: Lexicon;
16
- private readonly wordList;
17
- private readonly rules;
11
+ export declare class Linter extends ProseLinter {
18
12
  constructor(config: ResolvedConfig, lexicon?: Lexicon);
19
- /** The prose units of a file. */
20
- units(text: string, path: string): ProseUnit[];
21
- /** The findings in `text`. `path` gives the kind of file, and it is the file name in the findings. */
22
- lintText(text: string, path: string): Finding[];
23
13
  /** The findings in a file on disk. `displayPath` is the file name in the findings. */
24
14
  lintFile(path: string, displayPath?: string): Finding[];
25
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAQ1D,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,YAAY,CAAC;AAEzD,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,IAAI,EAAG,MAAM,GAAI,QAAQ,GAAG,IAAI,CAMxD;AAED,+FAA+F;AAC/F,qBAAa,MAAM;IAKH,QAAQ,CAAC,MAAM,EAAG,cAAc;IAJ5C,QAAQ,CAAC,OAAO,EAAG,OAAO,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgF;gBAEjF,MAAM,EAAG,cAAc,EAAE,OAAO,CAAC,EAAG,OAAO;IAWhE,iCAAiC;IACjC,KAAK,CAAC,IA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runs the rules on each
3
- * prose unit, and gives the findings with their lines and columns.
2
+ * The linter for files: the engine of `engine.ts`, with the extractor of
3
+ * TypeScript doc comments and the file system.
4
4
  */
5
5
  import { readFileSync } from "node:fs";
6
- import { buildLexicon } from "./lexicon.js";
7
- import { RULES } from "./rules/index.js";
8
- import { WordListMatcher } from "./rules/word-list-matcher.js";
9
- import { LineIndex } from "./source/lines.js";
10
- import { extractMarkdown } from "./source/markdown.js";
11
- import { isSuppressed } from "./source/suppressions.js";
12
- import { extractTsdoc } from "./source/tsdoc.js";
13
- import { extractJsxText } from "./source/jsx.js";
14
- import { buildUnit } from "./units.js";
15
- /** The kind of a file, from its extension, or null when the linter cannot read it. */
16
- export function fileKind(path) {
17
- const lower = path.toLowerCase();
18
- if (lower.endsWith(".mdx"))
19
- return "mdx";
20
- if (lower.endsWith(".md") || lower.endsWith(".markdown"))
21
- return "markdown";
22
- if (/\.(?:[mc]?ts|tsx|[mc]?js|jsx)$/.test(lower) && !lower.endsWith(".d.ts"))
23
- return "typescript";
24
- return null;
25
- }
6
+ import { ProseLinter } from "./engine.js";
7
+ import { extractCode } from "./source/code.js";
8
+ export { fileKind } from "./engine.js";
26
9
  /** A linter for one configuration. It makes the lexicon and the word list matcher one time. */
27
- export class Linter {
28
- config;
29
- lexicon;
30
- wordList;
31
- rules;
10
+ export class Linter extends ProseLinter {
32
11
  constructor(config, lexicon) {
33
- this.config = config;
34
- this.lexicon = lexicon ?? buildLexicon(config);
35
- this.wordList = new WordListMatcher(config.wordList);
36
- this.rules = RULES.flatMap((rule) => {
37
- const setting = config.rules[rule.id];
38
- if (setting === "off")
39
- return [];
40
- if (rule.id === "unknown-word" && this.lexicon.dictionary === null)
41
- return [];
42
- return [{ rule, override: setting ?? null }];
43
- });
44
- }
45
- /** The prose units of a file. */
46
- units(text, path) {
47
- return extract(text, path).blocks.flatMap((block) => buildUnit(block, this.lexicon) ?? []);
48
- }
49
- /** The findings in `text`. `path` gives the kind of file, and it is the file name in the findings. */
50
- lintText(text, path) {
51
- const extraction = extract(text, path);
52
- const lineIndex = new LineIndex(text);
53
- const raw = [];
54
- for (const block of extraction.blocks) {
55
- const unit = buildUnit(block, this.lexicon);
56
- if (unit === null)
57
- continue;
58
- const wordOnly = unit.kind !== "paragraph";
59
- for (const { rule, override } of this.rules) {
60
- if (wordOnly && rule.scope !== "word")
61
- continue;
62
- rule.check(unit, {
63
- config: this.config,
64
- lexicon: this.lexicon,
65
- wordList: this.wordList,
66
- report: (report) => {
67
- raw.push({
68
- ruleId: rule.id,
69
- severity: override ?? report.severity ?? rule.defaultSeverity,
70
- start: report.start,
71
- end: report.end,
72
- message: report.message,
73
- eachWord: reportsEachWord(rule),
74
- });
75
- },
76
- });
77
- }
78
- }
79
- // An unknown word that another rule reports already gets no second finding. A finding for a
80
- // sentence, a paragraph or a noun cluster does not report each word in it.
81
- const others = raw.filter((finding) => finding.ruleId !== "unknown-word" && finding.eachWord);
82
- const kept = raw.filter((finding) => finding.ruleId !== "unknown-word"
83
- || !others.some((other) => other.start < finding.end && finding.start < other.end));
84
- return kept
85
- .filter((finding) => !isSuppressed(extraction.suppressions, finding.ruleId, finding.start))
86
- .sort((a, b) => a.start - b.start || a.end - b.end || a.ruleId.localeCompare(b.ruleId))
87
- .map((finding) => {
88
- const start = lineIndex.position(finding.start);
89
- const end = lineIndex.position(Math.max(finding.start, finding.end));
90
- return {
91
- file: path,
92
- line: start.line,
93
- column: start.column,
94
- endLine: end.line,
95
- endColumn: end.column,
96
- ruleId: finding.ruleId,
97
- severity: finding.severity,
98
- message: finding.message,
99
- };
100
- });
12
+ super(config, lexicon, { extractCode });
101
13
  }
102
14
  /** The findings in a file on disk. `displayPath` is the file name in the findings. */
103
15
  lintFile(path, displayPath = path) {
104
16
  return this.lintText(readFileSync(path, "utf8"), displayPath);
105
17
  }
106
18
  }
107
- /**
108
- * True when a finding of the rule is about each word in its range. A word rule reports a word or a
109
- * phrase, for example a modal verb or a word list phrase. The noun-cluster rule reports a group of
110
- * nouns, and the sentence and paragraph rules report a full sentence or paragraph.
111
- */
112
- function reportsEachWord(rule) {
113
- return rule.scope === "word" && rule.id !== "noun-cluster";
114
- }
115
- function extract(text, path) {
116
- const kind = fileKind(path);
117
- if (kind === "typescript") {
118
- const comments = extractTsdoc(text, path);
119
- if (!/\.[jt]sx$/i.test(path))
120
- return comments;
121
- // The text that the user interface shows
122
- return { blocks: [...comments.blocks, ...extractJsxText(text, path).blocks], suppressions: comments.suppressions };
123
- }
124
- if (kind === null)
125
- return { blocks: [], suppressions: [] };
126
- return extractMarkdown(text, { mdx: kind === "mdx" });
127
- }
128
19
  /** The findings in `text`, with a new linter. To lint many files, make one `Linter` and use it again. */
129
20
  export function lintText(text, path, config, lexicon) {
130
21
  return new Linter(config, lexicon).lintText(text, path);
package/dist/lint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAgB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AAIvD,sFAAsF;AACtF,MAAM,UAAU,QAAQ,CAAC,IAAa;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,IAAI,KAAK,C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AAE,EAAE,GAAG,EAAG,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,QAAQ,CAAC,IAAa,EAAE,IAAa,EAAE,MAAuB,EAAE,OAAkB;IAC9F,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5D,CAAC"}
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AAEtD,+FAA+F;AAC/F,MAAM,OAAO,MAAO,SAAQ,WAAW;IACnC,YAAY,MAAuB,EAAE,OAAkB;QACnD,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,sFAAsF;IACtF,QAAQ,CAAC,IAAa,EAAE,cAAuB,IAAI;QAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;IAClE,CAAC;CACJ;AAED,yGAAyG;AACzG,MAAM,UAAU,QAAQ,CAAC,IAAa,EAAE,IAAa,EAAE,MAAuB,EAAE,OAAkB;IAC9F,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The prose of a TypeScript or JavaScript file: the doc comments, and the
3
+ * text that the JSX of a TSX or JSX file shows. This module needs the
4
+ * `typescript` package, but no file system. A browser can use it.
5
+ */
6
+ import type { Extraction } from "./markdown.js";
7
+ /** This function extracts the prose of the source text of a TypeScript or JavaScript file. `path` gives the kind of file. */
8
+ export declare function extractCode(text: string, path: string): Extraction;
9
+ //# sourceMappingURL=code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/source/code.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,6HAA6H;AAC7H,wBAAgB,WAAW,CAAC,IAAI,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,GAAI,UAAU,CAKrE"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The prose of a TypeScript or JavaScript file: the doc comments, and the
3
+ * text that the JSX of a TSX or JSX file shows. This module needs the
4
+ * `typescript` package, but no file system. A browser can use it.
5
+ */
6
+ import { extractJsxText } from "./jsx.js";
7
+ import { extractTsdoc } from "./tsdoc.js";
8
+ /** This function extracts the prose of the source text of a TypeScript or JavaScript file. `path` gives the kind of file. */
9
+ export function extractCode(text, path) {
10
+ const comments = extractTsdoc(text, path);
11
+ if (!/\.[jt]sx$/i.test(path))
12
+ return comments;
13
+ // The text that the user interface shows
14
+ return { blocks: [...comments.blocks, ...extractJsxText(text, path).blocks], suppressions: comments.suppressions };
15
+ }
16
+ //# sourceMappingURL=code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/source/code.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,6HAA6H;AAC7H,MAAM,UAAU,WAAW,CAAC,IAAa,EAAE,IAAa;IACpD,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC9C,yCAAyC;IACzC,OAAO,EAAE,MAAM,EAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,YAAY,EAAG,QAAQ,CAAC,YAAY,EAAE,CAAC;AACzH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/ste-lint",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "A linter for the writing rules of ASD-STE100 Simplified Technical English in Markdown, MDX and TypeScript doc comments",
6
6
  "type": "module",
7
7
  "engines": {
@@ -14,6 +14,14 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js"
16
16
  },
17
+ "./core": {
18
+ "types": "./dist/core.d.ts",
19
+ "import": "./dist/core.js"
20
+ },
21
+ "./code": {
22
+ "types": "./dist/source/code.d.ts",
23
+ "import": "./dist/source/code.js"
24
+ },
17
25
  "./ste.config.schema.json": "./ste.config.schema.json"
18
26
  },
19
27
  "bin": {
@@ -42,7 +50,7 @@
42
50
  },
43
51
  "scripts": {
44
52
  "build": "tsc -b",
45
- "typecheck": "tsc -p tsconfig.test.json",
53
+ "typecheck": "tsc -p tsconfig.test.json && pnpm --filter @ste-lint/site run typecheck",
46
54
  "test": "vitest run",
47
55
  "lint:ste": "tsx src/cli.ts"
48
56
  }