@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
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The optional local dictionary of approved words.
3
+ *
4
+ * The ASD-STE100 dictionary is copyrighted. This package does not contain
5
+ * it, and the repository must not contain it. Each user makes a local file
6
+ * from their own copy of the standard. Keep that file outside the
7
+ * repository, or in a git-ignored folder, for example `.ste/`.
8
+ *
9
+ * File format (JSON). The short form is an array of approved words:
10
+ *
11
+ * ```json
12
+ * ["a", "about", "make", "makes", "made"]
13
+ * ```
14
+ *
15
+ * The full form is an object with entries:
16
+ *
17
+ * ```json
18
+ * {
19
+ * "format": "ste-lint-dictionary",
20
+ * "version": 1,
21
+ * "entries": [
22
+ * { "word": "make", "pos": "verb", "forms": ["makes", "made"] },
23
+ * { "word": "valve", "pos": "noun" },
24
+ * { "word": "utilize", "pos": "verb", "approved": false, "alternatives": ["use"] }
25
+ * ]
26
+ * }
27
+ * ```
28
+ *
29
+ * - `word` (necessary): the headword. A phrase, for example "make sure", approves each of its words.
30
+ * - `pos`: the part of speech. A noun also permits its regular plural.
31
+ * - `approved`: `false` for a word that is not approved. The default is `true`.
32
+ * - `forms`: other approved forms, for example the past tense of a verb.
33
+ * - `alternatives`: approved words to use instead of a word that is not approved.
34
+ */
35
+ export type DictionaryEntry = {
36
+ readonly word: string;
37
+ readonly pos?: string;
38
+ readonly approved?: boolean;
39
+ readonly forms?: readonly string[];
40
+ readonly alternatives?: readonly string[];
41
+ };
42
+ export type DictionaryLookup = {
43
+ readonly status: "approved";
44
+ } | {
45
+ readonly status: "not-approved";
46
+ readonly alternatives: readonly string[];
47
+ } | {
48
+ readonly status: "unknown";
49
+ };
50
+ export declare const DICTIONARY_FORMAT = "ste-lint-dictionary";
51
+ /** An error in a dictionary file. */
52
+ export declare class DictionaryError extends Error {
53
+ readonly name: string;
54
+ }
55
+ /** The approved words of a local dictionary. */
56
+ export declare class Dictionary {
57
+ private readonly approved;
58
+ private readonly approvedNouns;
59
+ private readonly notApproved;
60
+ /** The approved nouns. The noun-cluster rule uses them. */
61
+ readonly nouns: Set<string>;
62
+ /** The approved verbs. The imperative and missing-subject heuristics use them. */
63
+ readonly verbs: Set<string>;
64
+ constructor(entries: readonly DictionaryEntry[]);
65
+ /** The number of approved words and forms. */
66
+ get size(): number;
67
+ /** The status of `word` in the dictionary. */
68
+ lookup(word: string): DictionaryLookup;
69
+ }
70
+ /** This function makes a dictionary from parsed JSON. `source` is the file name for error messages. */
71
+ export declare function parseDictionary(value: unknown, source: string): Dictionary;
72
+ //# sourceMappingURL=dictionary-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary-core.d.ts","sourceRoot":"","sources":["../src/dictionary-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAG,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAG,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAG,SAAS,MAAM,EAAE,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACtB;IAAE,QAAQ,CAAC,MAAM,EAAG,UAAU,CAAA;CAAE,GAChC;IAAE,QAAQ,CAAC,MAAM,EAAG,cAAc,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAG,SAAS,MAAM,EAAE,CAAA;CAAE,GAC/E;IAAE,QAAQ,CAAC,MAAM,EAAG,SAAS,CAAA;CAAE,CAAC;AAEtC,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AAEvD,qCAAqC;AACrC,qBAAa,eAAgB,SAAQ,KAAK;IACtC,SAAkB,IAAI,EAAG,MAAM,CAAqB;CACvD;AAID,gDAAgD;AAChD,qBAAa,UAAU;IACnB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IACpE,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAG,GAAG,CAAC,MAAM,CAAC,CAAqB;IACjD,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAG,GAAG,CAAC,MAAM,CAAC,CAAqB;gBAErC,OAAO,EAAG,SAAS,eAAe,EAAE;IAkBhD,8CAA8C;IAC9C,IAAI,IAAI,IAAK,MAAM,CAElB;IAED,8CAA8C;IAC9C,MAAM,CAAC,IAAI,EAAG,MAAM,GAAI,gBAAgB;CAe3C;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,KAAK,EAAG,OAAO,EAAE,MAAM,EAAG,MAAM,GAAI,UAAU,CAmB7E"}
@@ -0,0 +1,150 @@
1
+ /**
2
+ * The optional local dictionary of approved words.
3
+ *
4
+ * The ASD-STE100 dictionary is copyrighted. This package does not contain
5
+ * it, and the repository must not contain it. Each user makes a local file
6
+ * from their own copy of the standard. Keep that file outside the
7
+ * repository, or in a git-ignored folder, for example `.ste/`.
8
+ *
9
+ * File format (JSON). The short form is an array of approved words:
10
+ *
11
+ * ```json
12
+ * ["a", "about", "make", "makes", "made"]
13
+ * ```
14
+ *
15
+ * The full form is an object with entries:
16
+ *
17
+ * ```json
18
+ * {
19
+ * "format": "ste-lint-dictionary",
20
+ * "version": 1,
21
+ * "entries": [
22
+ * { "word": "make", "pos": "verb", "forms": ["makes", "made"] },
23
+ * { "word": "valve", "pos": "noun" },
24
+ * { "word": "utilize", "pos": "verb", "approved": false, "alternatives": ["use"] }
25
+ * ]
26
+ * }
27
+ * ```
28
+ *
29
+ * - `word` (necessary): the headword. A phrase, for example "make sure", approves each of its words.
30
+ * - `pos`: the part of speech. A noun also permits its regular plural.
31
+ * - `approved`: `false` for a word that is not approved. The default is `true`.
32
+ * - `forms`: other approved forms, for example the past tense of a verb.
33
+ * - `alternatives`: approved words to use instead of a word that is not approved.
34
+ */
35
+ export const DICTIONARY_FORMAT = "ste-lint-dictionary";
36
+ /** An error in a dictionary file. */
37
+ export class DictionaryError extends Error {
38
+ name = "DictionaryError";
39
+ }
40
+ const normalize = (word) => word.trim().toLowerCase().replace(/[’‘]/g, "'");
41
+ /** The approved words of a local dictionary. */
42
+ export class Dictionary {
43
+ approved = new Set();
44
+ approvedNouns = new Set();
45
+ notApproved = new Map();
46
+ /** The approved nouns. The noun-cluster rule uses them. */
47
+ nouns = new Set();
48
+ /** The approved verbs. The imperative and missing-subject heuristics use them. */
49
+ verbs = new Set();
50
+ constructor(entries) {
51
+ for (const entry of entries) {
52
+ const words = [entry.word, ...(entry.forms ?? [])].flatMap((form) => normalize(form).split(/\s+/)).filter((form) => form.length > 0);
53
+ if (entry.approved === false) {
54
+ for (const word of words)
55
+ this.notApproved.set(word, entry.alternatives ?? []);
56
+ continue;
57
+ }
58
+ for (const word of words)
59
+ this.approved.add(word);
60
+ const pos = (entry.pos ?? "").toLowerCase();
61
+ const base = normalize(entry.word);
62
+ if (pos === "n" || pos === "noun") {
63
+ this.approvedNouns.add(base);
64
+ this.nouns.add(base);
65
+ }
66
+ if (pos === "v" || pos === "verb")
67
+ this.verbs.add(base);
68
+ }
69
+ }
70
+ /** The number of approved words and forms. */
71
+ get size() {
72
+ return this.approved.size;
73
+ }
74
+ /** The status of `word` in the dictionary. */
75
+ lookup(word) {
76
+ const lower = normalize(word);
77
+ const candidates = [lower];
78
+ if (lower.endsWith("'s"))
79
+ candidates.push(lower.slice(0, -2));
80
+ for (const candidate of candidates) {
81
+ if (this.approved.has(candidate))
82
+ return { status: "approved" };
83
+ const plurals = [candidate.slice(0, -1), candidate.slice(0, -2), candidate.slice(0, -3) + "y"];
84
+ if (candidate.endsWith("s") && plurals.some((singular) => this.approvedNouns.has(singular)))
85
+ return { status: "approved" };
86
+ }
87
+ for (const candidate of candidates) {
88
+ const alternatives = this.notApproved.get(candidate);
89
+ if (alternatives !== undefined)
90
+ return { status: "not-approved", alternatives };
91
+ }
92
+ return { status: "unknown" };
93
+ }
94
+ }
95
+ /** This function makes a dictionary from parsed JSON. `source` is the file name for error messages. */
96
+ export function parseDictionary(value, source) {
97
+ if (Array.isArray(value)) {
98
+ if (!value.every((word) => typeof word === "string")) {
99
+ throw new DictionaryError(`${source}: the array form must contain only strings.`);
100
+ }
101
+ return new Dictionary(value.map((word) => ({ word })));
102
+ }
103
+ if (typeof value !== "object" || value === null) {
104
+ throw new DictionaryError(`${source}: the file must contain an array of words or an object with "entries".`);
105
+ }
106
+ const record = value;
107
+ const format = record["format"];
108
+ if (format !== undefined && format !== DICTIONARY_FORMAT) {
109
+ throw new DictionaryError(`${source}: "format" must be "${DICTIONARY_FORMAT}".`);
110
+ }
111
+ const entries = record["entries"];
112
+ if (!Array.isArray(entries))
113
+ throw new DictionaryError(`${source}: "entries" must be an array.`);
114
+ const parsed = entries.map((entry, index) => parseEntry(entry, `${source}: entries[${index}]`));
115
+ return new Dictionary(parsed);
116
+ }
117
+ function stringArray(value, where) {
118
+ if (value === undefined)
119
+ return undefined;
120
+ if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
121
+ throw new DictionaryError(`${where} must be an array of strings.`);
122
+ }
123
+ return value;
124
+ }
125
+ function parseEntry(entry, where) {
126
+ if (typeof entry === "string")
127
+ return { word: entry };
128
+ if (typeof entry !== "object" || entry === null)
129
+ throw new DictionaryError(`${where} must be a string or an object.`);
130
+ const record = entry;
131
+ const word = record["word"];
132
+ if (typeof word !== "string" || word.trim().length === 0)
133
+ throw new DictionaryError(`${where}.word must be a string that is not empty.`);
134
+ const pos = record["pos"];
135
+ if (pos !== undefined && typeof pos !== "string")
136
+ throw new DictionaryError(`${where}.pos must be a string.`);
137
+ const approved = record["approved"];
138
+ if (approved !== undefined && typeof approved !== "boolean")
139
+ throw new DictionaryError(`${where}.approved must be true or false.`);
140
+ const forms = stringArray(record["forms"], `${where}.forms`);
141
+ const alternatives = stringArray(record["alternatives"], `${where}.alternatives`);
142
+ return {
143
+ word,
144
+ ...(pos === undefined ? {} : { pos }),
145
+ ...(approved === undefined ? {} : { approved }),
146
+ ...(forms === undefined ? {} : { forms }),
147
+ ...(alternatives === undefined ? {} : { alternatives }),
148
+ };
149
+ }
150
+ //# sourceMappingURL=dictionary-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary-core.js","sourceRoot":"","sources":["../src/dictionary-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAeH,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEvD,qCAAqC;AACrC,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACpB,IAAI,GAAY,iBAAiB,CAAC;CACvD;AAED,MAAM,SAAS,GAAG,CAAC,IAAa,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAE9F,gDAAgD;AAChD,MAAM,OAAO,UAAU;IACF,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;IACpE,2DAA2D;IAClD,KAAK,GAAiB,IAAI,GAAG,EAAU,CAAC;IACjD,kFAAkF;IACzE,KAAK,GAAiB,IAAI,GAAG,EAAU,CAAC;IAEjD,YAAY,OAAoC;QAC5C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAA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AAe,CAAC,CAAC;IAClF,OAAO;QACH,IAAI;QACJ,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QACrC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;QAC/C,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QACzC,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC;KAC1D,CAAC;AACN,CAAC"}
@@ -1,74 +1,9 @@
1
1
  /**
2
- * The optional local dictionary of approved words.
3
- *
4
- * The ASD-STE100 dictionary is copyrighted. This package does not contain
5
- * it, and the repository must not contain it. Each user makes a local file
6
- * from their own copy of the standard. Keep that file outside the
7
- * repository, or in a git-ignored folder, for example `.ste/`.
8
- *
9
- * File format (JSON). The short form is an array of approved words:
10
- *
11
- * ```json
12
- * ["a", "about", "make", "makes", "made"]
13
- * ```
14
- *
15
- * The full form is an object with entries:
16
- *
17
- * ```json
18
- * {
19
- * "format": "ste-lint-dictionary",
20
- * "version": 1,
21
- * "entries": [
22
- * { "word": "make", "pos": "verb", "forms": ["makes", "made"] },
23
- * { "word": "valve", "pos": "noun" },
24
- * { "word": "utilize", "pos": "verb", "approved": false, "alternatives": ["use"] }
25
- * ]
26
- * }
27
- * ```
28
- *
29
- * - `word` (necessary): the headword. A phrase, for example "make sure", approves each of its words.
30
- * - `pos`: the part of speech. A noun also permits its regular plural.
31
- * - `approved`: `false` for a word that is not approved. The default is `true`.
32
- * - `forms`: other approved forms, for example the past tense of a verb.
33
- * - `alternatives`: approved words to use instead of a word that is not approved.
2
+ * The local dictionary file. The format and the lookup are in
3
+ * `dictionary-core.ts`, which a browser can use. This module reads the file.
34
4
  */
