@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
package/dist/index.js
CHANGED
|
@@ -1,621 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var assert = require('assert');
|
|
11
|
-
var cspellLib = require('cspell-lib');
|
|
12
|
-
var path = require('path');
|
|
13
|
-
var util = require('util');
|
|
14
|
-
var fs = require('fs');
|
|
15
|
-
|
|
16
|
-
function _interopNamespaceDefault(e) {
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
Object.keys(e).forEach(function (k) {
|
|
20
|
-
if (k !== 'default') {
|
|
21
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () { return e[k]; }
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
n.default = e;
|
|
30
|
-
return Object.freeze(n);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
34
|
-
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
35
|
-
|
|
36
|
-
var $schema = "http://json-schema.org/draft-07/schema#";
|
|
37
|
-
var additionalProperties = false;
|
|
38
|
-
var definitions = {
|
|
39
|
-
};
|
|
40
|
-
var properties = {
|
|
41
|
-
checkComments: {
|
|
42
|
-
"default": true,
|
|
43
|
-
description: "Spell check comments",
|
|
44
|
-
type: "boolean"
|
|
45
|
-
},
|
|
46
|
-
checkIdentifiers: {
|
|
47
|
-
"default": true,
|
|
48
|
-
description: "Spell check identifiers (variables names, function names, class names, etc.)",
|
|
49
|
-
type: "boolean"
|
|
50
|
-
},
|
|
51
|
-
checkJSXText: {
|
|
52
|
-
"default": true,
|
|
53
|
-
description: "Spell check JSX Text",
|
|
54
|
-
type: "boolean"
|
|
55
|
-
},
|
|
56
|
-
checkStringTemplates: {
|
|
57
|
-
"default": true,
|
|
58
|
-
description: "Spell check template strings",
|
|
59
|
-
type: "boolean"
|
|
60
|
-
},
|
|
61
|
-
checkStrings: {
|
|
62
|
-
"default": true,
|
|
63
|
-
description: "Spell check strings",
|
|
64
|
-
type: "boolean"
|
|
65
|
-
},
|
|
66
|
-
customWordListFile: {
|
|
67
|
-
anyOf: [
|
|
68
|
-
{
|
|
69
|
-
description: "Specify a path to a custom word list file",
|
|
70
|
-
type: "string"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
additionalProperties: false,
|
|
74
|
-
properties: {
|
|
75
|
-
addWords: {
|
|
76
|
-
description: "**Experimental**: Provide a fix option to add words to the file.\n\nNote: this does not yet work perfectly.",
|
|
77
|
-
type: "boolean"
|
|
78
|
-
},
|
|
79
|
-
path: {
|
|
80
|
-
description: "Path to word list file. File format: 1 word per line",
|
|
81
|
-
type: "string"
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
required: [
|
|
85
|
-
"path"
|
|
86
|
-
],
|
|
87
|
-
type: "object"
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
|
-
description: "Specify a path to a custom word list file.\n\nexample: ```js customWordListFile: \"./myWords.txt\" ```"
|
|
91
|
-
},
|
|
92
|
-
debugMode: {
|
|
93
|
-
"default": false,
|
|
94
|
-
description: "Output debug logs",
|
|
95
|
-
type: "boolean"
|
|
96
|
-
},
|
|
97
|
-
generateSuggestions: {
|
|
98
|
-
"default": true,
|
|
99
|
-
description: "Generate suggestions",
|
|
100
|
-
type: "boolean"
|
|
101
|
-
},
|
|
102
|
-
ignoreImportProperties: {
|
|
103
|
-
"default": true,
|
|
104
|
-
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. ```",
|
|
105
|
-
type: "boolean"
|
|
106
|
-
},
|
|
107
|
-
ignoreImports: {
|
|
108
|
-
"default": true,
|
|
109
|
-
description: "Ignore import and require names",
|
|
110
|
-
type: "boolean"
|
|
111
|
-
},
|
|
112
|
-
numSuggestions: {
|
|
113
|
-
"default": 8,
|
|
114
|
-
description: "Number of spelling suggestions to make.",
|
|
115
|
-
type: "number"
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var required = [
|
|
119
|
-
"numSuggestions",
|
|
120
|
-
"generateSuggestions"
|
|
121
|
-
];
|
|
122
|
-
var type = "object";
|
|
123
|
-
var optionsSchema = {
|
|
124
|
-
$schema: $schema,
|
|
125
|
-
additionalProperties: additionalProperties,
|
|
126
|
-
definitions: definitions,
|
|
127
|
-
properties: properties,
|
|
128
|
-
required: required,
|
|
129
|
-
type: type
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const sortFn = new Intl.Collator().compare;
|
|
133
|
-
function addWordToCustomWordList(customWordListPath, word) {
|
|
134
|
-
const content = readFile(customWordListPath) || '\n';
|
|
135
|
-
const lineEndingMatch = content.match(/\r?\n/);
|
|
136
|
-
const lineEnding = (lineEndingMatch === null || lineEndingMatch === void 0 ? void 0 : lineEndingMatch[0]) || '\n';
|
|
137
|
-
const words = new Set(content
|
|
138
|
-
.split(/\n/g)
|
|
139
|
-
.map((a) => a.trim())
|
|
140
|
-
.filter((a) => !!a));
|
|
141
|
-
words.add(word);
|
|
142
|
-
const lines = [...words];
|
|
143
|
-
lines.sort(sortFn);
|
|
144
|
-
writeFile(customWordListPath, lines.join(lineEnding) + lineEnding);
|
|
145
|
-
}
|
|
146
|
-
function readFile(file) {
|
|
147
|
-
try {
|
|
148
|
-
return fs__namespace.readFileSync(file, 'utf-8');
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
return undefined;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function writeFile(file, content) {
|
|
155
|
-
makeDir(path__namespace.dirname(file));
|
|
156
|
-
fs__namespace.writeFileSync(file, content);
|
|
157
|
-
}
|
|
158
|
-
function makeDir(dir) {
|
|
159
|
-
try {
|
|
160
|
-
fs__namespace.mkdirSync(dir, { recursive: true });
|
|
161
|
-
}
|
|
162
|
-
catch (e) {
|
|
163
|
-
console.log(e);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const defaultCheckOptions = {
|
|
168
|
-
checkComments: true,
|
|
169
|
-
checkIdentifiers: true,
|
|
170
|
-
checkJSXText: true,
|
|
171
|
-
checkStrings: true,
|
|
172
|
-
checkStringTemplates: true,
|
|
173
|
-
customWordListFile: undefined,
|
|
174
|
-
ignoreImportProperties: true,
|
|
175
|
-
ignoreImports: true,
|
|
176
|
-
};
|
|
177
|
-
const defaultOptions = {
|
|
178
|
-
...defaultCheckOptions,
|
|
179
|
-
numSuggestions: 8,
|
|
180
|
-
generateSuggestions: true,
|
|
181
|
-
debugMode: false,
|
|
182
|
-
};
|
|
183
|
-
function normalizeOptions(opts) {
|
|
184
|
-
const options = Object.assign({}, defaultOptions, opts || {});
|
|
185
|
-
return options;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const schema = optionsSchema;
|
|
189
|
-
const messages = {
|
|
190
|
-
wordUnknown: 'Unknown word: "{{word}}"',
|
|
191
|
-
wordForbidden: 'Forbidden word: "{{word}}"',
|
|
192
|
-
suggestWord: '{{word}}',
|
|
193
|
-
addWordToDictionary: 'Add "{{word}}" to {{dictionary}}',
|
|
194
|
-
};
|
|
195
|
-
const meta = {
|
|
196
|
-
docs: {
|
|
197
|
-
description: 'CSpell spellchecker',
|
|
198
|
-
category: 'Possible Errors',
|
|
199
|
-
recommended: false,
|
|
200
|
-
},
|
|
201
|
-
messages,
|
|
202
|
-
hasSuggestions: true,
|
|
203
|
-
schema: [schema],
|
|
204
|
-
};
|
|
205
|
-
const defaultSettings = {
|
|
206
|
-
patterns: [
|
|
207
|
-
// @todo: be able to use cooked / transformed strings.
|
|
208
|
-
// {
|
|
209
|
-
// // Do not block unicode escape sequences.
|
|
210
|
-
// name: 'js-unicode-escape',
|
|
211
|
-
// pattern: /$^/g,
|
|
212
|
-
// },
|
|
213
|
-
],
|
|
214
|
-
};
|
|
215
|
-
let isDebugMode = false;
|
|
216
|
-
function log(...args) {
|
|
217
|
-
if (!isDebugMode)
|
|
218
|
-
return;
|
|
219
|
-
console.log(...args);
|
|
220
|
-
}
|
|
221
|
-
function create(context) {
|
|
222
|
-
const options = normalizeOptions(context.options[0]);
|
|
223
|
-
const toIgnore = new Set();
|
|
224
|
-
const importedIdentifiers = new Set();
|
|
225
|
-
isDebugMode = options.debugMode || false;
|
|
226
|
-
isDebugMode && logContext(context);
|
|
227
|
-
const validator = getDocValidator(context);
|
|
228
|
-
validator.prepareSync();
|
|
229
|
-
function checkLiteral(node) {
|
|
230
|
-
if (!options.checkStrings)
|
|
231
|
-
return;
|
|
232
|
-
if (typeof node.value === 'string') {
|
|
233
|
-
debugNode(node, node.value);
|
|
234
|
-
if (options.ignoreImports && isImportOrRequired(node))
|
|
235
|
-
return;
|
|
236
|
-
if (options.ignoreImportProperties && isImportedProperty(node))
|
|
237
|
-
return;
|
|
238
|
-
checkNodeText(node, node.value);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function checkJSXText(node) {
|
|
242
|
-
if (!options.checkJSXText)
|
|
243
|
-
return;
|
|
244
|
-
if (typeof node.value === 'string') {
|
|
245
|
-
debugNode(node, node.value);
|
|
246
|
-
checkNodeText(node, node.value);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function checkTemplateElement(node) {
|
|
250
|
-
if (!options.checkStringTemplates)
|
|
251
|
-
return;
|
|
252
|
-
debugNode(node, node.value);
|
|
253
|
-
checkNodeText(node, node.value.cooked || node.value.raw);
|
|
254
|
-
}
|
|
255
|
-
function checkIdentifier(node) {
|
|
256
|
-
debugNode(node, node.name);
|
|
257
|
-
if (options.ignoreImports) {
|
|
258
|
-
if (isRawImportIdentifier(node)) {
|
|
259
|
-
toIgnore.add(node.name);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (isImportIdentifier(node)) {
|
|
263
|
-
importedIdentifiers.add(node.name);
|
|
264
|
-
if (isLocalImportIdentifierUnique(node)) {
|
|
265
|
-
checkNodeText(node, node.name);
|
|
266
|
-
}
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
else if (options.ignoreImportProperties && isImportedProperty(node)) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (!options.checkIdentifiers)
|
|
274
|
-
return;
|
|
275
|
-
if (toIgnore.has(node.name) && !isObjectProperty(node))
|
|
276
|
-
return;
|
|
277
|
-
if (skipCheckForRawImportIdentifiers(node))
|
|
278
|
-
return;
|
|
279
|
-
checkNodeText(node, node.name);
|
|
280
|
-
}
|
|
281
|
-
function checkComment(node) {
|
|
282
|
-
if (!options.checkComments)
|
|
283
|
-
return;
|
|
284
|
-
debugNode(node, node.value);
|
|
285
|
-
checkNodeText(node, node.value);
|
|
286
|
-
}
|
|
287
|
-
function checkNodeText(node, text) {
|
|
288
|
-
if (!node.range)
|
|
289
|
-
return;
|
|
290
|
-
const adj = node.type === 'Literal' ? 1 : 0;
|
|
291
|
-
const range = [node.range[0] + adj, node.range[1] - adj];
|
|
292
|
-
const scope = calcScope();
|
|
293
|
-
const result = validator.checkText(range, text, scope);
|
|
294
|
-
result.forEach((issue) => reportIssue(issue));
|
|
295
|
-
}
|
|
296
|
-
function calcScope(_node) {
|
|
297
|
-
// inheritance(node);
|
|
298
|
-
return [];
|
|
299
|
-
}
|
|
300
|
-
function isImportIdentifier(node) {
|
|
301
|
-
const parent = node.parent;
|
|
302
|
-
if (node.type !== 'Identifier' || !parent)
|
|
303
|
-
return false;
|
|
304
|
-
return ((parent.type === 'ImportSpecifier' ||
|
|
305
|
-
parent.type === 'ImportNamespaceSpecifier' ||
|
|
306
|
-
parent.type === 'ImportDefaultSpecifier') &&
|
|
307
|
-
parent.local === node);
|
|
308
|
-
}
|
|
309
|
-
function isRawImportIdentifier(node) {
|
|
310
|
-
const parent = node.parent;
|
|
311
|
-
if (node.type !== 'Identifier' || !parent)
|
|
312
|
-
return false;
|
|
313
|
-
return ((parent.type === 'ImportSpecifier' && parent.imported === node) ||
|
|
314
|
-
(parent.type === 'ExportSpecifier' && parent.local === node));
|
|
315
|
-
}
|
|
316
|
-
function isLocalImportIdentifierUnique(node) {
|
|
317
|
-
var _a, _b, _c, _d;
|
|
318
|
-
const parent = getImportParent(node);
|
|
319
|
-
if (!parent)
|
|
320
|
-
return true;
|
|
321
|
-
const { imported, local } = parent;
|
|
322
|
-
if (imported.name !== local.name)
|
|
323
|
-
return true;
|
|
324
|
-
return ((_a = imported.range) === null || _a === void 0 ? void 0 : _a[0]) !== ((_b = local.range) === null || _b === void 0 ? void 0 : _b[0]) && ((_c = imported.range) === null || _c === void 0 ? void 0 : _c[1]) !== ((_d = local.range) === null || _d === void 0 ? void 0 : _d[1]);
|
|
325
|
-
}
|
|
326
|
-
function getImportParent(node) {
|
|
327
|
-
const parent = node.parent;
|
|
328
|
-
return (parent === null || parent === void 0 ? void 0 : parent.type) === 'ImportSpecifier' ? parent : undefined;
|
|
329
|
-
}
|
|
330
|
-
function skipCheckForRawImportIdentifiers(node) {
|
|
331
|
-
if (options.ignoreImports)
|
|
332
|
-
return false;
|
|
333
|
-
const parent = getImportParent(node);
|
|
334
|
-
return !!parent && parent.imported === node && !isLocalImportIdentifierUnique(node);
|
|
335
|
-
}
|
|
336
|
-
function isImportedProperty(node) {
|
|
337
|
-
const obj = findOriginObject(node);
|
|
338
|
-
return !!obj && obj.type === 'Identifier' && importedIdentifiers.has(obj.name);
|
|
339
|
-
}
|
|
340
|
-
function isObjectProperty(node) {
|
|
341
|
-
var _a;
|
|
342
|
-
return ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression';
|
|
343
|
-
}
|
|
344
|
-
function reportIssue(issue) {
|
|
345
|
-
var _a;
|
|
346
|
-
const messageId = issue.isFlagged ? 'wordForbidden' : 'wordUnknown';
|
|
347
|
-
const data = {
|
|
348
|
-
word: issue.text,
|
|
349
|
-
};
|
|
350
|
-
const code = context.getSourceCode();
|
|
351
|
-
const start = issue.offset;
|
|
352
|
-
const end = issue.offset + (issue.length || issue.text.length);
|
|
353
|
-
const startPos = code.getLocFromIndex(start);
|
|
354
|
-
const endPos = code.getLocFromIndex(end);
|
|
355
|
-
const loc = { start: startPos, end: endPos };
|
|
356
|
-
function fixFactory(word) {
|
|
357
|
-
return (fixer) => fixer.replaceTextRange([start, end], word);
|
|
358
|
-
}
|
|
359
|
-
function createSug(word) {
|
|
360
|
-
const data = { word };
|
|
361
|
-
const messageId = 'suggestWord';
|
|
362
|
-
return {
|
|
363
|
-
messageId,
|
|
364
|
-
data,
|
|
365
|
-
fix: fixFactory(word),
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function createAddWordToDictionaryFix(word) {
|
|
369
|
-
if (!isCustomWordListFile(options.customWordListFile) || !options.customWordListFile.addWords) {
|
|
370
|
-
return undefined;
|
|
371
|
-
}
|
|
372
|
-
const dictFile = path__namespace.resolve(context.getCwd(), options.customWordListFile.path);
|
|
373
|
-
const data = { word, dictionary: path__namespace.basename(dictFile) };
|
|
374
|
-
const messageId = 'addWordToDictionary';
|
|
375
|
-
return {
|
|
376
|
-
messageId,
|
|
377
|
-
data,
|
|
378
|
-
fix: (_fixer) => {
|
|
379
|
-
// This wrapper is a hack to delay applying the fix until it is actually used.
|
|
380
|
-
// But it is not reliable, since ESLint + extension will randomly read the value.
|
|
381
|
-
return new WrapFix({ range: [start, end], text: word }, () => {
|
|
382
|
-
cspellLib.refreshDictionaryCache(0);
|
|
383
|
-
addWordToCustomWordList(dictFile, word);
|
|
384
|
-
validator.updateDocumentText(context.getSourceCode().getText());
|
|
385
|
-
});
|
|
386
|
-
},
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
log('Suggestions: %o', issue.suggestions);
|
|
390
|
-
const suggestions = (_a = issue.suggestions) === null || _a === void 0 ? void 0 : _a.map(createSug);
|
|
391
|
-
const addWordFix = createAddWordToDictionaryFix(issue.text);
|
|
392
|
-
const suggest = suggestions || addWordFix ? (suggestions || []).concat(addWordFix ? [addWordFix] : []) : undefined;
|
|
393
|
-
const des = {
|
|
394
|
-
messageId,
|
|
395
|
-
data,
|
|
396
|
-
loc,
|
|
397
|
-
suggest,
|
|
398
|
-
};
|
|
399
|
-
context.report(des);
|
|
400
|
-
}
|
|
401
|
-
context
|
|
402
|
-
.getSourceCode()
|
|
403
|
-
.getAllComments()
|
|
404
|
-
.forEach(function (commentNode) {
|
|
405
|
-
checkComment(commentNode);
|
|
406
|
-
});
|
|
407
|
-
return {
|
|
408
|
-
Literal: checkLiteral,
|
|
409
|
-
TemplateElement: checkTemplateElement,
|
|
410
|
-
Identifier: checkIdentifier,
|
|
411
|
-
JSXText: checkJSXText,
|
|
412
|
-
};
|
|
413
|
-
function mapNode(node, index, nodes) {
|
|
414
|
-
const child = nodes[index + 1];
|
|
415
|
-
if (node.type === 'ImportSpecifier') {
|
|
416
|
-
const extra = node.imported === child ? '.imported' : node.local === child ? '.local' : '';
|
|
417
|
-
return node.type + extra;
|
|
418
|
-
}
|
|
419
|
-
if (node.type === 'ImportDeclaration') {
|
|
420
|
-
const extra = node.source === child ? '.source' : '';
|
|
421
|
-
return node.type + extra;
|
|
422
|
-
}
|
|
423
|
-
if (node.type === 'ExportSpecifier') {
|
|
424
|
-
const extra = node.exported === child ? '.exported' : node.local === child ? '.local' : '';
|
|
425
|
-
return node.type + extra;
|
|
426
|
-
}
|
|
427
|
-
if (node.type === 'ExportNamedDeclaration') {
|
|
428
|
-
const extra = node.source === child ? '.source' : '';
|
|
429
|
-
return node.type + extra;
|
|
430
|
-
}
|
|
431
|
-
if (node.type === 'Property') {
|
|
432
|
-
const extra = node.key === child ? 'key' : node.value === child ? 'value' : '';
|
|
433
|
-
return [node.type, node.kind, extra].join('.');
|
|
434
|
-
}
|
|
435
|
-
if (node.type === 'MemberExpression') {
|
|
436
|
-
const extra = node.property === child ? 'property' : node.object === child ? 'object' : '';
|
|
437
|
-
return node.type + '.' + extra;
|
|
438
|
-
}
|
|
439
|
-
if (node.type === 'ArrowFunctionExpression') {
|
|
440
|
-
const extra = node.body === child ? 'body' : 'param';
|
|
441
|
-
return node.type + '.' + extra;
|
|
442
|
-
}
|
|
443
|
-
if (node.type === 'FunctionDeclaration') {
|
|
444
|
-
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'params';
|
|
445
|
-
return node.type + '.' + extra;
|
|
446
|
-
}
|
|
447
|
-
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
|
|
448
|
-
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'superClass';
|
|
449
|
-
return node.type + '.' + extra;
|
|
450
|
-
}
|
|
451
|
-
if (node.type === 'CallExpression') {
|
|
452
|
-
const extra = node.callee === child ? 'callee' : 'arguments';
|
|
453
|
-
return node.type + '.' + extra;
|
|
454
|
-
}
|
|
455
|
-
if (node.type === 'Literal') {
|
|
456
|
-
return tagLiteral(node);
|
|
457
|
-
}
|
|
458
|
-
if (node.type === 'Block') {
|
|
459
|
-
return node.value[0] === '*' ? 'Comment.docBlock' : 'Comment.block';
|
|
460
|
-
}
|
|
461
|
-
if (node.type === 'Line') {
|
|
462
|
-
return 'Comment.line';
|
|
463
|
-
}
|
|
464
|
-
return node.type;
|
|
465
|
-
}
|
|
466
|
-
function inheritance(node) {
|
|
467
|
-
const a = [...context.getAncestors(), node];
|
|
468
|
-
return a.map(mapNode);
|
|
469
|
-
}
|
|
470
|
-
function inheritanceSummary(node) {
|
|
471
|
-
return inheritance(node).join(' ');
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* find the origin of a member expression
|
|
475
|
-
*/
|
|
476
|
-
function findOriginObject(node) {
|
|
477
|
-
const parent = node.parent;
|
|
478
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.type) !== 'MemberExpression' || parent.property !== node)
|
|
479
|
-
return undefined;
|
|
480
|
-
let obj = parent.object;
|
|
481
|
-
while (obj.type === 'MemberExpression') {
|
|
482
|
-
obj = obj.object;
|
|
483
|
-
}
|
|
484
|
-
return obj;
|
|
485
|
-
}
|
|
486
|
-
function isFunctionCall(node, name) {
|
|
487
|
-
return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === name;
|
|
488
|
-
}
|
|
489
|
-
function isRequireCall(node) {
|
|
490
|
-
return isFunctionCall(node, 'require');
|
|
491
|
-
}
|
|
492
|
-
function isImportOrRequired(node) {
|
|
493
|
-
var _a;
|
|
494
|
-
return isRequireCall(node.parent) || (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'ImportDeclaration' && node.parent.source === node);
|
|
495
|
-
}
|
|
496
|
-
function debugNode(node, value) {
|
|
497
|
-
if (!isDebugMode)
|
|
498
|
-
return;
|
|
499
|
-
const val = util.format('%o', value);
|
|
500
|
-
log(`${inheritanceSummary(node)}: ${val}`);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
function tagLiteral(node) {
|
|
504
|
-
var _a;
|
|
505
|
-
assert(node.type === 'Literal');
|
|
506
|
-
const kind = typeof node.value;
|
|
507
|
-
const extra = kind === 'string'
|
|
508
|
-
? ((_a = node.raw) === null || _a === void 0 ? void 0 : _a[0]) === '"'
|
|
509
|
-
? 'string.double'
|
|
510
|
-
: 'string.single'
|
|
511
|
-
: node.value === null
|
|
512
|
-
? 'null'
|
|
513
|
-
: kind;
|
|
514
|
-
return node.type + '.' + extra;
|
|
515
|
-
}
|
|
516
|
-
const rules = {
|
|
517
|
-
spellchecker: {
|
|
518
|
-
meta,
|
|
519
|
-
create,
|
|
520
|
-
},
|
|
521
|
-
};
|
|
522
|
-
function logContext(context) {
|
|
523
|
-
log('\n\n************************');
|
|
524
|
-
// log(context.getSourceCode().text);
|
|
525
|
-
log(`
|
|
526
|
-
|
|
527
|
-
id: ${context.id}
|
|
528
|
-
cwd: ${context.getCwd()}
|
|
529
|
-
filename: ${context.getFilename()}
|
|
530
|
-
physicalFilename: ${context.getPhysicalFilename()}
|
|
531
|
-
scope: ${context.getScope().type}
|
|
532
|
-
`);
|
|
533
|
-
}
|
|
534
|
-
const configs = {
|
|
535
|
-
recommended: {
|
|
536
|
-
plugins: ['@cspell'],
|
|
537
|
-
rules: {
|
|
538
|
-
'@cspell/spellchecker': ['warn', {}],
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
debug: {
|
|
542
|
-
plugins: ['@cspell'],
|
|
543
|
-
rules: {
|
|
544
|
-
'@cspell/spellchecker': ['warn', { debugMode: true }],
|
|
545
|
-
},
|
|
546
|
-
},
|
|
547
|
-
};
|
|
548
|
-
const cache = { lastDoc: undefined };
|
|
549
|
-
const docValCache = new WeakMap();
|
|
550
|
-
function getDocValidator(context) {
|
|
551
|
-
const text = context.getSourceCode().getText();
|
|
552
|
-
const doc = getTextDocument(context.getFilename(), text);
|
|
553
|
-
const cachedValidator = docValCache.get(doc);
|
|
554
|
-
if (cachedValidator) {
|
|
555
|
-
cspellLib.refreshDictionaryCache(0);
|
|
556
|
-
cachedValidator.updateDocumentText(text);
|
|
557
|
-
return cachedValidator;
|
|
558
|
-
}
|
|
559
|
-
const options = normalizeOptions(context.options[0]);
|
|
560
|
-
const settings = calcInitialSettings(options, context.getCwd());
|
|
561
|
-
isDebugMode = options.debugMode || false;
|
|
562
|
-
isDebugMode && logContext(context);
|
|
563
|
-
const validator = new cspellLib.DocumentValidator(doc, options, settings);
|
|
564
|
-
docValCache.set(doc, validator);
|
|
565
|
-
return validator;
|
|
566
|
-
}
|
|
567
|
-
function calcInitialSettings(options, cwd) {
|
|
568
|
-
const { customWordListFile } = options;
|
|
569
|
-
if (!customWordListFile)
|
|
570
|
-
return defaultSettings;
|
|
571
|
-
const filePath = isCustomWordListFile(customWordListFile) ? customWordListFile.path : customWordListFile;
|
|
572
|
-
const dictFile = path__namespace.resolve(cwd, filePath);
|
|
573
|
-
const settings = {
|
|
574
|
-
...defaultSettings,
|
|
575
|
-
dictionaryDefinitions: [{ name: 'eslint-plugin-custom-words', path: dictFile }],
|
|
576
|
-
dictionaries: ['eslint-plugin-custom-words'],
|
|
577
|
-
};
|
|
578
|
-
return settings;
|
|
579
|
-
}
|
|
580
|
-
function getTextDocument(filename, content) {
|
|
581
|
-
var _a;
|
|
582
|
-
if (((_a = cache.lastDoc) === null || _a === void 0 ? void 0 : _a.filename) === filename) {
|
|
583
|
-
return cache.lastDoc.doc;
|
|
584
|
-
}
|
|
585
|
-
const doc = cspellLib.createTextDocument({ uri: filename, content });
|
|
586
|
-
cache.lastDoc = { filename, doc };
|
|
587
|
-
return doc;
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* This wrapper is used to add a
|
|
591
|
-
*/
|
|
592
|
-
class WrapFix {
|
|
593
|
-
/**
|
|
594
|
-
*
|
|
595
|
-
* @param fix - the example Fix
|
|
596
|
-
* @param onGetText - called when `fix.text` is accessed
|
|
597
|
-
* @param limit - limit the number of times onGetText is called. Set it to `-1` for infinite.
|
|
598
|
-
*/
|
|
599
|
-
constructor(fix, onGetText, limit = 1) {
|
|
600
|
-
this.fix = fix;
|
|
601
|
-
this.onGetText = onGetText;
|
|
602
|
-
this.limit = limit;
|
|
603
|
-
}
|
|
604
|
-
get range() {
|
|
605
|
-
return this.fix.range;
|
|
606
|
-
}
|
|
607
|
-
get text() {
|
|
608
|
-
if (this.limit) {
|
|
609
|
-
this.limit--;
|
|
610
|
-
this.onGetText();
|
|
611
|
-
}
|
|
612
|
-
return this.fix.text;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
function isCustomWordListFile(value) {
|
|
616
|
-
return !!value && typeof value === 'object';
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
exports.configs = configs;
|
|
620
|
-
exports.rules = rules;
|
|
621
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rules = exports.configs = void 0;
|
|
4
|
+
var cspell_eslint_plugin_1 = require("./cspell-eslint-plugin");
|
|
5
|
+
Object.defineProperty(exports, "configs", { enumerable: true, get: function () { return cspell_eslint_plugin_1.configs; } });
|
|
6
|
+
Object.defineProperty(exports, "rules", { enumerable: true, get: function () { return cspell_eslint_plugin_1.rules; } });
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = exports.defaultOptions = exports.defaultCheckOptions = void 0;
|
|
4
|
+
exports.defaultCheckOptions = {
|
|
5
|
+
checkComments: true,
|
|
6
|
+
checkIdentifiers: true,
|
|
7
|
+
checkJSXText: true,
|
|
8
|
+
checkStrings: true,
|
|
9
|
+
checkStringTemplates: true,
|
|
10
|
+
customWordListFile: undefined,
|
|
11
|
+
ignoreImportProperties: true,
|
|
12
|
+
ignoreImports: true,
|
|
13
|
+
};
|
|
14
|
+
exports.defaultOptions = {
|
|
15
|
+
...exports.defaultCheckOptions,
|
|
16
|
+
numSuggestions: 8,
|
|
17
|
+
generateSuggestions: true,
|
|
18
|
+
debugMode: false,
|
|
19
|
+
};
|
|
20
|
+
function normalizeOptions(opts, cwd) {
|
|
21
|
+
const options = Object.assign({}, exports.defaultOptions, opts || {}, { cwd });
|
|
22
|
+
return options;
|
|
23
|
+
}
|
|
24
|
+
exports.normalizeOptions = normalizeOptions;
|