@cspell/eslint-plugin 6.22.0 → 6.23.0
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 +18 -6
- package/dist/common/options.d.ts +86 -0
- package/dist/{ASTNode.js → common/options.js} +0 -0
- package/dist/plugin/cspell-eslint-plugin.d.ts +22 -0
- package/dist/{cspell-eslint-plugin.js → plugin/cspell-eslint-plugin.js} +5 -17
- package/dist/plugin/defaultCheckOptions.d.ts +4 -0
- package/dist/{options.js → plugin/defaultCheckOptions.js} +0 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/{index.js → plugin/index.js} +0 -0
- package/dist/worker/ASTNode.d.mts +7 -0
- package/dist/worker/ASTNode.mjs +1 -0
- package/dist/worker/spellCheck.d.mts +13 -0
- package/dist/{spellCheck.js → worker/spellCheck.mjs} +21 -57
- package/dist/worker/walkTree.d.mts +4 -0
- package/dist/{walkTree.js → worker/walkTree.mjs} +3 -7
- package/dist/worker/worker.d.mts +3 -0
- package/dist/worker/worker.mjs +27 -0
- package/package.json +17 -17
- package/dist/customWordList.js +0 -63
- package/dist/worker.js +0 -51
package/README.md
CHANGED
|
@@ -6,12 +6,6 @@ A spell checker plugin for ESLint based upon CSpell.
|
|
|
6
6
|
|
|
7
7
|
This plugin is still in active development as part of the CSpell suite of tools and applications.
|
|
8
8
|
|
|
9
|
-
## In Combination with CSpell
|
|
10
|
-
|
|
11
|
-
Due to the nature of how files are parsed, the `cspell` command line tool and this ESLint plugin will give different results.
|
|
12
|
-
It is recommended that either ESLint or `cspell` checks a file, but not both. Use `ignorePaths` setting in `cspell.json` to
|
|
13
|
-
tell the `cspell` command line tool to ignore files checked by ESLint.
|
|
14
|
-
|
|
15
9
|
## Quick Setup
|
|
16
10
|
|
|
17
11
|
- Install `@cspell/eslint-plugin` as a dev-dependency
|
|
@@ -109,3 +103,21 @@ Example:
|
|
|
109
103
|
}
|
|
110
104
|
}
|
|
111
105
|
```
|
|
106
|
+
|
|
107
|
+
## In Combination with CSpell
|
|
108
|
+
|
|
109
|
+
Due to the nature of how files are parsed, the `cspell` command line tool and this ESLint plugin will give different results.
|
|
110
|
+
It is recommended that either ESLint or `cspell` checks a file, but not both. Use `ignorePaths` setting in `cspell.json` to
|
|
111
|
+
tell the `cspell` command line tool to ignore files checked by ESLint.
|
|
112
|
+
|
|
113
|
+
Differences:
|
|
114
|
+
|
|
115
|
+
- The CSpell parser is generic across all file types. It just breaks an entire document into words and tests them against the dictionaries. Everything is checked, comments, code, strings, etc.
|
|
116
|
+
|
|
117
|
+
- The CSpell ESLint plugin uses the [AST](https://dev.to/akshay9677/what-the-heck-is-an-abstract-syntax-tree-ast--3kk5) (a way to identify the meaning of the individual parts of your code) provided by ESLint to only check literal strings, identifiers, and comments. See [Options](#options) on selecting what to check.
|
|
118
|
+
|
|
119
|
+
Example spell checked with ESLint CSpell Plugin:
|
|
120
|
+
<img width="749" alt="image" src="https://user-images.githubusercontent.com/3740137/216295162-38ddf6a0-3873-4e48-b3a5-65fd421dae94.png">
|
|
121
|
+
|
|
122
|
+
Example spell checked with just `cspell`:
|
|
123
|
+
<img width="744" alt="image" src="https://user-images.githubusercontent.com/3740137/216295368-024c1065-2432-4d10-b204-7eb0589695e6.png">
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export interface Options extends Check {
|
|
2
|
+
/**
|
|
3
|
+
* Number of spelling suggestions to make.
|
|
4
|
+
* @default 8
|
|
5
|
+
*/
|
|
6
|
+
numSuggestions: number;
|
|
7
|
+
/**
|
|
8
|
+
* Generate suggestions
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
generateSuggestions: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Output debug logs
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
debugMode?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type RequiredOptions = Required<Options>;
|
|
19
|
+
export interface Check {
|
|
20
|
+
/**
|
|
21
|
+
* Ignore import and require names
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
ignoreImports?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Ignore the properties of imported variables, structures, and types.
|
|
27
|
+
*
|
|
28
|
+
* Example:
|
|
29
|
+
* ```
|
|
30
|
+
* import { example } from 'third-party';
|
|
31
|
+
*
|
|
32
|
+
* const msg = example.property; // `property` is not spell checked.
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
ignoreImportProperties?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Spell check identifiers (variables names, function names, class names, etc.)
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
checkIdentifiers?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Spell check strings
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
checkStrings?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Spell check template strings
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
checkStringTemplates?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Spell check JSX Text
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
checkJSXText?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Spell check comments
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
checkComments?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Specify a path to a custom word list file.
|
|
65
|
+
*
|
|
66
|
+
* example:
|
|
67
|
+
* ```js
|
|
68
|
+
* customWordListFile: "./myWords.txt"
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
customWordListFile?: CustomWordListFilePath | CustomWordListFile | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Specify a path to a custom word list file
|
|
75
|
+
*/
|
|
76
|
+
export type CustomWordListFilePath = string;
|
|
77
|
+
export interface CustomWordListFile {
|
|
78
|
+
/**
|
|
79
|
+
* Path to word list file.
|
|
80
|
+
* File format: 1 word per line
|
|
81
|
+
*/
|
|
82
|
+
path: CustomWordListFilePath;
|
|
83
|
+
}
|
|
84
|
+
export type WorkerOptions = RequiredOptions & {
|
|
85
|
+
cwd: string;
|
|
86
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
interface PluginRules {
|
|
3
|
+
['spellchecker']: Rule.RuleModule;
|
|
4
|
+
}
|
|
5
|
+
export declare const rules: PluginRules;
|
|
6
|
+
export declare const configs: {
|
|
7
|
+
recommended: {
|
|
8
|
+
plugins: string[];
|
|
9
|
+
rules: {
|
|
10
|
+
'@cspell/spellchecker': {}[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
debug: {
|
|
14
|
+
plugins: string[];
|
|
15
|
+
rules: {
|
|
16
|
+
'@cspell/spellchecker': (string | {
|
|
17
|
+
debugMode: boolean;
|
|
18
|
+
})[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -5,11 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.configs = exports.rules = void 0;
|
|
7
7
|
const synckit_1 = require("synckit");
|
|
8
|
-
const options_schema_json_1 = __importDefault(require("
|
|
9
|
-
const
|
|
10
|
-
const walkTree_1 = require("./walkTree");
|
|
8
|
+
const options_schema_json_1 = __importDefault(require("../_auto_generated_/options.schema.json"));
|
|
9
|
+
const defaultCheckOptions_1 = require("./defaultCheckOptions");
|
|
11
10
|
const schema = options_schema_json_1.default;
|
|
12
|
-
const spellCheck = (0, synckit_1.createSyncFn)(require.resolve('
|
|
11
|
+
const spellCheck = (0, synckit_1.createSyncFn)(require.resolve('../worker/worker.mjs'), undefined, 30000);
|
|
13
12
|
const messages = {
|
|
14
13
|
wordUnknown: 'Unknown word: "{{word}}"',
|
|
15
14
|
wordForbidden: 'Forbidden word: "{{word}}"',
|
|
@@ -32,22 +31,11 @@ function log(...args) {
|
|
|
32
31
|
return;
|
|
33
32
|
console.log(...args);
|
|
34
33
|
}
|
|
35
|
-
const debugTree = false;
|
|
36
|
-
function dumpTree(context) {
|
|
37
|
-
if (!debugTree)
|
|
38
|
-
return;
|
|
39
|
-
(0, walkTree_1.walkTree)(context.getSourceCode().ast, function (node, _parent, key) {
|
|
40
|
-
const withValue = node;
|
|
41
|
-
console.log('key: %o, node: %o', key, { type: node.type, value: withValue.value });
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
34
|
function create(context) {
|
|
45
|
-
const options = (0,
|
|
35
|
+
const options = (0, defaultCheckOptions_1.normalizeOptions)(context.options[0], context.getCwd());
|
|
46
36
|
isDebugMode = options.debugMode || false;
|
|
47
37
|
isDebugMode && logContext(context);
|
|
48
|
-
dumpTree(context);
|
|
49
38
|
function reportIssue(issue) {
|
|
50
|
-
var _a;
|
|
51
39
|
const messageId = issue.severity === 'Forbidden' ? 'wordForbidden' : 'wordUnknown';
|
|
52
40
|
const { word, start, end } = issue;
|
|
53
41
|
const data = {
|
|
@@ -70,7 +58,7 @@ function create(context) {
|
|
|
70
58
|
};
|
|
71
59
|
}
|
|
72
60
|
log('Suggestions: %o', issue.suggestions);
|
|
73
|
-
const suggestions =
|
|
61
|
+
const suggestions = issue.suggestions?.map(createSug);
|
|
74
62
|
const suggest = suggestions;
|
|
75
63
|
const des = {
|
|
76
64
|
messageId,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Check, Options, RequiredOptions, WorkerOptions } from '../common/options';
|
|
2
|
+
export declare const defaultCheckOptions: Required<Check>;
|
|
3
|
+
export declare const defaultOptions: RequiredOptions;
|
|
4
|
+
export declare function normalizeOptions(opts: Options | undefined, cwd: string): WorkerOptions;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Node } from 'estree';
|
|
2
|
+
import type { WorkerOptions } from '../common/options.js';
|
|
3
|
+
export interface Issue {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
word: string;
|
|
7
|
+
severity: 'Forbidden' | 'Unknown' | 'Hint';
|
|
8
|
+
suggestions: string[] | undefined;
|
|
9
|
+
}
|
|
10
|
+
type SpellCheckFn = typeof spellCheck;
|
|
11
|
+
export type SpellCheckSyncFn = (...p: Parameters<SpellCheckFn>) => Awaited<ReturnType<SpellCheckFn>>;
|
|
12
|
+
export declare function spellCheck(filename: string, text: string, root: Node, options: WorkerOptions): Promise<Issue[]>;
|
|
13
|
+
export {};
|
|
@@ -1,37 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.spellCheck = void 0;
|
|
30
|
-
const assert_1 = __importDefault(require("assert"));
|
|
31
|
-
const cspell_lib_1 = require("cspell-lib");
|
|
32
|
-
const path = __importStar(require("path"));
|
|
33
|
-
const util_1 = require("util");
|
|
34
|
-
const walkTree_1 = require("./walkTree");
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { createTextDocument, DocumentValidator, refreshDictionaryCache } from 'cspell-lib';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { format } from 'util';
|
|
5
|
+
import { walkTree } from './walkTree.mjs';
|
|
35
6
|
const defaultSettings = {
|
|
36
7
|
patterns: [
|
|
37
8
|
// @todo: be able to use cooked / transformed strings.
|
|
@@ -48,7 +19,7 @@ function log(...args) {
|
|
|
48
19
|
return;
|
|
49
20
|
console.log(...args);
|
|
50
21
|
}
|
|
51
|
-
async function spellCheck(filename, text, root, options) {
|
|
22
|
+
export async function spellCheck(filename, text, root, options) {
|
|
52
23
|
const toIgnore = new Set();
|
|
53
24
|
const importedIdentifiers = new Set();
|
|
54
25
|
isDebugMode = options.debugMode || false;
|
|
@@ -153,18 +124,17 @@ async function spellCheck(filename, text, root, options) {
|
|
|
153
124
|
(parent.type === 'ExportSpecifier' && parent.local === node));
|
|
154
125
|
}
|
|
155
126
|
function isLocalImportIdentifierUnique(node) {
|
|
156
|
-
var _a, _b, _c, _d;
|
|
157
127
|
const parent = getImportParent(node);
|
|
158
128
|
if (!parent)
|
|
159
129
|
return true;
|
|
160
130
|
const { imported, local } = parent;
|
|
161
131
|
if (imported.name !== local.name)
|
|
162
132
|
return true;
|
|
163
|
-
return
|
|
133
|
+
return imported.range?.[0] !== local.range?.[0] && imported.range?.[1] !== local.range?.[1];
|
|
164
134
|
}
|
|
165
135
|
function getImportParent(node) {
|
|
166
136
|
const parent = node.parent;
|
|
167
|
-
return
|
|
137
|
+
return parent?.type === 'ImportSpecifier' ? parent : undefined;
|
|
168
138
|
}
|
|
169
139
|
function skipCheckForRawImportIdentifiers(node) {
|
|
170
140
|
if (options.ignoreImports)
|
|
@@ -177,8 +147,7 @@ async function spellCheck(filename, text, root, options) {
|
|
|
177
147
|
return !!obj && obj.type === 'Identifier' && importedIdentifiers.has(obj.name);
|
|
178
148
|
}
|
|
179
149
|
function isObjectProperty(node) {
|
|
180
|
-
|
|
181
|
-
return ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression';
|
|
150
|
+
return node.parent?.type === 'MemberExpression';
|
|
182
151
|
}
|
|
183
152
|
function reportIssue(issue) {
|
|
184
153
|
const word = issue.text;
|
|
@@ -197,8 +166,7 @@ async function spellCheck(filename, text, root, options) {
|
|
|
197
166
|
JSXText: checkJSXText,
|
|
198
167
|
};
|
|
199
168
|
function checkNode(node) {
|
|
200
|
-
|
|
201
|
-
(_a = processors[node.type]) === null || _a === void 0 ? void 0 : _a.call(processors, node);
|
|
169
|
+
processors[node.type]?.(node);
|
|
202
170
|
}
|
|
203
171
|
function mapNode(node, index, nodes) {
|
|
204
172
|
const child = nodes[index + 1];
|
|
@@ -271,7 +239,7 @@ async function spellCheck(filename, text, root, options) {
|
|
|
271
239
|
*/
|
|
272
240
|
function findOriginObject(node) {
|
|
273
241
|
const parent = node.parent;
|
|
274
|
-
if (
|
|
242
|
+
if (parent?.type !== 'MemberExpression' || parent.property !== node)
|
|
275
243
|
return undefined;
|
|
276
244
|
let obj = parent.object;
|
|
277
245
|
while (obj.type === 'MemberExpression') {
|
|
@@ -280,31 +248,28 @@ async function spellCheck(filename, text, root, options) {
|
|
|
280
248
|
return obj;
|
|
281
249
|
}
|
|
282
250
|
function isFunctionCall(node, name) {
|
|
283
|
-
return
|
|
251
|
+
return node?.type === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === name;
|
|
284
252
|
}
|
|
285
253
|
function isRequireCall(node) {
|
|
286
254
|
return isFunctionCall(node, 'require');
|
|
287
255
|
}
|
|
288
256
|
function isImportOrRequired(node) {
|
|
289
|
-
|
|
290
|
-
return isRequireCall(node.parent) || (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'ImportDeclaration' && node.parent.source === node);
|
|
257
|
+
return isRequireCall(node.parent) || (node.parent?.type === 'ImportDeclaration' && node.parent.source === node);
|
|
291
258
|
}
|
|
292
259
|
function debugNode(node, value) {
|
|
293
260
|
if (!isDebugMode)
|
|
294
261
|
return;
|
|
295
|
-
const val =
|
|
262
|
+
const val = format('%o', value);
|
|
296
263
|
log(`${inheritanceSummary(node)}: ${val}`);
|
|
297
264
|
}
|
|
298
|
-
|
|
265
|
+
walkTree(root, checkNode);
|
|
299
266
|
return issues;
|
|
300
267
|
}
|
|
301
|
-
exports.spellCheck = spellCheck;
|
|
302
268
|
function tagLiteral(node) {
|
|
303
|
-
|
|
304
|
-
(0, assert_1.default)(node.type === 'Literal');
|
|
269
|
+
assert(node.type === 'Literal');
|
|
305
270
|
const kind = typeof node.value;
|
|
306
271
|
const extra = kind === 'string'
|
|
307
|
-
?
|
|
272
|
+
? node.raw?.[0] === '"'
|
|
308
273
|
? 'string.double'
|
|
309
274
|
: 'string.single'
|
|
310
275
|
: node.value === null
|
|
@@ -318,13 +283,13 @@ function getDocValidator(filename, text, options) {
|
|
|
318
283
|
const doc = getTextDocument(filename, text);
|
|
319
284
|
const cachedValidator = docValCache.get(doc);
|
|
320
285
|
if (cachedValidator) {
|
|
321
|
-
|
|
286
|
+
refreshDictionaryCache(0);
|
|
322
287
|
cachedValidator.updateDocumentText(text);
|
|
323
288
|
return cachedValidator;
|
|
324
289
|
}
|
|
325
290
|
const settings = calcInitialSettings(options);
|
|
326
291
|
isDebugMode = options.debugMode || false;
|
|
327
|
-
const validator = new
|
|
292
|
+
const validator = new DocumentValidator(doc, options, settings);
|
|
328
293
|
docValCache.set(doc, validator);
|
|
329
294
|
return validator;
|
|
330
295
|
}
|
|
@@ -342,11 +307,10 @@ function calcInitialSettings(options) {
|
|
|
342
307
|
return settings;
|
|
343
308
|
}
|
|
344
309
|
function getTextDocument(filename, content) {
|
|
345
|
-
|
|
346
|
-
if (((_a = cache.lastDoc) === null || _a === void 0 ? void 0 : _a.filename) === filename) {
|
|
310
|
+
if (cache.lastDoc?.filename === filename) {
|
|
347
311
|
return cache.lastDoc.doc;
|
|
348
312
|
}
|
|
349
|
-
const doc =
|
|
313
|
+
const doc = createTextDocument({ uri: filename, content });
|
|
350
314
|
cache.lastDoc = { filename, doc };
|
|
351
315
|
return doc;
|
|
352
316
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.walkTree = void 0;
|
|
4
|
-
const estree_walker_1 = require("estree-walker");
|
|
5
|
-
function walkTree(node, enter) {
|
|
1
|
+
import { walk } from 'estree-walker';
|
|
2
|
+
export function walkTree(node, enter) {
|
|
6
3
|
const visited = new Set();
|
|
7
|
-
|
|
4
|
+
walk(node, {
|
|
8
5
|
enter: function (node, parent, key) {
|
|
9
6
|
if (visited.has(node) || key === 'tokens') {
|
|
10
7
|
this.skip();
|
|
@@ -15,4 +12,3 @@ function walkTree(node, enter) {
|
|
|
15
12
|
},
|
|
16
13
|
});
|
|
17
14
|
}
|
|
18
|
-
exports.walkTree = walkTree;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable import/no-unresolved */
|
|
2
|
+
/* eslint-disable node/no-missing-import */
|
|
3
|
+
// @ts-check
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('estree').Node} Node
|
|
6
|
+
* @typedef {import('./spellCheck.mjs').Issue} Issue
|
|
7
|
+
* @typedef {import('../common/options.js').WorkerOptions} WorkerOptions
|
|
8
|
+
*/
|
|
9
|
+
import { runAsWorker } from 'synckit';
|
|
10
|
+
/**
|
|
11
|
+
* @type {typeof import('./spellCheck.mjs')}
|
|
12
|
+
*/
|
|
13
|
+
let spellChecker;
|
|
14
|
+
runAsWorker(
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} filename
|
|
17
|
+
* @param {string} text
|
|
18
|
+
* @param {Node} root
|
|
19
|
+
* @param {WorkerOptions} options
|
|
20
|
+
* @returns {Promise<Issue[]>} The issues found.
|
|
21
|
+
*/
|
|
22
|
+
async (filename, text, root, options) => {
|
|
23
|
+
if (!spellChecker) {
|
|
24
|
+
spellChecker = await import('./spellCheck.mjs');
|
|
25
|
+
}
|
|
26
|
+
return spellChecker.spellCheck(filename, text, root, options);
|
|
27
|
+
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "6.
|
|
6
|
+
"version": "6.23.0",
|
|
7
7
|
"description": "CSpell ESLint plugin",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"cspell",
|
|
@@ -17,25 +17,25 @@
|
|
|
17
17
|
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-eslint-plugin#readme",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"exports": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"default": "./dist/index.js"
|
|
20
|
+
"types": "./dist/plugin/index.d.ts",
|
|
21
|
+
"require": "./dist/plugin/index.js",
|
|
22
|
+
"default": "./dist/plugin/index.js"
|
|
24
23
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"types": "dist/index.d.ts",
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"main": "dist/plugin/index.js",
|
|
26
|
+
"types": "dist/plugin/index.d.ts",
|
|
28
27
|
"files": [
|
|
29
28
|
"dist",
|
|
30
29
|
"!**/__mocks__",
|
|
30
|
+
"!**/*.tsbuildInfo",
|
|
31
31
|
"!**/*.test.*",
|
|
32
32
|
"!**/*.spec.*",
|
|
33
33
|
"!**/*.map"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm build:schema && pnpm build:src",
|
|
37
|
-
"build:src": "tsc -
|
|
38
|
-
"build:schema": "ts-json-schema-generator --no-top-ref --expose none --path src/options.ts --type Options -o ./src/_auto_generated_/options.schema.json",
|
|
37
|
+
"build:src": "tsc -b ./tsconfig.json",
|
|
38
|
+
"build:schema": "ts-json-schema-generator --no-top-ref --expose none --path src/common/options.ts --type Options -o ./src/_auto_generated_/options.schema.json",
|
|
39
39
|
"watch": "tsc -p . --watch",
|
|
40
40
|
"clean": "shx rm -rf dist coverage .tsbuildinfo",
|
|
41
41
|
"clean-build": "pnpm run clean && pnpm run build",
|
|
@@ -56,19 +56,19 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/eslint": "^8.21.0",
|
|
58
58
|
"@types/estree": "^1.0.0",
|
|
59
|
-
"@types/node": "^18.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"@typescript-eslint/types": "^5.
|
|
62
|
-
"@typescript-eslint/typescript-estree": "^5.
|
|
59
|
+
"@types/node": "^18.13.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
61
|
+
"@typescript-eslint/types": "^5.51.0",
|
|
62
|
+
"@typescript-eslint/typescript-estree": "^5.51.0",
|
|
63
63
|
"eslint": "^8.33.0",
|
|
64
64
|
"eslint-plugin-react": "^7.32.2",
|
|
65
65
|
"mocha": "^10.2.0",
|
|
66
66
|
"ts-json-schema-generator": "^1.2.0"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"cspell-lib": "6.
|
|
70
|
-
"estree-walker": "^
|
|
69
|
+
"cspell-lib": "6.23.0",
|
|
70
|
+
"estree-walker": "^3.0.3",
|
|
71
71
|
"synckit": "^0.8.5"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "a7cfbfa6cf42c9d9746dd8229d9f1317472e5af8"
|
|
74
74
|
}
|
package/dist/customWordList.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.addWordToCustomWordList = void 0;
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const sortFn = new Intl.Collator().compare;
|
|
30
|
-
function addWordToCustomWordList(customWordListPath, word) {
|
|
31
|
-
const content = readFile(customWordListPath) || '\n';
|
|
32
|
-
const lineEndingMatch = content.match(/\r?\n/);
|
|
33
|
-
const lineEnding = (lineEndingMatch === null || lineEndingMatch === void 0 ? void 0 : lineEndingMatch[0]) || '\n';
|
|
34
|
-
const words = new Set(content
|
|
35
|
-
.split(/\n/g)
|
|
36
|
-
.map((a) => a.trim())
|
|
37
|
-
.filter((a) => !!a));
|
|
38
|
-
words.add(word);
|
|
39
|
-
const lines = [...words];
|
|
40
|
-
lines.sort(sortFn);
|
|
41
|
-
writeFile(customWordListPath, lines.join(lineEnding) + lineEnding);
|
|
42
|
-
}
|
|
43
|
-
exports.addWordToCustomWordList = addWordToCustomWordList;
|
|
44
|
-
function readFile(file) {
|
|
45
|
-
try {
|
|
46
|
-
return fs.readFileSync(file, 'utf-8');
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function writeFile(file, content) {
|
|
53
|
-
makeDir(path.dirname(file));
|
|
54
|
-
fs.writeFileSync(file, content);
|
|
55
|
-
}
|
|
56
|
-
function makeDir(dir) {
|
|
57
|
-
try {
|
|
58
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
console.log(e);
|
|
62
|
-
}
|
|
63
|
-
}
|
package/dist/worker.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable import/no-unresolved */
|
|
3
|
-
/* eslint-disable node/no-missing-import */
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v;
|
|
19
|
-
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
-
if (mod && mod.__esModule) return mod;
|
|
22
|
-
var result = {};
|
|
23
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
-
__setModuleDefault(result, mod);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
// @ts-check
|
|
28
|
-
/**
|
|
29
|
-
* @typedef {import('estree').Node} Node
|
|
30
|
-
* @typedef {import('./spellCheck').Issue} Issue
|
|
31
|
-
* @typedef {import('./options').WorkerOptions} WorkerOptions
|
|
32
|
-
*/
|
|
33
|
-
const { runAsWorker } = require('synckit');
|
|
34
|
-
/**
|
|
35
|
-
* @type {typeof import('./spellCheck')}
|
|
36
|
-
*/
|
|
37
|
-
let spellChecker;
|
|
38
|
-
runAsWorker(
|
|
39
|
-
/**
|
|
40
|
-
* @param {string} filename
|
|
41
|
-
* @param {string} text
|
|
42
|
-
* @param {Node} root
|
|
43
|
-
* @param {WorkerOptions} options
|
|
44
|
-
* @returns {Promise<Issue[]>} The issues found.
|
|
45
|
-
*/
|
|
46
|
-
async (filename, text, root, options) => {
|
|
47
|
-
if (!spellChecker) {
|
|
48
|
-
spellChecker = await Promise.resolve().then(() => __importStar(require('./spellCheck')));
|
|
49
|
-
}
|
|
50
|
-
return spellChecker.spellCheck(filename, text, root, options);
|
|
51
|
-
});
|