35
- export type DictionaryEntry = {
36
- readonly word: string;
37
- readonly pos?: string;
38
- readonly approved?: boolean;
39
- readonly forms?: readonly string[];
40
- readonly alternatives?: readonly string[];
41
- };
42
- export type DictionaryLookup = {
43
- readonly status: "approved";
44
- } | {
45
- readonly status: "not-approved";
46
- readonly alternatives: readonly string[];
47
- } | {
48
- readonly status: "unknown";
49
- };
50
- export declare const DICTIONARY_FORMAT = "ste-lint-dictionary";
51
- /** An error in a dictionary file. */
52
- export declare class DictionaryError extends Error {
53
- readonly name: string;
54
- }
55
- /** The approved words of a local dictionary. */
56
- export declare class Dictionary {
57
- private readonly approved;
58
- private readonly approvedNouns;
59
- private readonly notApproved;
60
- /** The approved nouns. The noun-cluster rule uses them. */
61
- readonly nouns: Set<string>;
62
- /** The approved verbs. The imperative and missing-subject heuristics use them. */
63
- readonly verbs: Set<string>;
64
- constructor(entries: readonly DictionaryEntry[]);
65
- /** The number of approved words and forms. */
66
- get size(): number;
67
- /** The status of `word` in the dictionary. */
68
- lookup(word: string): DictionaryLookup;
69
- }
70
- /** This function makes a dictionary from parsed JSON. `source` is the file name for error messages. */
71
- export declare function parseDictionary(value: unknown, source: string): Dictionary;
5
+ import { type Dictionary } from "./dictionary-core.js";
6
+ export * from "./dictionary-core.js";
72
7
  /** This function reads a dictionary file. */
