@cspell/eslint-plugin 6.19.2 → 6.20.1
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/dist/ASTNode.js +2 -0
- package/dist/_auto_generated_/options.schema.json +84 -0
- package/dist/cspell-eslint-plugin.js +121 -0
- package/dist/customWordList.js +63 -0
- package/dist/index.js +6 -621
- package/dist/options.js +24 -0
- package/dist/{index.mjs → spellCheck.js} +78 -321
- package/dist/walkTree.js +18 -0
- package/dist/worker.js +52 -0
- package/package.json +14 -18
- package/dist/index.d.ts +0 -113
|
@@ -1,185 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
17
24
|
};
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
"default": true,
|
|
21
|
-
description: "Spell check comments",
|
|
22
|
-
type: "boolean"
|
|
23
|
-
},
|
|
24
|
-
checkIdentifiers: {
|
|
25
|
-
"default": true,
|
|
26
|
-
description: "Spell check identifiers (variables names, function names, class names, etc.)",
|
|
27
|
-
type: "boolean"
|
|
28
|
-
},
|
|
29
|
-
checkJSXText: {
|
|
30
|
-
"default": true,
|
|
31
|
-
description: "Spell check JSX Text",
|
|
32
|
-
type: "boolean"
|
|
33
|
-
},
|
|
34
|
-
checkStringTemplates: {
|
|
35
|
-
"default": true,
|
|
36
|
-
description: "Spell check template strings",
|
|
37
|
-
type: "boolean"
|
|
38
|
-
},
|
|
39
|
-
checkStrings: {
|
|
40
|
-
"default": true,
|
|
41
|
-
description: "Spell check strings",
|
|
42
|
-
type: "boolean"
|
|
43
|
-
},
|
|
44
|
-
customWordListFile: {
|
|
45
|
-
anyOf: [
|
|
46
|
-
{
|
|
47
|
-
description: "Specify a path to a custom word list file",
|
|
48
|
-
type: "string"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
additionalProperties: false,
|
|
52
|
-
properties: {
|
|
53
|
-
addWords: {
|
|
54
|
-
description: "**Experimental**: Provide a fix option to add words to the file.\n\nNote: this does not yet work perfectly.",
|
|
55
|
-
type: "boolean"
|
|
56
|
-
},
|
|
57
|
-
path: {
|
|
58
|
-
description: "Path to word list file. File format: 1 word per line",
|
|
59
|
-
type: "string"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
required: [
|
|
63
|
-
"path"
|
|
64
|
-
],
|
|
65
|
-
type: "object"
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
description: "Specify a path to a custom word list file.\n\nexample: ```js customWordListFile: \"./myWords.txt\" ```"
|
|
69
|
-
},
|
|
70
|
-
debugMode: {
|
|
71
|
-
"default": false,
|
|
72
|
-
description: "Output debug logs",
|
|
73
|
-
type: "boolean"
|
|
74
|
-
},
|
|
75
|
-
generateSuggestions: {
|
|
76
|
-
"default": true,
|
|
77
|
-
description: "Generate suggestions",
|
|
78
|
-
type: "boolean"
|
|
79
|
-
},
|
|
80
|
-
ignoreImportProperties: {
|
|
81
|
-
"default": true,
|
|
82
|
-
description: "Ignore the properties of imported variables, structures, and types.\n\nExample: ``` import { example } from 'third-party';\n\nconst msg = example.property; // `property` is not spell checked. ```",
|
|
83
|
-
type: "boolean"
|
|
84
|
-
},
|
|
85
|
-
ignoreImports: {
|
|
86
|
-
"default": true,
|
|
87
|
-
description: "Ignore import and require names",
|
|
88
|
-
type: "boolean"
|
|
89
|
-
},
|
|
90
|
-
numSuggestions: {
|
|
91
|
-
"default": 8,
|
|
92
|
-
description: "Number of spelling suggestions to make.",
|
|
93
|
-
type: "number"
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
var required = [
|
|
97
|
-
"numSuggestions",
|
|
98
|
-
"generateSuggestions"
|
|
99
|
-
];
|
|
100
|
-
var type = "object";
|
|
101
|
-
var optionsSchema = {
|
|
102
|
-
$schema: $schema,
|
|
103
|
-
additionalProperties: additionalProperties,
|
|
104
|
-
definitions: definitions,
|
|
105
|
-
properties: properties,
|
|
106
|
-
required: required,
|
|
107
|
-
type: type
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const sortFn = new Intl.Collator().compare;
|
|
111
|
-
function addWordToCustomWordList(customWordListPath, word) {
|
|
112
|
-
const content = readFile(customWordListPath) || '\n';
|
|
113
|
-
const lineEndingMatch = content.match(/\r?\n/);
|
|
114
|
-
const lineEnding = (lineEndingMatch === null || lineEndingMatch === void 0 ? void 0 : lineEndingMatch[0]) || '\n';
|
|
115
|
-
const words = new Set(content
|
|
116
|
-
.split(/\n/g)
|
|
117
|
-
.map((a) => a.trim())
|
|
118
|
-
.filter((a) => !!a));
|
|
119
|
-
words.add(word);
|
|
120
|
-
const lines = [...words];
|
|
121
|
-
lines.sort(sortFn);
|
|
122
|
-
writeFile(customWordListPath, lines.join(lineEnding) + lineEnding);
|
|
123
|
-
}
|
|
124
|
-
function readFile(file) {
|
|
125
|
-
try {
|
|
126
|
-
return fs.readFileSync(file, 'utf-8');
|
|
127
|
-
}
|
|
128
|
-
catch (e) {
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function writeFile(file, content) {
|
|
133
|
-
makeDir(path.dirname(file));
|
|
134
|
-
fs.writeFileSync(file, content);
|
|
135
|
-
}
|
|
136
|
-
function makeDir(dir) {
|
|
137
|
-
try {
|
|
138
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
139
|
-
}
|
|
140
|
-
catch (e) {
|
|
141
|
-
console.log(e);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const defaultCheckOptions = {
|
|
146
|
-
checkComments: true,
|
|
147
|
-
checkIdentifiers: true,
|
|
148
|
-
checkJSXText: true,
|
|
149
|
-
checkStrings: true,
|
|
150
|
-
checkStringTemplates: true,
|
|
151
|
-
customWordListFile: undefined,
|
|
152
|
-
ignoreImportProperties: true,
|
|
153
|
-
ignoreImports: true,
|
|
154
|
-
};
|
|
155
|
-
const defaultOptions = {
|
|
156
|
-
...defaultCheckOptions,
|
|
157
|
-
numSuggestions: 8,
|
|
158
|
-
generateSuggestions: true,
|
|
159
|
-
debugMode: false,
|
|
160
|
-
};
|
|
161
|
-
function normalizeOptions(opts) {
|
|
162
|
-
const options = Object.assign({}, defaultOptions, opts || {});
|
|
163
|
-
return options;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const schema = optionsSchema;
|
|
167
|
-
const messages = {
|
|
168
|
-
wordUnknown: 'Unknown word: "{{word}}"',
|
|
169
|
-
wordForbidden: 'Forbidden word: "{{word}}"',
|
|
170
|
-
suggestWord: '{{word}}',
|
|
171
|
-
addWordToDictionary: 'Add "{{word}}" to {{dictionary}}',
|
|
172
|
-
};
|
|
173
|
-
const meta = {
|
|
174
|
-
docs: {
|
|
175
|
-
description: 'CSpell spellchecker',
|
|
176
|
-
category: 'Possible Errors',
|
|
177
|
-
recommended: false,
|
|
178
|
-
},
|
|
179
|
-
messages,
|
|
180
|
-
hasSuggestions: true,
|
|
181
|
-
schema: [schema],
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
182
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");
|
|
183
35
|
const defaultSettings = {
|
|
184
36
|
patterns: [
|
|
185
37
|
// @todo: be able to use cooked / transformed strings.
|
|
@@ -196,15 +48,16 @@ function log(...args) {
|
|
|
196
48
|
return;
|
|
197
49
|
console.log(...args);
|
|
198
50
|
}
|
|
199
|
-
function
|
|
200
|
-
const options = normalizeOptions(context.options[0]);
|
|
51
|
+
async function spellCheck(filename, text, root, options) {
|
|
201
52
|
const toIgnore = new Set();
|
|
202
53
|
const importedIdentifiers = new Set();
|
|
203
54
|
isDebugMode = options.debugMode || false;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
55
|
+
const validator = getDocValidator(filename, text, options);
|
|
56
|
+
await validator.prepare();
|
|
57
|
+
const issues = [];
|
|
207
58
|
function checkLiteral(node) {
|
|
59
|
+
if (node.type !== 'Literal')
|
|
60
|
+
return;
|
|
208
61
|
if (!options.checkStrings)
|
|
209
62
|
return;
|
|
210
63
|
if (typeof node.value === 'string') {
|
|
@@ -217,6 +70,8 @@ function create(context) {
|
|
|
217
70
|
}
|
|
218
71
|
}
|
|
219
72
|
function checkJSXText(node) {
|
|
73
|
+
if (node.type !== 'JSXText')
|
|
74
|
+
return;
|
|
220
75
|
if (!options.checkJSXText)
|
|
221
76
|
return;
|
|
222
77
|
if (typeof node.value === 'string') {
|
|
@@ -225,12 +80,16 @@ function create(context) {
|
|
|
225
80
|
}
|
|
226
81
|
}
|
|
227
82
|
function checkTemplateElement(node) {
|
|
83
|
+
if (node.type !== 'TemplateElement')
|
|
84
|
+
return;
|
|
228
85
|
if (!options.checkStringTemplates)
|
|
229
86
|
return;
|
|
230
87
|
debugNode(node, node.value);
|
|
231
88
|
checkNodeText(node, node.value.cooked || node.value.raw);
|
|
232
89
|
}
|
|
233
90
|
function checkIdentifier(node) {
|
|
91
|
+
if (node.type !== 'Identifier')
|
|
92
|
+
return;
|
|
234
93
|
debugNode(node, node.name);
|
|
235
94
|
if (options.ignoreImports) {
|
|
236
95
|
if (isRawImportIdentifier(node)) {
|
|
@@ -257,6 +116,8 @@ function create(context) {
|
|
|
257
116
|
checkNodeText(node, node.name);
|
|
258
117
|
}
|
|
259
118
|
function checkComment(node) {
|
|
119
|
+
if (node.type !== 'Line' && node.type !== 'Block')
|
|
120
|
+
return;
|
|
260
121
|
if (!options.checkComments)
|
|
261
122
|
return;
|
|
262
123
|
debugNode(node, node.value);
|
|
@@ -267,7 +128,7 @@ function create(context) {
|
|
|
267
128
|
return;
|
|
268
129
|
const adj = node.type === 'Literal' ? 1 : 0;
|
|
269
130
|
const range = [node.range[0] + adj, node.range[1] - adj];
|
|
270
|
-
const scope = calcScope();
|
|
131
|
+
const scope = calcScope(node);
|
|
271
132
|
const result = validator.checkText(range, text, scope);
|
|
272
133
|
result.forEach((issue) => reportIssue(issue));
|
|
273
134
|
}
|
|
@@ -320,74 +181,25 @@ function create(context) {
|
|
|
320
181
|
return ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression';
|
|
321
182
|
}
|
|
322
183
|
function reportIssue(issue) {
|
|
323
|
-
|
|
324
|
-
const messageId = issue.isFlagged ? 'wordForbidden' : 'wordUnknown';
|
|
325
|
-
const data = {
|
|
326
|
-
word: issue.text,
|
|
327
|
-
};
|
|
328
|
-
const code = context.getSourceCode();
|
|
184
|
+
const word = issue.text;
|
|
329
185
|
const start = issue.offset;
|
|
330
186
|
const end = issue.offset + (issue.length || issue.text.length);
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
function fixFactory(word) {
|
|
335
|
-
return (fixer) => fixer.replaceTextRange([start, end], word);
|
|
336
|
-
}
|
|
337
|
-
function createSug(word) {
|
|
338
|
-
const data = { word };
|
|
339
|
-
const messageId = 'suggestWord';
|
|
340
|
-
return {
|
|
341
|
-
messageId,
|
|
342
|
-
data,
|
|
343
|
-
fix: fixFactory(word),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function createAddWordToDictionaryFix(word) {
|
|
347
|
-
if (!isCustomWordListFile(options.customWordListFile) || !options.customWordListFile.addWords) {
|
|
348
|
-
return undefined;
|
|
349
|
-
}
|
|
350
|
-
const dictFile = path.resolve(context.getCwd(), options.customWordListFile.path);
|
|
351
|
-
const data = { word, dictionary: path.basename(dictFile) };
|
|
352
|
-
const messageId = 'addWordToDictionary';
|
|
353
|
-
return {
|
|
354
|
-
messageId,
|
|
355
|
-
data,
|
|
356
|
-
fix: (_fixer) => {
|
|
357
|
-
// This wrapper is a hack to delay applying the fix until it is actually used.
|
|
358
|
-
// But it is not reliable, since ESLint + extension will randomly read the value.
|
|
359
|
-
return new WrapFix({ range: [start, end], text: word }, () => {
|
|
360
|
-
refreshDictionaryCache(0);
|
|
361
|
-
addWordToCustomWordList(dictFile, word);
|
|
362
|
-
validator.updateDocumentText(context.getSourceCode().getText());
|
|
363
|
-
});
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
log('Suggestions: %o', issue.suggestions);
|
|
368
|
-
const suggestions = (_a = issue.suggestions) === null || _a === void 0 ? void 0 : _a.map(createSug);
|
|
369
|
-
const addWordFix = createAddWordToDictionaryFix(issue.text);
|
|
370
|
-
const suggest = suggestions || addWordFix ? (suggestions || []).concat(addWordFix ? [addWordFix] : []) : undefined;
|
|
371
|
-
const des = {
|
|
372
|
-
messageId,
|
|
373
|
-
data,
|
|
374
|
-
loc,
|
|
375
|
-
suggest,
|
|
376
|
-
};
|
|
377
|
-
context.report(des);
|
|
187
|
+
const suggestions = issue.suggestions;
|
|
188
|
+
const severity = issue.isFlagged ? 'Forbidden' : 'Unknown';
|
|
189
|
+
issues.push({ word, start, end, suggestions, severity });
|
|
378
190
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
.forEach(function (commentNode) {
|
|
383
|
-
checkComment(commentNode);
|
|
384
|
-
});
|
|
385
|
-
return {
|
|
191
|
+
const processors = {
|
|
192
|
+
Line: checkComment,
|
|
193
|
+
Block: checkComment,
|
|
386
194
|
Literal: checkLiteral,
|
|
387
195
|
TemplateElement: checkTemplateElement,
|
|
388
196
|
Identifier: checkIdentifier,
|
|
389
197
|
JSXText: checkJSXText,
|
|
390
198
|
};
|
|
199
|
+
function checkNode(node) {
|
|
200
|
+
var _a;
|
|
201
|
+
(_a = processors[node.type]) === null || _a === void 0 ? void 0 : _a.call(processors, node);
|
|
202
|
+
}
|
|
391
203
|
function mapNode(node, index, nodes) {
|
|
392
204
|
const child = nodes[index + 1];
|
|
393
205
|
if (node.type === 'ImportSpecifier') {
|
|
@@ -442,9 +254,15 @@ function create(context) {
|
|
|
442
254
|
return node.type;
|
|
443
255
|
}
|
|
444
256
|
function inheritance(node) {
|
|
445
|
-
const a = [...
|
|
257
|
+
const a = [...parents(node), node];
|
|
446
258
|
return a.map(mapNode);
|
|
447
259
|
}
|
|
260
|
+
function* parents(node) {
|
|
261
|
+
while (node && node.parent) {
|
|
262
|
+
yield node.parent;
|
|
263
|
+
node = node.parent;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
448
266
|
function inheritanceSummary(node) {
|
|
449
267
|
return inheritance(node).join(' ');
|
|
450
268
|
}
|
|
@@ -474,13 +292,16 @@ function create(context) {
|
|
|
474
292
|
function debugNode(node, value) {
|
|
475
293
|
if (!isDebugMode)
|
|
476
294
|
return;
|
|
477
|
-
const val = format('%o', value);
|
|
295
|
+
const val = (0, util_1.format)('%o', value);
|
|
478
296
|
log(`${inheritanceSummary(node)}: ${val}`);
|
|
479
297
|
}
|
|
298
|
+
(0, walkTree_1.walkTree)(root, checkNode);
|
|
299
|
+
return issues;
|
|
480
300
|
}
|
|
301
|
+
exports.spellCheck = spellCheck;
|
|
481
302
|
function tagLiteral(node) {
|
|
482
303
|
var _a;
|
|
483
|
-
|
|
304
|
+
(0, assert_1.default)(node.type === 'Literal');
|
|
484
305
|
const kind = typeof node.value;
|
|
485
306
|
const extra = kind === 'string'
|
|
486
307
|
? ((_a = node.raw) === null || _a === void 0 ? void 0 : _a[0]) === '"'
|
|
@@ -491,59 +312,24 @@ function tagLiteral(node) {
|
|
|
491
312
|
: kind;
|
|
492
313
|
return node.type + '.' + extra;
|
|
493
314
|
}
|
|
494
|
-
const rules = {
|
|
495
|
-
spellchecker: {
|
|
496
|
-
meta,
|
|
497
|
-
create,
|
|
498
|
-
},
|
|
499
|
-
};
|
|
500
|
-
function logContext(context) {
|
|
501
|
-
log('\n\n************************');
|
|
502
|
-
// log(context.getSourceCode().text);
|
|
503
|
-
log(`
|
|
504
|
-
|
|
505
|
-
id: ${context.id}
|
|
506
|
-
cwd: ${context.getCwd()}
|
|
507
|
-
filename: ${context.getFilename()}
|
|
508
|
-
physicalFilename: ${context.getPhysicalFilename()}
|
|
509
|
-
scope: ${context.getScope().type}
|
|
510
|
-
`);
|
|
511
|
-
}
|
|
512
|
-
const configs = {
|
|
513
|
-
recommended: {
|
|
514
|
-
plugins: ['@cspell'],
|
|
515
|
-
rules: {
|
|
516
|
-
'@cspell/spellchecker': ['warn', {}],
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
debug: {
|
|
520
|
-
plugins: ['@cspell'],
|
|
521
|
-
rules: {
|
|
522
|
-
'@cspell/spellchecker': ['warn', { debugMode: true }],
|
|
523
|
-
},
|
|
524
|
-
},
|
|
525
|
-
};
|
|
526
315
|
const cache = { lastDoc: undefined };
|
|
527
316
|
const docValCache = new WeakMap();
|
|
528
|
-
function getDocValidator(
|
|
529
|
-
const
|
|
530
|
-
const doc = getTextDocument(context.getFilename(), text);
|
|
317
|
+
function getDocValidator(filename, text, options) {
|
|
318
|
+
const doc = getTextDocument(filename, text);
|
|
531
319
|
const cachedValidator = docValCache.get(doc);
|
|
532
320
|
if (cachedValidator) {
|
|
533
|
-
refreshDictionaryCache(0);
|
|
321
|
+
(0, cspell_lib_1.refreshDictionaryCache)(0);
|
|
534
322
|
cachedValidator.updateDocumentText(text);
|
|
535
323
|
return cachedValidator;
|
|
536
324
|
}
|
|
537
|
-
const
|
|
538
|
-
const settings = calcInitialSettings(options, context.getCwd());
|
|
325
|
+
const settings = calcInitialSettings(options);
|
|
539
326
|
isDebugMode = options.debugMode || false;
|
|
540
|
-
|
|
541
|
-
const validator = new DocumentValidator(doc, options, settings);
|
|
327
|
+
const validator = new cspell_lib_1.DocumentValidator(doc, options, settings);
|
|
542
328
|
docValCache.set(doc, validator);
|
|
543
329
|
return validator;
|
|
544
330
|
}
|
|
545
|
-
function calcInitialSettings(options
|
|
546
|
-
const { customWordListFile } = options;
|
|
331
|
+
function calcInitialSettings(options) {
|
|
332
|
+
const { customWordListFile, cwd } = options;
|
|
547
333
|
if (!customWordListFile)
|
|
548
334
|
return defaultSettings;
|
|
549
335
|
const filePath = isCustomWordListFile(customWordListFile) ? customWordListFile.path : customWordListFile;
|
|
@@ -560,39 +346,10 @@ function getTextDocument(filename, content) {
|
|
|
560
346
|
if (((_a = cache.lastDoc) === null || _a === void 0 ? void 0 : _a.filename) === filename) {
|
|
561
347
|
return cache.lastDoc.doc;
|
|
562
348
|
}
|
|
563
|
-
const doc = createTextDocument({ uri: filename, content });
|
|
349
|
+
const doc = (0, cspell_lib_1.createTextDocument)({ uri: filename, content });
|
|
564
350
|
cache.lastDoc = { filename, doc };
|
|
565
351
|
return doc;
|
|
566
352
|
}
|
|
567
|
-
/**
|
|
568
|
-
* This wrapper is used to add a
|
|
569
|
-
*/
|
|
570
|
-
class WrapFix {
|
|
571
|
-
/**
|
|
572
|
-
*
|
|
573
|
-
* @param fix - the example Fix
|
|
574
|
-
* @param onGetText - called when `fix.text` is accessed
|
|
575
|
-
* @param limit - limit the number of times onGetText is called. Set it to `-1` for infinite.
|
|
576
|
-
*/
|
|
577
|
-
constructor(fix, onGetText, limit = 1) {
|
|
578
|
-
this.fix = fix;
|
|
579
|
-
this.onGetText = onGetText;
|
|
580
|
-
this.limit = limit;
|
|
581
|
-
}
|
|
582
|
-
get range() {
|
|
583
|
-
return this.fix.range;
|
|
584
|
-
}
|
|
585
|
-
get text() {
|
|
586
|
-
if (this.limit) {
|
|
587
|
-
this.limit--;
|
|
588
|
-
this.onGetText();
|
|
589
|
-
}
|
|
590
|
-
return this.fix.text;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
353
|
function isCustomWordListFile(value) {
|
|
594
354
|
return !!value && typeof value === 'object';
|
|
595
355
|
}
|
|
596
|
-
|
|
597
|
-
export { configs, rules };
|
|
598
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/walkTree.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walkTree = void 0;
|
|
4
|
+
const estree_walker_1 = require("estree-walker");
|
|
5
|
+
function walkTree(node, enter) {
|
|
6
|
+
const visited = new Set();
|
|
7
|
+
(0, estree_walker_1.walk)(node, {
|
|
8
|
+
enter: function (node, parent, key) {
|
|
9
|
+
if (visited.has(node) || key === 'tokens') {
|
|
10
|
+
this.skip();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
visited.add(node);
|
|
14
|
+
enter(node, parent, key);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.walkTree = walkTree;
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable import/no-unresolved */
|
|
3
|
+
/* eslint-disable node/no-missing-import */
|
|
4
|
+
/* eslint-disable node/no-unsupported-features/es-syntax */
|
|
5
|
+
// @ts-check
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {import('estree').Node} Node
|
|
31
|
+
* @typedef {import('./spellCheck').Issue} Issue
|
|
32
|
+
* @typedef {import('./options').WorkerOptions} WorkerOptions
|
|
33
|
+
*/
|
|
34
|
+
const { runAsWorker } = require('synckit');
|
|
35
|
+
/**
|
|
36
|
+
* @type {typeof import('./spellCheck')}
|
|
37
|
+
*/
|
|
38
|
+
let spellChecker;
|
|
39
|
+
runAsWorker(
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} filename
|
|
42
|
+
* @param {string} text
|
|
43
|
+
* @param {Node} root
|
|
44
|
+
* @param {WorkerOptions} options
|
|
45
|
+
* @returns {Promise<Issue[]>} The issues found.
|
|
46
|
+
*/
|
|
47
|
+
async (filename, text, root, options) => {
|
|
48
|
+
if (!spellChecker) {
|
|
49
|
+
spellChecker = await Promise.resolve().then(() => __importStar(require('./spellCheck')));
|
|
50
|
+
}
|
|
51
|
+
return spellChecker.spellCheck(filename, text, root, options);
|
|
52
|
+
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "6.
|
|
6
|
+
"version": "6.20.1",
|
|
7
7
|
"description": "CSpell ESLint plugin",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"cspell",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"!**/*.map"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "pnpm
|
|
37
|
-
"build
|
|
38
|
-
"build
|
|
39
|
-
"watch": "
|
|
36
|
+
"build": "pnpm build:schema && pnpm build:src",
|
|
37
|
+
"build:src": "tsc -p .",
|
|
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",
|
|
39
|
+
"watch": "tsc -p . --watch",
|
|
40
40
|
"clean": "shx rm -rf dist coverage .tsbuildinfo",
|
|
41
41
|
"clean-build": "pnpm run clean && pnpm run build",
|
|
42
42
|
"coverage": "echo coverage",
|
|
@@ -54,25 +54,21 @@
|
|
|
54
54
|
"node": ">=14"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@rollup/plugin-commonjs": "^24.0.0",
|
|
58
|
-
"@rollup/plugin-json": "^6.0.0",
|
|
59
|
-
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
60
|
-
"@rollup/plugin-typescript": "^11.0.0",
|
|
61
57
|
"@types/eslint": "^8.4.10",
|
|
62
58
|
"@types/estree": "^1.0.0",
|
|
63
59
|
"@types/node": "^18.11.18",
|
|
64
|
-
"@typescript-eslint/parser": "^5.
|
|
65
|
-
"@typescript-eslint/types": "^5.
|
|
66
|
-
"@typescript-eslint/typescript-estree": "^5.
|
|
67
|
-
"eslint": "^8.
|
|
68
|
-
"eslint-plugin-react": "^7.32.
|
|
60
|
+
"@typescript-eslint/parser": "^5.50.0",
|
|
61
|
+
"@typescript-eslint/types": "^5.50.0",
|
|
62
|
+
"@typescript-eslint/typescript-estree": "^5.50.0",
|
|
63
|
+
"eslint": "^8.33.0",
|
|
64
|
+
"eslint-plugin-react": "^7.32.2",
|
|
69
65
|
"mocha": "^10.2.0",
|
|
70
|
-
"rollup": "^3.10.0",
|
|
71
|
-
"rollup-plugin-dts": "^5.1.1",
|
|
72
66
|
"ts-json-schema-generator": "^1.2.0"
|
|
73
67
|
},
|
|
74
68
|
"dependencies": {
|
|
75
|
-
"cspell-lib": "6.
|
|
69
|
+
"cspell-lib": "6.20.1",
|
|
70
|
+
"estree-walker": "^2.0.2",
|
|
71
|
+
"synckit": "^0.8.5"
|
|
76
72
|
},
|
|
77
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "508a06d32dd59d881d07cb60fe8c0a7c0bddf8eb"
|
|
78
74
|
}
|