@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.
- package/README.md +246 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-core.d.ts +92 -0
- package/dist/config-core.d.ts.map +1 -0
- package/dist/config-core.js +198 -0
- package/dist/config-core.js.map +1 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +68 -0
- package/dist/config.js.map +1 -0
- package/dist/core.d.ts +16 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +16 -0
- package/dist/core.js.map +1 -0
- package/dist/dictionary-core.d.ts +72 -0
- package/dist/dictionary-core.d.ts.map +1 -0
- package/dist/dictionary-core.js +150 -0
- package/dist/dictionary-core.js.map +1 -0
- package/dist/dictionary.d.ts +9 -0
- package/dist/dictionary.d.ts.map +1 -0
- package/dist/dictionary.js +26 -0
- package/dist/dictionary.js.map +1 -0
- package/dist/engine.d.ts +44 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +122 -0
- package/dist/engine.js.map +1 -0
- package/dist/files.d.ts +35 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +181 -0
- package/dist/files.js.map +1 -0
- package/dist/format.d.ts +21 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +61 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/lexicon.d.ts +33 -0
- package/dist/lexicon.d.ts.map +1 -0
- package/dist/lexicon.js +71 -0
- package/dist/lexicon.js.map +1 -0
- package/dist/lint.d.ts +18 -0
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +23 -0
- package/dist/lint.js.map +1 -0
- package/dist/rules/about-quantity.d.ts +3 -0
- package/dist/rules/about-quantity.d.ts.map +1 -0
- package/dist/rules/about-quantity.js +34 -0
- package/dist/rules/about-quantity.js.map +1 -0
- package/dist/rules/index.d.ts +8 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +35 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/ing-verb.d.ts +9 -0
- package/dist/rules/ing-verb.d.ts.map +1 -0
- package/dist/rules/ing-verb.js +60 -0
- package/dist/rules/ing-verb.js.map +1 -0
- package/dist/rules/latin-abbreviation.d.ts +3 -0
- package/dist/rules/latin-abbreviation.d.ts.map +1 -0
- package/dist/rules/latin-abbreviation.js +48 -0
- package/dist/rules/latin-abbreviation.js.map +1 -0
- package/dist/rules/missing-subject.d.ts +16 -0
- package/dist/rules/missing-subject.d.ts.map +1 -0
- package/dist/rules/missing-subject.js +138 -0
- package/dist/rules/missing-subject.js.map +1 -0
- package/dist/rules/modal-verb.d.ts +3 -0
- package/dist/rules/modal-verb.d.ts.map +1 -0
- package/dist/rules/modal-verb.js +72 -0
- package/dist/rules/modal-verb.js.map +1 -0
- package/dist/rules/noun-cluster.d.ts +17 -0
- package/dist/rules/noun-cluster.d.ts.map +1 -0
- package/dist/rules/noun-cluster.js +83 -0
- package/dist/rules/noun-cluster.js.map +1 -0
- package/dist/rules/paragraph-length.d.ts +3 -0
- package/dist/rules/paragraph-length.d.ts.map +1 -0
- package/dist/rules/paragraph-length.js +19 -0
- package/dist/rules/paragraph-length.js.map +1 -0
- package/dist/rules/passive-instruction.d.ts +15 -0
- package/dist/rules/passive-instruction.d.ts.map +1 -0
- package/dist/rules/passive-instruction.js +38 -0
- package/dist/rules/passive-instruction.js.map +1 -0
- package/dist/rules/pronouns.d.ts +4 -0
- package/dist/rules/pronouns.d.ts.map +1 -0
- package/dist/rules/pronouns.js +57 -0
- package/dist/rules/pronouns.js.map +1 -0
- package/dist/rules/rule.d.ts +46 -0
- package/dist/rules/rule.d.ts.map +1 -0
- package/dist/rules/rule.js +31 -0
- package/dist/rules/rule.js.map +1 -0
- package/dist/rules/semicolon.d.ts +3 -0
- package/dist/rules/semicolon.d.ts.map +1 -0
- package/dist/rules/semicolon.js +20 -0
- package/dist/rules/semicolon.js.map +1 -0
- package/dist/rules/sentence-length.d.ts +3 -0
- package/dist/rules/sentence-length.d.ts.map +1 -0
- package/dist/rules/sentence-length.js +31 -0
- package/dist/rules/sentence-length.js.map +1 -0
- package/dist/rules/unknown-word.d.ts +9 -0
- package/dist/rules/unknown-word.d.ts.map +1 -0
- package/dist/rules/unknown-word.js +49 -0
- package/dist/rules/unknown-word.js.map +1 -0
- package/dist/rules/word-list-matcher.d.ts +25 -0
- package/dist/rules/word-list-matcher.d.ts.map +1 -0
- package/dist/rules/word-list-matcher.js +60 -0
- package/dist/rules/word-list-matcher.js.map +1 -0
- package/dist/rules/word-list.d.ts +3 -0
- package/dist/rules/word-list.d.ts.map +1 -0
- package/dist/rules/word-list.js +26 -0
- package/dist/rules/word-list.js.map +1 -0
- package/dist/run-cli.d.ts +27 -0
- package/dist/run-cli.d.ts.map +1 -0
- package/dist/run-cli.js +176 -0
- package/dist/run-cli.js.map +1 -0
- package/dist/source/blocks.d.ts +55 -0
- package/dist/source/blocks.d.ts.map +1 -0
- package/dist/source/blocks.js +464 -0
- package/dist/source/blocks.js.map +1 -0
- package/dist/source/code.d.ts +9 -0
- package/dist/source/code.d.ts.map +1 -0
- package/dist/source/code.js +16 -0
- package/dist/source/code.js.map +1 -0
- package/dist/source/inline.d.ts +42 -0
- package/dist/source/inline.d.ts.map +1 -0
- package/dist/source/inline.js +396 -0
- package/dist/source/inline.js.map +1 -0
- package/dist/source/jsx.d.ts +18 -0
- package/dist/source/jsx.d.ts.map +1 -0
- package/dist/source/jsx.js +137 -0
- package/dist/source/jsx.js.map +1 -0
- package/dist/source/lines.d.ts +34 -0
- package/dist/source/lines.d.ts.map +1 -0
- package/dist/source/lines.js +83 -0
- package/dist/source/lines.js.map +1 -0
- package/dist/source/markdown.d.ts +23 -0
- package/dist/source/markdown.d.ts.map +1 -0
- package/dist/source/markdown.js +42 -0
- package/dist/source/markdown.js.map +1 -0
- package/dist/source/suppressions.d.ts +38 -0
- package/dist/source/suppressions.d.ts.map +1 -0
- package/dist/source/suppressions.js +69 -0
- package/dist/source/suppressions.js.map +1 -0
- package/dist/source/tsdoc.d.ts +40 -0
- package/dist/source/tsdoc.d.ts.map +1 -0
- package/dist/source/tsdoc.js +176 -0
- package/dist/source/tsdoc.js.map +1 -0
- package/dist/text/grammar.d.ts +91 -0
- package/dist/text/grammar.d.ts.map +1 -0
- package/dist/text/grammar.js +289 -0
- package/dist/text/grammar.js.map +1 -0
- package/dist/text/phrases.d.ts +30 -0
- package/dist/text/phrases.d.ts.map +1 -0
- package/dist/text/phrases.js +65 -0
- package/dist/text/phrases.js.map +1 -0
- package/dist/text/sentences.d.ts +45 -0
- package/dist/text/sentences.d.ts.map +1 -0
- package/dist/text/sentences.js +141 -0
- package/dist/text/sentences.js.map +1 -0
- package/dist/text/tokens.d.ts +35 -0
- package/dist/text/tokens.d.ts.map +1 -0
- package/dist/text/tokens.js +113 -0
- package/dist/text/tokens.js.map +1 -0
- package/dist/text/words.d.ts +58 -0
- package/dist/text/words.d.ts.map +1 -0
- package/dist/text/words.js +159 -0
- package/dist/text/words.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +47 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +42 -0
- package/dist/units.js.map +1 -0
- package/dist/word-list.d.ts +34 -0
- package/dist/word-list.d.ts.map +1 -0
- package/dist/word-list.js +90 -0
- package/dist/word-list.js.map +1 -0
- package/package.json +54 -3
- package/src/cli.ts +9 -0
- package/src/config-core.ts +258 -0
- package/src/config.test.ts +188 -0
- package/src/config.ts +83 -0
- package/src/core.test.ts +87 -0
- package/src/core.ts +32 -0
- package/src/dictionary-core.ts +158 -0
- package/src/dictionary.test.ts +82 -0
- package/src/dictionary.ts +26 -0
- package/src/engine.ts +138 -0
- package/src/files.test.ts +107 -0
- package/src/files.ts +191 -0
- package/src/format.ts +78 -0
- package/src/index.test.ts +28 -0
- package/src/index.ts +38 -0
- package/src/lexicon.ts +92 -0
- package/src/lint.test.ts +182 -0
- package/src/lint.ts +30 -0
- package/src/rules/about-quantity.ts +33 -0
- package/src/rules/index.ts +40 -0
- package/src/rules/ing-verb.test.ts +48 -0
- package/src/rules/ing-verb.ts +54 -0
- package/src/rules/latin-abbreviation.ts +46 -0
- package/src/rules/missing-subject.test.ts +53 -0
- package/src/rules/missing-subject.ts +129 -0
- package/src/rules/modal-verb.test.ts +45 -0
- package/src/rules/modal-verb.ts +72 -0
- package/src/rules/noun-cluster.test.ts +49 -0
- package/src/rules/noun-cluster.ts +82 -0
- package/src/rules/paragraph-length.test.ts +30 -0
- package/src/rules/paragraph-length.ts +19 -0
- package/src/rules/passive-instruction.test.ts +38 -0
- package/src/rules/passive-instruction.ts +37 -0
- package/src/rules/pronouns.test.ts +38 -0
- package/src/rules/pronouns.ts +54 -0
- package/src/rules/punctuation.test.ts +59 -0
- package/src/rules/rule.ts +73 -0
- package/src/rules/semicolon.ts +19 -0
- package/src/rules/sentence-length.test.ts +52 -0
- package/src/rules/sentence-length.ts +32 -0
- package/src/rules/unknown-word.test.ts +81 -0
- package/src/rules/unknown-word.ts +43 -0
- package/src/rules/word-list-matcher.ts +68 -0
- package/src/rules/word-list.test.ts +110 -0
- package/src/rules/word-list.ts +25 -0
- package/src/run-cli.test.ts +189 -0
- package/src/run-cli.ts +193 -0
- package/src/source/blocks.ts +534 -0
- package/src/source/code.ts +17 -0
- package/src/source/inline.test.ts +92 -0
- package/src/source/inline.ts +416 -0
- package/src/source/jsx.test.ts +46 -0
- package/src/source/jsx.ts +147 -0
- package/src/source/lines.test.ts +51 -0
- package/src/source/lines.ts +91 -0
- package/src/source/markdown.test.ts +210 -0
- package/src/source/markdown.ts +49 -0
- package/src/source/suppressions.ts +79 -0
- package/src/source/tsdoc.test.ts +137 -0
- package/src/source/tsdoc.ts +189 -0
- package/src/text/grammar.ts +304 -0
- package/src/text/phrases.ts +72 -0
- package/src/text/sentences.ts +148 -0
- package/src/text/text.test.ts +262 -0
- package/src/text/tokens.ts +135 -0
- package/src/text/words.ts +183 -0
- package/src/types.ts +39 -0
- package/src/units.ts +86 -0
- package/src/word-list.ts +128 -0
- package/ste.config.schema.json +87 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of the configuration that need no file system: the types of
|
|
3
|
+
* `ste.config.json`, the defaults, the validation and the word list merge.
|
|
4
|
+
* A browser can use this module.
|
|
5
|
+
*/
|
|
6
|
+
import { isRuleId, RULE_IDS } from "./types.js";
|
|
7
|
+
import { DEFAULT_WORD_LIST } from "./word-list.js";
|
|
8
|
+
export const CONFIG_FILE_NAME = "ste.config.json";
|
|
9
|
+
/** The environment variable that gives the path of the local dictionary. It has priority over `dictionaryPath`. */
|
|
10
|
+
export const DICTIONARY_ENV = "STE_DICTIONARY";
|
|
11
|
+
export const DEFAULT_INCLUDE = [
|
|
12
|
+
"README.md",
|
|
13
|
+
"docs/**/*.{md,mdx}",
|
|
14
|
+
"packages/*/README.md",
|
|
15
|
+
"packages/*/src/**/*.{ts,tsx}",
|
|
16
|
+
"packages/*/build/**/*.{ts,tsx}",
|
|
17
|
+
"packages/*/commands/**/*.{ts,tsx}",
|
|
18
|
+
"packages/*/*.config.{ts,mts}",
|
|
19
|
+
];
|
|
20
|
+
export const DEFAULT_IGNORE = [
|
|
21
|
+
"**/node_modules/**",
|
|
22
|
+
"**/dist/**",
|
|
23
|
+
"**/*.d.ts",
|
|
24
|
+
"**/*.test.ts",
|
|
25
|
+
"**/*.test.tsx",
|
|
26
|
+
"**/*.spec.ts",
|
|
27
|
+
"**/*.spec.tsx",
|
|
28
|
+
];
|
|
29
|
+
export const DEFAULT_LIMITS = {
|
|
30
|
+
instructionWords: 20,
|
|
31
|
+
descriptionWords: 25,
|
|
32
|
+
paragraphSentences: 6,
|
|
33
|
+
nounClusterNouns: 3,
|
|
34
|
+
};
|
|
35
|
+
/** An error in the configuration. */
|
|
36
|
+
export class ConfigError extends Error {
|
|
37
|
+
name = "ConfigError";
|
|
38
|
+
}
|
|
39
|
+
const SETTINGS = ["error", "warning", "off"];
|
|
40
|
+
const KNOWN_KEYS = new Set([
|
|
41
|
+
"$schema", "include", "ignore", "technicalNouns", "technicalVerbs", "properNouns", "allowedWords",
|
|
42
|
+
"rules", "wordList", "limits", "dictionaryPath",
|
|
43
|
+
]);
|
|
44
|
+
const WORD_LIST_KEYS = new Set(["id", "match", "suggest", "note", "severity", "verbOnly"]);
|
|
45
|
+
/** This function makes sure that `value` is a valid configuration. It throws a `ConfigError` that lists all problems. */
|
|
46
|
+
export function validateConfig(value, source) {
|
|
47
|
+
const problems = [];
|
|
48
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
49
|
+
throw new ConfigError(`${source}: the configuration must be a JSON object.`);
|
|
50
|
+
}
|
|
51
|
+
const record = value;
|
|
52
|
+
for (const key of Object.keys(record)) {
|
|
53
|
+
if (!KNOWN_KEYS.has(key))
|
|
54
|
+
problems.push(`"${key}" is not a known property. Known properties: ${[...KNOWN_KEYS].join(", ")}.`);
|
|
55
|
+
}
|
|
56
|
+
for (const key of ["include", "ignore", "technicalNouns", "technicalVerbs", "properNouns", "allowedWords"]) {
|
|
57
|
+
const item = record[key];
|
|
58
|
+
if (item !== undefined && !(Array.isArray(item) && item.every((entry) => typeof entry === "string"))) {
|
|
59
|
+
problems.push(`"${key}" must be an array of strings.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const rules = record["rules"];
|
|
63
|
+
if (rules !== undefined) {
|
|
64
|
+
if (typeof rules !== "object" || rules === null || Array.isArray(rules)) {
|
|
65
|
+
problems.push(`"rules" must be an object.`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
for (const [id, setting] of Object.entries(rules)) {
|
|
69
|
+
if (!isRuleId(id))
|
|
70
|
+
problems.push(`"rules.${id}" is not a known rule. Known rules: ${RULE_IDS.join(", ")}.`);
|
|
71
|
+
if (typeof setting !== "string" || !SETTINGS.includes(setting))
|
|
72
|
+
problems.push(`"rules.${id}" must be "error", "warning" or "off".`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const limits = record["limits"];
|
|
77
|
+
if (limits !== undefined) {
|
|
78
|
+
if (typeof limits !== "object" || limits === null || Array.isArray(limits)) {
|
|
79
|
+
problems.push(`"limits" must be an object.`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
for (const [key, limit] of Object.entries(limits)) {
|
|
83
|
+
if (!Object.hasOwn(DEFAULT_LIMITS, key))
|
|
84
|
+
problems.push(`"limits.${key}" is not a known limit. Known limits: ${Object.keys(DEFAULT_LIMITS).join(", ")}.`);
|
|
85
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1)
|
|
86
|
+
problems.push(`"limits.${key}" must be an integer of 1 or more.`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const dictionaryPath = record["dictionaryPath"];
|
|
91
|
+
if (dictionaryPath !== undefined && dictionaryPath !== null && typeof dictionaryPath !== "string") {
|
|
92
|
+
problems.push(`"dictionaryPath" must be a string or null.`);
|
|
93
|
+
}
|
|
94
|
+
const wordList = record["wordList"];
|
|
95
|
+
if (wordList !== undefined) {
|
|
96
|
+
if (!Array.isArray(wordList)) {
|
|
97
|
+
problems.push(`"wordList" must be an array.`);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
wordList.forEach((item, index) => problems.push(...validateWordListEntry(item, `wordList[${index}]`)));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (problems.length > 0)
|
|
104
|
+
throw new ConfigError(`${source}:\n - ${problems.join("\n - ")}`);
|
|
105
|
+
return record;
|
|
106
|
+
}
|
|
107
|
+
function validateWordListEntry(item, where) {
|
|
108
|
+
if (typeof item !== "object" || item === null || Array.isArray(item))
|
|
109
|
+
return [`"${where}" must be an object.`];
|
|
110
|
+
const problems = [];
|
|
111
|
+
const entry = item;
|
|
112
|
+
for (const key of Object.keys(entry)) {
|
|
113
|
+
if (!WORD_LIST_KEYS.has(key))
|
|
114
|
+
problems.push(`"${where}.${key}" is not a known property.`);
|
|
115
|
+
}
|
|
116
|
+
const match = entry["match"];
|
|
117
|
+
const matchValid = typeof match === "string" || (Array.isArray(match) && match.length > 0 && match.every((word) => typeof word === "string"));
|
|
118
|
+
if (match !== undefined && !matchValid)
|
|
119
|
+
problems.push(`"${where}.match" must be a string or an array of strings.`);
|
|
120
|
+
if (entry["id"] !== undefined && typeof entry["id"] !== "string")
|
|
121
|
+
problems.push(`"${where}.id" must be a string.`);
|
|
122
|
+
if (entry["id"] === undefined && match === undefined)
|
|
123
|
+
problems.push(`"${where}" must have "id" or "match".`);
|
|
124
|
+
for (const key of ["suggest", "note"]) {
|
|
125
|
+
const text = entry[key];
|
|
126
|
+
if (text !== undefined && text !== null && typeof text !== "string")
|
|
127
|
+
problems.push(`"${where}.${key}" must be a string or null.`);
|
|
128
|
+
}
|
|
129
|
+
const severity = entry["severity"];
|
|
130
|
+
if (severity !== undefined && (typeof severity !== "string" || !SETTINGS.includes(severity)))
|
|
131
|
+
problems.push(`"${where}.severity" must be "error", "warning" or "off".`);
|
|
132
|
+
if (entry["verbOnly"] !== undefined && typeof entry["verbOnly"] !== "boolean")
|
|
133
|
+
problems.push(`"${where}.verbOnly" must be true or false.`);
|
|
134
|
+
return problems;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* This function merges the default word list and the entries of the
|
|
138
|
+
* configuration. An entry with the ID (or the first `match` word) of a
|
|
139
|
+
* default entry changes that entry. The severity "off" removes the entry
|
|
140
|
+
* with that ID, and it removes the `match` words from all entries.
|
|
141
|
+
*/
|
|
142
|
+
export function mergeWordList(defaults, overrides) {
|
|
143
|
+
const entries = new Map(defaults.map((entry) => [entry.id, entry]));
|
|
144
|
+
for (const override of overrides) {
|
|
145
|
+
const match = override.match === undefined ? undefined : typeof override.match === "string" ? [override.match] : [...override.match];
|
|
146
|
+
const id = override.id ?? match[0];
|
|
147
|
+
const base = entries.get(id) ?? null;
|
|
148
|
+
if (override.severity === "off") {
|
|
149
|
+
entries.set(id, null);
|
|
150
|
+
const removed = new Set((match ?? []).map((word) => word.toLowerCase()));
|
|
151
|
+
for (const [key, entry] of entries) {
|
|
152
|
+
if (entry === null)
|
|
153
|
+
continue;
|
|
154
|
+
const kept = entry.match.filter((word) => !removed.has(word.toLowerCase()));
|
|
155
|
+
entries.set(key, kept.length === 0 ? null : { ...entry, match: kept });
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const merged = {
|
|
160
|
+
id,
|
|
161
|
+
match: match ?? base?.match ?? [id],
|
|
162
|
+
suggest: override.suggest !== undefined ? override.suggest : base?.suggest ?? null,
|
|
163
|
+
note: override.note !== undefined ? override.note : base?.note ?? null,
|
|
164
|
+
severity: override.severity ?? base?.severity ?? "error",
|
|
165
|
+
verbOnly: override.verbOnly ?? base?.verbOnly ?? false,
|
|
166
|
+
context: base?.context ?? null,
|
|
167
|
+
};
|
|
168
|
+
entries.set(id, merged);
|
|
169
|
+
}
|
|
170
|
+
return [...entries.values()].filter((entry) => entry !== null);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* This function applies the defaults to a configuration file. It reads no
|
|
174
|
+
* file and no environment variable, thus the result has no dictionary path.
|
|
175
|
+
*/
|
|
176
|
+
export function baseConfig(file = {}, options = {}) {
|
|
177
|
+
const rules = {};
|
|
178
|
+
for (const [id, setting] of Object.entries(file.rules ?? {})) {
|
|
179
|
+
if (isRuleId(id))
|
|
180
|
+
rules[id] = setting;
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
root: options.root ?? "",
|
|
184
|
+
configFile: options.configFile ?? null,
|
|
185
|
+
include: file.include ?? DEFAULT_INCLUDE,
|
|
186
|
+
ignore: file.ignore ?? DEFAULT_IGNORE,
|
|
187
|
+
technicalNouns: file.technicalNouns ?? [],
|
|
188
|
+
technicalVerbs: file.technicalVerbs ?? [],
|
|
189
|
+
properNouns: file.properNouns ?? [],
|
|
190
|
+
allowedWords: file.allowedWords ?? [],
|
|
191
|
+
rules,
|
|
192
|
+
wordList: mergeWordList(DEFAULT_WORD_LIST, file.wordList ?? []),
|
|
193
|
+
limits: { ...DEFAULT_LIMITS, ...file.limits },
|
|
194
|
+
dictionaryPath: null,
|
|
195
|
+
dictionarySource: null,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=config-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-core.js","sourceRoot":"","sources":["../src/config-core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAgD,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC;AAEvE,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,mHAAmH;AACnH,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AA8D/C,MAAM,CAAC,MAAM,eAAe,GAAuB;IAC/C,WAAW;IACX,oBAAoB;IACpB,sBAAsB;IACtB,8BAA8B;IAC9B,gCAAgC;IAChC,mCAAmC;IACnC,8BAA8B;CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAuB;IAC9C,oBAAoB;IACpB,YAAY;IACZ,WAAW;IACX,cAAc;IACd,eAAe;IACf,cAAc;IACd,eAAe;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAY;IACnC,gBAAgB,EAAG,EAAE;IACrB,gBAAgB,E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EAAG,OAAO,CAAC,UAAU,IAAI,IAAI;QACvC,OAAO,EAAG,IAAI,CAAC,OAAO,IAAI,eAAe;QACzC,MAAM,EAAG,IAAI,CAAC,MAAM,IAAI,cAAc;QACtC,cAAc,EAAG,IAAI,CAAC,cAAc,IAAI,EAAE;QAC1C,cAAc,EAAG,IAAI,CAAC,cAAc,IAAI,EAAE;QAC1C,WAAW,EAAG,IAAI,CAAC,WAAW,IAAI,EAAE;QACpC,YAAY,EAAG,IAAI,CAAC,YAAY,IAAI,EAAE;QACtC,KAAK;QACL,QAAQ,EAAG,aAAa,CAAC,iBAAiB,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;QAChE,MAAM,EAAG,EAAE,GAAG,cAAc,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE;QAC9C,cAAc,EAAG,IAAI;QACrB,gBAAgB,EAAG,IAAI;KAC1B,CAAC;AACN,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configuration file `ste.config.json`, and the configuration that the
|
|
3
|
+
* linter uses after it reads the file, the environment and the defaults.
|
|
4
|
+
*/
|
|
5
|
+
import { type ResolvedConfig, type SteConfigFile } from "./config-core.js";
|
|
6
|
+
export * from "./config-core.js";
|
|
7
|
+
/** This function expands a leading `~/` to the home directory, and makes the path absolute. */
|
|
8
|
+
export declare function resolvePath(path: string, base: string): string;
|
|
9
|
+
export type ResolveOptions = {
|
|
10
|
+
/** The directory of the configuration file, or the working directory. */
|
|
11
|
+
readonly root: string;
|
|
12
|
+
readonly configFile?: string | null;
|
|
13
|
+
/** The working directory. `STE_DICTIONARY` is relative to it. */
|
|
14
|
+
readonly cwd?: string;
|
|
15
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
16
|
+
};
|
|
17
|
+
/** This function applies the defaults and the environment to a configuration file. */
|
|
18
|
+
export declare function resolveConfig(file: SteConfigFile, options: ResolveOptions): ResolvedConfig;
|
|
19
|
+
/** The first `ste.config.json` in `cwd` or one of its parent directories, or null. */
|
|
20
|
+
export declare function findConfigFile(cwd: string): string | null;
|
|
21
|
+
export type LoadOptions = {
|
|
22
|
+
readonly cwd: string;
|
|
23
|
+
/** An explicit configuration file. Without it, the linter looks for `ste.config.json`. */
|
|
24
|
+
readonly configPath?: string;
|
|
25
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
26
|
+
};
|
|
27
|
+
/** This function reads the configuration file, if there is one, and resolves it. */
|
|
28
|
+
export declare function loadConfig(options: LoadOptions): ResolvedConfig;
|
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAA6E,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtJ,cAAc,kBAAkB,CAAC;AAEjC,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,IAAI,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,GAAI,MAAM,CAGjE;AAED,MAAM,MAAM,cAAc,GAAG;IACzB,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAG,MAAM,GAAG,IAAI,CAAC;IACrC,iEAAiE;IACjE,QAAQ,CAAC,GAAG,CAAC,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,IAAI,EAAG,aAAa,EAAE,OAAO,EAAG,cAAc,GAAI,cAAc,CAc7F;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,GAAG,EAAG,MAAM,GAAI,MAAM,GAAG,IAAI,CAS3D;AAED,MAAM,MAAM,WAAW,GAAG;IACtB,QAAQ,CAAC,GAAG,EAAG,MAAM,CAAC;IACtB,0FAA0F;IAC1F,QAAQ,CAAC,UAAU,CAAC,EAAG,MAAM,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,OAAO,EAAG,WAAW,GAAI,cAAc,CAkBjE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configuration file `ste.config.json`, and the configuration that the
|
|
3
|
+
* linter uses after it reads the file, the environment and the defaults.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { baseConfig, CONFIG_FILE_NAME, ConfigError, DICTIONARY_ENV, validateConfig } from "./config-core.js";
|
|
9
|
+
export * from "./config-core.js";
|
|
10
|
+
/** This function expands a leading `~/` to the home directory, and makes the path absolute. */
|
|
11
|
+
export function resolvePath(path, base) {
|
|
12
|
+
const expanded = path === "~" ? homedir() : path.startsWith("~/") || path.startsWith("~\\") ? join(homedir(), path.slice(2)) : path;
|
|
13
|
+
return resolve(base, expanded);
|
|
14
|
+
}
|
|
15
|
+
/** This function applies the defaults and the environment to a configuration file. */
|
|
16
|
+
export function resolveConfig(file, options) {
|
|
17
|
+
const env = options.env ?? {};
|
|
18
|
+
const cwd = options.cwd ?? options.root;
|
|
19
|
+
const fromEnv = env[DICTIONARY_ENV];
|
|
20
|
+
let dictionaryPath = null;
|
|
21
|
+
let dictionarySource = null;
|
|
22
|
+
if (fromEnv !== undefined && fromEnv.trim().length > 0) {
|
|
23
|
+
dictionaryPath = resolvePath(fromEnv.trim(), cwd);
|
|
24
|
+
dictionarySource = "env";
|
|
25
|
+
}
|
|
26
|
+
else if (typeof file.dictionaryPath === "string" && file.dictionaryPath.trim().length > 0) {
|
|
27
|
+
dictionaryPath = resolvePath(file.dictionaryPath.trim(), options.root);
|
|
28
|
+
dictionarySource = "config";
|
|
29
|
+
}
|
|
30
|
+
return { ...baseConfig(file, { root: options.root, configFile: options.configFile ?? null }), dictionaryPath, dictionarySource };
|
|
31
|
+
}
|
|
32
|
+
/** The first `ste.config.json` in `cwd` or one of its parent directories, or null. */
|
|
33
|
+
export function findConfigFile(cwd) {
|
|
34
|
+
let directory = resolve(cwd);
|
|
35
|
+
for (;;) {
|
|
36
|
+
const candidate = join(directory, CONFIG_FILE_NAME);
|
|
37
|
+
if (existsSync(candidate))
|
|
38
|
+
return candidate;
|
|
39
|
+
const parent = dirname(directory);
|
|
40
|
+
if (parent === directory)
|
|
41
|
+
return null;
|
|
42
|
+
directory = parent;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** This function reads the configuration file, if there is one, and resolves it. */
|
|
46
|
+
export function loadConfig(options) {
|
|
47
|
+
const configFile = options.configPath !== undefined ? resolve(options.cwd, options.configPath) : findConfigFile(options.cwd);
|
|
48
|
+
const env = options.env ?? {};
|
|
49
|
+
if (configFile === null)
|
|
50
|
+
return resolveConfig({}, { root: resolve(options.cwd), cwd: options.cwd, env });
|
|
51
|
+
let text;
|
|
52
|
+
try {
|
|
53
|
+
text = readFileSync(configFile, "utf8");
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new ConfigError(`Cannot read the configuration file ${configFile}: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
let value;
|
|
59
|
+
try {
|
|
60
|
+
value = JSON.parse(text);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new ConfigError(`${configFile}: the file is not valid JSON: ${error.message}`);
|
|
64
|
+
}
|
|
65
|
+
const file = validateConfig(value, configFile);
|
|
66
|
+
return resolveConfig(file, { root: dirname(configFile), configFile, cwd: options.cwd, env });
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAA2C,MAAM,kBAAkB,CAAC;AAEtJ,cAAc,kBAAkB,CAAC;AAEjC,+FAA+F;AAC/F,MAAM,UAAU,WAAW,CAAC,IAAa,EAAE,IAAa;IACpD,MAAM,QAAQ,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpI,OAAO,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAWD,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAAC,IAAoB,EAAE,OAAwB;IACxE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IACxC,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC;IACpC,IAAI,cAAc,GAAmB,IAAI,CAAC;IAC1C,IAAI,gBAAg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browser or another host that has the text in memory. It examines Markdown
|
|
4
|
+
* and MDX. For TypeScript doc comments, give the extractor of
|
|
5
|
+
* `@mark1russell7/ste-lint/code` to `ProseLinter`. The rules are the same
|
|
6
|
+
* rules that the command line uses.
|
|
7
|
+
*/
|
|
8
|
+
export { baseConfig, CONFIG_FILE_NAME, ConfigError, DEFAULT_IGNORE, DEFAULT_INCLUDE, DEFAULT_LIMITS, DICTIONARY_ENV, mergeWordList, validateConfig, type BaseConfigOptions, type Limits, type LimitsConfig, type ResolvedConfig, type SteConfigFile, type WordListEntryConfig, } from "./config-core.js";
|
|
9
|
+
export { Dictionary, DICTIONARY_FORMAT, DictionaryError, parseDictionary, type DictionaryEntry, type DictionaryLookup } from "./dictionary-core.js";
|
|
10
|
+
export { fileKind, ProseLinter, type CodeExtractor, type FileKind, type ProseLinterOptions } from "./engine.js";
|
|
11
|
+
export { formatJson, formatText, summarize, type RuleCount, type Summary } from "./format.js";
|
|
12
|
+
export { buildLexicon, type Lexicon } from "./lexicon.js";
|
|
13
|
+
export { getRule, RULES, type Rule } from "./rules/index.js";
|
|
14
|
+
export { isRuleId, RULE_IDS, type Finding, type RuleId, type RuleSetting, type Severity } from "./types.js";
|
|
15
|
+
export { DEFAULT_WORD_LIST, type WordListEntry } from "./word-list.js";
|
|
16
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACpJ,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChH,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,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7D,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/core.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mark1russell7/ste-lint/core`: the linter without a file system, for a
|
|
3
|
+
* browser or another host that has the text in memory. It examines Markdown
|
|
4
|
+
* and MDX. For TypeScript doc comments, give the extractor of
|
|
5
|
+
* `@mark1russell7/ste-lint/code` to `ProseLinter`. The rules are the same
|
|
6
|
+
* rules that the command line uses.
|
|
7
|
+
*/
|
|
8
|
+
export { baseConfig, CONFIG_FILE_NAME, ConfigError, DEFAULT_IGNORE, DEFAULT_INCLUDE, DEFAULT_LIMITS, DICTIONARY_ENV, mergeWordList, validateConfig, } from "./config-core.js";
|
|
9
|
+
export { Dictionary, DICTIONARY_FORMAT, DictionaryError, parseDictionary } from "./dictionary-core.js";
|
|
10
|
+
export { fileKind, ProseLinter } from "./engine.js";
|
|
11
|
+
export { formatJson, formatText, summarize } from "./format.js";
|
|
12
|
+
export { buildLexicon } from "./lexicon.js";
|
|
13
|
+
export { getRule, RULES } from "./rules/index.js";
|
|
14
|
+
export { isRuleId, RULE_IDS } from "./types.js";
|
|
15
|
+
export { DEFAULT_WORD_LIST } from "./word-list.js";
|
|
16
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,GAOjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,eAAe,EAA+C,MAAM,sBAAsB,CAAC;AACpJ,OAAO,EAAE,QAAQ,EAAE,WAAW,EAA8D,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAgC,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAgB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAA8D,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC"}
|
|
@@ -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,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C,cAAc,CAAC,EAAE,GAAG,KAAK,eAAe,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
4
|
+
*/
|
|
5
|
+
import { type Dictionary } from "./dictionary-core.js";
|
|
6
|
+
export * from "./dictionary-core.js";
|
|
7
|
+
/** This function reads a dictionary file. */
|
|
8
|
+
export declare function loadDictionary(path: string): Dictionary;
|
|
9
|
+
//# sourceMappingURL=dictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../src/dictionary.ts"],"names":[],"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"}
|