73
8
  export declare function loadDictionary(path: string): Dictionary;
74
9
  //# sourceMappingURL=dictionary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../src/dictionary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAG,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,CA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":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEzF,cAAc,sBAAsB,CAAC;AAErC,6CAA6C;AAC7C,wBAAgB,cAAc,CAAC,IAAI,EAAG,MAAM,GAAI,UAAU,CAczD"}
@@ -1,153 +1,10 @@
1
1
  /**
2
- * The optional local dictionary of approved words.
3
- *
4
- * The ASD-STE100 dictionary is copyrighted. This package does not contain
5
- * it, and the repository must not contain it. Each user makes a local file
6
- * from their own copy of the standard. Keep that file outside the
7
- * repository, or in a git-ignored folder, for example `.ste/`.
8
- *
9
- * File format (JSON). The short form is an array of approved words:
10
- *
11
- * ```json
12
- * ["a", "about", "make", "makes", "made"]
13
- * ```
14
- *
15
- * The full form is an object with entries:
16
- *
17
- * ```json
18
- * {
19
- * "format": "ste-lint-dictionary",
20
- * "version": 1,
21
- * "entries": [
22
- * { "word": "make", "pos": "verb", "forms": ["makes", "made"] },
23
- * { "word": "valve", "pos": "noun" },
24
- * { "word": "utilize", "pos": "verb", "approved": false, "alternatives": ["use"] }
25
- * ]
26
- * }
27
- * ```
28
- *
29
- * - `word` (necessary): the headword. A phrase, for example "make sure", approves each of its words.
30
- * - `pos`: the part of speech. A noun also permits its regular plural.
31
- * - `approved`: `false` for a word that is not approved. The default is `true`.
32
- * - `forms`: other approved forms, for example the past tense of a verb.
33
- * - `alternatives`: approved words to use instead of a word that is not approved.
2
+ * The local dictionary file. The format and the lookup are in
3
+ * `dictionary-core.ts`, which a browser can use. This module reads the file.
34
4
  */
