@cspell/eslint-plugin 6.19.2 → 6.20.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/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/ASTNode.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"additionalProperties": false,
|
|
4
|
+
"definitions": {},
|
|
5
|
+
"properties": {
|
|
6
|
+
"checkComments": {
|
|
7
|
+
"default": true,
|
|
8
|
+
"description": "Spell check comments",
|
|
9
|
+
"type": "boolean"
|
|
10
|
+
},
|
|
11
|
+
"checkIdentifiers": {
|
|
12
|
+
"default": true,
|
|
13
|
+
"description": "Spell check identifiers (variables names, function names, class names, etc.)",
|
|
14
|
+
"type": "boolean"
|
|
15
|
+
},
|
|
16
|
+
"checkJSXText": {
|
|
17
|
+
"default": true,
|
|
18
|
+
"description": "Spell check JSX Text",
|
|
19
|
+
"type": "boolean"
|
|
20
|
+
},
|
|
21
|
+
"checkStringTemplates": {
|
|
22
|
+
"default": true,
|
|
23
|
+
"description": "Spell check template strings",
|
|
24
|
+
"type": "boolean"
|
|
25
|
+
},
|
|
26
|
+
"checkStrings": {
|
|
27
|
+
"default": true,
|
|
28
|
+
"description": "Spell check strings",
|
|
29
|
+
"type": "boolean"
|
|
30
|
+
},
|
|
31
|
+
"customWordListFile": {
|
|
32
|
+
"anyOf": [
|
|
33
|
+
{
|
|
34
|
+
"description": "Specify a path to a custom word list file",
|
|
35
|
+
"type": "string"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"additionalProperties": false,
|
|
39
|
+
"properties": {
|
|
40
|
+
"path": {
|
|
41
|
+
"description": "Path to word list file. File format: 1 word per line",
|
|
42
|
+
"type": "string"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"required": [
|
|
46
|
+
"path"
|
|
47
|
+
],
|
|
48
|
+
"type": "object"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"description": "Specify a path to a custom word list file.\n\nexample: ```js customWordListFile: \"./myWords.txt\" ```"
|
|
52
|
+
},
|
|
53
|
+
"debugMode": {
|
|
54
|
+
"default": false,
|
|
55
|
+
"description": "Output debug logs",
|
|
56
|
+
"type": "boolean"
|
|
57
|
+
},
|
|
58
|
+
"generateSuggestions": {
|
|
59
|
+
"default": true,
|
|
60
|
+
"description": "Generate suggestions",
|
|
61
|
+
"type": "boolean"
|
|
62
|
+
},
|
|
63
|
+
"ignoreImportProperties": {
|
|
64
|
+
"default": true,
|
|
65
|
+
"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. ```",
|
|
66
|
+
"type": "boolean"
|
|
67
|
+
},
|
|
68
|
+
"ignoreImports": {
|
|
69
|
+
"default": true,
|
|
70
|
+
"description": "Ignore import and require names",
|
|
71
|
+
"type": "boolean"
|
|
72
|
+
},
|
|
73
|
+
"numSuggestions": {
|
|
74
|
+
"default": 8,
|
|
75
|
+
"description": "Number of spelling suggestions to make.",
|
|
76
|
+
"type": "number"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"required": [
|
|
80
|
+
"numSuggestions",
|
|
81
|
+
"generateSuggestions"
|
|
82
|
+
],
|
|
83
|
+
"type": "object"
|
|
84
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configs = exports.rules = void 0;
|
|
7
|
+
const synckit_1 = require("synckit");
|
|
8
|
+
const options_schema_json_1 = __importDefault(require("./_auto_generated_/options.schema.json"));
|
|
9
|
+
const options_1 = require("./options");
|
|
10
|
+
const walkTree_1 = require("./walkTree");
|
|
11
|
+
const schema = options_schema_json_1.default;
|
|
12
|
+
const spellCheck = (0, synckit_1.createSyncFn)(require.resolve('./worker'), undefined, 30000);
|
|
13
|
+
const messages = {
|
|
14
|
+
wordUnknown: 'Unknown word: "{{word}}"',
|
|
15
|
+
wordForbidden: 'Forbidden word: "{{word}}"',
|
|
16
|
+
suggestWord: '{{word}}',
|
|
17
|
+
addWordToDictionary: 'Add "{{word}}" to {{dictionary}}',
|
|
18
|
+
};
|
|
19
|
+
const meta = {
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'CSpell spellchecker',
|
|
22
|
+
category: 'Possible Errors',
|
|
23
|
+
recommended: false,
|
|
24
|
+
},
|
|
25
|
+
messages,
|
|
26
|
+
hasSuggestions: true,
|
|
27
|
+
schema: [schema],
|
|
28
|
+
};
|
|
29
|
+
let isDebugMode = false;
|
|
30
|
+
function log(...args) {
|
|
31
|
+
if (!isDebugMode)
|
|
32
|
+
return;
|
|
33
|
+
console.log(...args);
|
|
34
|
+
}
|
|
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
|
+
function create(context) {
|
|
45
|
+
const options = (0, options_1.normalizeOptions)(context.options[0], context.getCwd());
|
|
46
|
+
isDebugMode = options.debugMode || false;
|
|
47
|
+
isDebugMode && logContext(context);
|
|
48
|
+
dumpTree(context);
|
|
49
|
+
function reportIssue(issue) {
|
|
50
|
+
var _a;
|
|
51
|
+
const messageId = issue.severity === 'Forbidden' ? 'wordForbidden' : 'wordUnknown';
|
|
52
|
+
const { word, start, end } = issue;
|
|
53
|
+
const data = {
|
|
54
|
+
word,
|
|
55
|
+
};
|
|
56
|
+
const code = context.getSourceCode();
|
|
57
|
+
const startPos = code.getLocFromIndex(start);
|
|
58
|
+
const endPos = code.getLocFromIndex(end);
|
|
59
|
+
const loc = { start: startPos, end: endPos };
|
|
60
|
+
function fixFactory(word) {
|
|
61
|
+
return (fixer) => fixer.replaceTextRange([start, end], word);
|
|
62
|
+
}
|
|
63
|
+
function createSug(word) {
|
|
64
|
+
const data = { word };
|
|
65
|
+
const messageId = 'suggestWord';
|
|
66
|
+
return {
|
|
67
|
+
messageId,
|
|
68
|
+
data,
|
|
69
|
+
fix: fixFactory(word),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
log('Suggestions: %o', issue.suggestions);
|
|
73
|
+
const suggestions = (_a = issue.suggestions) === null || _a === void 0 ? void 0 : _a.map(createSug);
|
|
74
|
+
const suggest = suggestions;
|
|
75
|
+
const des = {
|
|
76
|
+
messageId,
|
|
77
|
+
data,
|
|
78
|
+
loc,
|
|
79
|
+
suggest,
|
|
80
|
+
};
|
|
81
|
+
context.report(des);
|
|
82
|
+
}
|
|
83
|
+
function checkProgram() {
|
|
84
|
+
const sc = context.getSourceCode();
|
|
85
|
+
const issues = spellCheck(context.getFilename(), sc.text, sc.ast, options);
|
|
86
|
+
issues.forEach((issue) => reportIssue(issue));
|
|
87
|
+
}
|
|
88
|
+
return { Program: checkProgram };
|
|
89
|
+
}
|
|
90
|
+
exports.rules = {
|
|
91
|
+
spellchecker: {
|
|
92
|
+
meta,
|
|
93
|
+
create,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
function logContext(context) {
|
|
97
|
+
log('\n\n************************');
|
|
98
|
+
// log(context.getSourceCode().text);
|
|
99
|
+
log(`
|
|
100
|
+
|
|
101
|
+
id: ${context.id}
|
|
102
|
+
cwd: ${context.getCwd()}
|
|
103
|
+
filename: ${context.getFilename()}
|
|
104
|
+
physicalFilename: ${context.getPhysicalFilename()}
|
|
105
|
+
scope: ${context.getScope().type}
|
|
106
|
+
`);
|
|
107
|
+
}
|
|
108
|
+
exports.configs = {
|
|
109
|
+
recommended: {
|
|
110
|
+
plugins: ['@cspell'],
|
|
111
|
+
rules: {
|
|
112
|
+
'@cspell/spellchecker': ['warn', {}],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
debug: {
|
|
116
|
+
plugins: ['@cspell'],
|
|
117
|
+
rules: {
|
|
118
|
+
'@cspell/spellchecker': ['warn', { debugMode: true }],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
}
|