35
5
  import { readFileSync } from "node:fs";
36
- export const DICTIONARY_FORMAT = "ste-lint-dictionary";
37
- /** An error in a dictionary file. */
38
- export class DictionaryError extends Error {
39
- name = "DictionaryError";
40
- }
41
- const normalize = (word) => word.trim().toLowerCase().replace(/[’‘]/g, "'");
42
- /** The approved words of a local dictionary. */
43
- export class Dictionary {
44
- approved = new Set();
45
- approvedNouns = new Set();
46
- notApproved = new Map();
47
- /** The approved nouns. The noun-cluster rule uses them. */
48
- nouns = new Set();
49
- /** The approved verbs. The imperative and missing-subject heuristics use them. */
50
- verbs = new Set();
51
- constructor(entries) {
52
- for (const entry of entries) {
53
- const words = [entry.word, ...(entry.forms ?? [])].flatMap((form) => normalize(form).split(/\s+/)).filter((form) => form.length > 0);
54
- if (entry.approved === false) {
55
- for (const word of words)
56
- this.notApproved.set(word, entry.alternatives ?? []);
57
- continue;
58
- }
59
- for (const word of words)
60
- this.approved.add(word);
61
- const pos = (entry.pos ?? "").toLowerCase();
62
- const base = normalize(entry.word);
63
- if (pos === "n" || pos === "noun") {
64
- this.approvedNouns.add(base);
65
- this.nouns.add(base);
66
- }
67
- if (pos === "v" || pos === "verb")
68
- this.verbs.add(base);
69
- }
70
- }
71
- /** The number of approved words and forms. */
72
- get size() {
73
- return this.approved.size;
74
- }
75
- /** The status of `word` in the dictionary. */
76
- lookup(word) {
77
- const lower = normalize(word);
78
- const candidates = [lower];
79
- if (lower.endsWith("'s"))
80
- candidates.push(lower.slice(0, -2));
81
- for (const candidate of candidates) {
82
- if (this.approved.has(candidate))
83
- return { status: "approved" };
84
- const plurals = [candidate.slice(0, -1), candidate.slice(0, -2), candidate.slice(0, -3) + "y"];
85
- if (candidate.endsWith("s") && plurals.some((singular) => this.approvedNouns.has(singular)))
86
- return { status: "approved" };
87
- }
88
- for (const candidate of candidates) {
89
- const alternatives = this.notApproved.get(candidate);
90
- if (alternatives !== undefined)
91
- return { status: "not-approved", alternatives };
92
- }
93
- return { status: "unknown" };
94
- }
95
- }
96
- /** This function makes a dictionary from parsed JSON. `source` is the file name for error messages. */
97
- export function parseDictionary(value, source) {
98
- if (Array.isArray(value)) {
99
- if (!value.every((word) => typeof word === "string")) {
100
- throw new DictionaryError(`${source}: the array form must contain only strings.`);
101
- }
102
- return new Dictionary(value.map((word) => ({ word })));
103
- }
104
- if (typeof value !== "object" || value === null) {
105
- throw new DictionaryError(`${source}: the file must contain an array of words or an object with "entries".`);
106
- }
107
- const record = value;
108
- const format = record["format"];
109
- if (format !== undefined && format !== DICTIONARY_FORMAT) {
110
- throw new DictionaryError(`${source}: "format" must be "${DICTIONARY_FORMAT}".`);
111
- }
112
- const entries = record["entries"];
113
- if (!Array.isArray(entries))
114
- throw new DictionaryError(`${source}: "entries" must be an array.`);
115
- const parsed = entries.map((entry, index) => parseEntry(entry, `${source}: entries[${index}]`));
116
- return new Dictionary(parsed);
117
- }
118
- function stringArray(value, where) {
119
- if (value === undefined)
120
- return undefined;
121
- if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
122
- throw new DictionaryError(`${where} must be an array of strings.`);
123
- }
124
- return value;
125
- }
126
- function parseEntry(entry, where) {
127
- if (typeof entry === "string")
128
- return { word: entry };
129
- if (typeof entry !== "object" || entry === null)
130
- throw new DictionaryError(`${where} must be a string or an object.`);
131
- const record = entry;
132
- const word = record["word"];
133
- if (typeof word !== "string" || word.trim().length === 0)
134
- throw new DictionaryError(`${where}.word must be a string that is not empty.`);
135
- const pos = record["pos"];
136
- if (pos !== undefined && typeof pos !== "string")
137
- throw new DictionaryError(`${where}.pos must be a string.`);
138
- const approved = record["approved"];
139
- if (approved !== undefined && typeof approved !== "boolean")
140
- throw new DictionaryError(`${where}.approved must be true or false.`);
141
- const forms = stringArray(record["forms"], `${where}.forms`);
142
- const alternatives = stringArray(record["alternatives"], `${where}.alternatives`);
143
- return {
144
- word,
145
- ...(pos === undefined ? {} : { pos }),
146
- ...(approved === undefined ? {} : { approved }),
147
- ...(forms === undefined ? {} : { forms }),
148
- ...(alternatives === undefined ? {} : { alternatives }),
149
- };
150
- }
6
+ import { DictionaryError, parseDictionary } from "./dictionary-core.js";
7
+ export * from "./dictionary-core.js";
151
8
  /** This function reads a dictionary file. */
152
9
  export function loadDictionary(path) {
153
10
  let text;
@@ -1 +1 @@
1
- {"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../src/dictionary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,IAAI,CAAC;QACD,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,iCAAkC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,44 @@
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 type { ResolvedConfig } from "./config-core.js";
7
+ import { type Lexicon } from "./lexicon.js";
8
+ import { type Extraction } from "./source/markdown.js";
9
+ import type { Finding } from "./types.js";
10
+ import { type ProseUnit } from "./units.js";
11
+ export type FileKind = "markdown" | "mdx" | "typescript";
12
+ /** The kind of a file, from its extension, or null when the linter cannot read it. */
13
+ export declare function fileKind(path: string): FileKind | null;
14
+ /**
15
+ * A function that extracts the prose of a TypeScript or JavaScript file:
16
+ * the doc comments, and the JSX text of a TSX or JSX file.
17
+ */
18
+ export type CodeExtractor = (text: string, path: string) => Extraction;
19
+ export type ProseLinterOptions = {
20
+ /**
21
+ * The extractor for TypeScript and JavaScript files. Without it, the
22
+ * linter gives no findings for these files. The extractor of this
23
+ * package (`extractCode`) needs the `typescript` package.
24
+ */
25
+ readonly extractCode?: CodeExtractor;
26
+ };
27
+ /**
28
+ * A linter for one configuration, for text in memory. It makes the lexicon
29
+ * and the word list matcher one time. It reads no file.
30
+ */
31
+ export declare class ProseLinter {
32
+ readonly config: ResolvedConfig;
33
+ readonly lexicon: Lexicon;
34
+ private readonly wordList;
35
+ private readonly rules;
36
+ private readonly extractCode;
37
+ constructor(config: ResolvedConfig, lexicon?: Lexicon, options?: ProseLinterOptions);
38
+ /** The prose units of a file. */
39
+ units(text: string, path: string): ProseUnit[];
40
+ /** The findings in `text`. `path` gives the kind of file, and it is the file name in the findings. */
41
+ lintText(text: string, path: string): Finding[];
42
+ private extract;
43
+ }
44
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAI1D,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAExE,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;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,KAAK,UAAU,CAAC;AAEzE,MAAM,MAAM,kBAAkB,GAAG;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAG,aAAa,CAAC;CACzC,CAAC;AAEF;;;GAGG;AACH,qBAAa,WAAW;IAMR,QAAQ,CAAC,MAAM,EAAG,cAAc;IAL5C,QAAQ,CAAC,OAAO,EAAG,OAAO,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgF;IACtG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;gBAE/B,MAAM,EAAG,cAAc,EAAE,OAAO,CAAC,EAAG,OAAO,EAAE,OAAO,GAAG,kBAAuB;IAYnG,iCAAiC;IACjC,KA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