@cspell/eslint-plugin 5.18.5
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +159 -0
- package/dist/index.mjs +151 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Jason Dent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @cspell/eslint-plugin v5.18.5
|
|
3
|
+
* Copyright 2022 Jason Dent <jason@streetsidesoftware.nl>
|
|
4
|
+
* Released under the MIT License
|
|
5
|
+
* https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-eslint-plugin#readme
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var assert = require('assert');
|
|
13
|
+
var util = require('util');
|
|
14
|
+
var cspellLib = require('cspell-lib');
|
|
15
|
+
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
+
|
|
18
|
+
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
|
|
19
|
+
|
|
20
|
+
const meta = {
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'CSpell',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const defaultSettings = {
|
|
26
|
+
patterns: [
|
|
27
|
+
// @todo: be able to use cooked / transformed strings.
|
|
28
|
+
// {
|
|
29
|
+
// // Do not block unicode escape sequences.
|
|
30
|
+
// name: 'js-unicode-escape',
|
|
31
|
+
// pattern: /$^/g,
|
|
32
|
+
// },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
const log = () => undefined;
|
|
36
|
+
function create(context) {
|
|
37
|
+
const doc = cspellLib.createTextDocument({ uri: context.getFilename(), content: context.getSourceCode().getText() });
|
|
38
|
+
const validator = new cspellLib.DocumentValidator(doc, {}, defaultSettings);
|
|
39
|
+
validator.prepareSync();
|
|
40
|
+
log(`
|
|
41
|
+
|
|
42
|
+
id: ${context.id}
|
|
43
|
+
cwd: ${context.getCwd()}
|
|
44
|
+
filename: ${context.getFilename()}
|
|
45
|
+
physicalFilename: ${context.getPhysicalFilename()}
|
|
46
|
+
scope: ${context.getScope().type}
|
|
47
|
+
`);
|
|
48
|
+
function checkLiteral(node) {
|
|
49
|
+
if (typeof node.value === 'string') {
|
|
50
|
+
checkNodeText(node, node.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function checkTemplateElement(node) {
|
|
54
|
+
// console.log('Template: %o', node.value);
|
|
55
|
+
checkNodeText(node, node.value.cooked || node.value.raw);
|
|
56
|
+
}
|
|
57
|
+
function checkIdentifier(node) {
|
|
58
|
+
checkNodeText(node, node.name);
|
|
59
|
+
}
|
|
60
|
+
function checkComment(node) {
|
|
61
|
+
checkNodeText(node, node.value);
|
|
62
|
+
util.format('%o', node);
|
|
63
|
+
}
|
|
64
|
+
function checkNodeText(node, text) {
|
|
65
|
+
if (!node.range)
|
|
66
|
+
return;
|
|
67
|
+
const adj = node.type === 'Literal' ? 1 : 0;
|
|
68
|
+
const range = [node.range[0] + adj, node.range[1] - adj];
|
|
69
|
+
const scope = inheritance(node);
|
|
70
|
+
const result = validator.checkText(range, text, scope);
|
|
71
|
+
result.forEach((issue) => reportIssue(issue));
|
|
72
|
+
}
|
|
73
|
+
function reportIssue(issue) {
|
|
74
|
+
// const messageId = issue.isFlagged ? 'cspell-forbidden-word' : 'cspell-unknown-word';
|
|
75
|
+
const messageType = issue.isFlagged ? 'Forbidden' : 'Unknown';
|
|
76
|
+
const message = `${messageType} word: "${issue.text}"`;
|
|
77
|
+
const code = context.getSourceCode();
|
|
78
|
+
const start = code.getLocFromIndex(issue.offset);
|
|
79
|
+
const end = code.getLocFromIndex(issue.offset + (issue.length || issue.text.length));
|
|
80
|
+
const loc = { start, end };
|
|
81
|
+
const des = {
|
|
82
|
+
message,
|
|
83
|
+
loc,
|
|
84
|
+
};
|
|
85
|
+
context.report(des);
|
|
86
|
+
}
|
|
87
|
+
context
|
|
88
|
+
.getSourceCode()
|
|
89
|
+
.getAllComments()
|
|
90
|
+
.forEach(function (commentNode) {
|
|
91
|
+
checkComment(commentNode);
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
Literal: checkLiteral,
|
|
95
|
+
TemplateElement: checkTemplateElement,
|
|
96
|
+
Identifier: checkIdentifier,
|
|
97
|
+
};
|
|
98
|
+
function mapNode(node, index, nodes) {
|
|
99
|
+
const child = nodes[index + 1];
|
|
100
|
+
if (node.type === 'ImportSpecifier') {
|
|
101
|
+
const extra = node.imported === child ? '.imported' : node.local === child ? '.local' : '';
|
|
102
|
+
return node.type + extra;
|
|
103
|
+
}
|
|
104
|
+
if (node.type === 'ImportDeclaration') {
|
|
105
|
+
const extra = node.source === child ? '.source' : '';
|
|
106
|
+
return node.type + extra;
|
|
107
|
+
}
|
|
108
|
+
if (node.type === 'Property') {
|
|
109
|
+
const extra = node.key === child ? 'key' : node.value === child ? 'value' : '';
|
|
110
|
+
return [node.type, node.kind, extra].join('.');
|
|
111
|
+
}
|
|
112
|
+
if (node.type === 'MemberExpression') {
|
|
113
|
+
const extra = node.property === child ? 'property' : node.object === child ? 'object' : '';
|
|
114
|
+
return node.type + '.' + extra;
|
|
115
|
+
}
|
|
116
|
+
if (node.type === 'ArrowFunctionExpression') {
|
|
117
|
+
const extra = node.body === child ? 'body' : 'param';
|
|
118
|
+
return node.type + '.' + extra;
|
|
119
|
+
}
|
|
120
|
+
if (node.type === 'FunctionDeclaration') {
|
|
121
|
+
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'params';
|
|
122
|
+
return node.type + '.' + extra;
|
|
123
|
+
}
|
|
124
|
+
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
|
|
125
|
+
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'superClass';
|
|
126
|
+
return node.type + '.' + extra;
|
|
127
|
+
}
|
|
128
|
+
if (node.type === 'Literal') {
|
|
129
|
+
return tagLiteral(node);
|
|
130
|
+
}
|
|
131
|
+
return node.type;
|
|
132
|
+
}
|
|
133
|
+
function inheritance(node) {
|
|
134
|
+
const a = [...context.getAncestors(), node];
|
|
135
|
+
return a.map(mapNode);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function tagLiteral(node) {
|
|
139
|
+
var _a;
|
|
140
|
+
assert__default["default"](node.type === 'Literal');
|
|
141
|
+
const kind = typeof node.value;
|
|
142
|
+
const extra = kind === 'string'
|
|
143
|
+
? ((_a = node.raw) === null || _a === void 0 ? void 0 : _a[0]) === '"'
|
|
144
|
+
? 'string.double'
|
|
145
|
+
: 'string.single'
|
|
146
|
+
: node.value === null
|
|
147
|
+
? 'null'
|
|
148
|
+
: kind;
|
|
149
|
+
return node.type + '.' + extra;
|
|
150
|
+
}
|
|
151
|
+
const rules = {
|
|
152
|
+
cspell: {
|
|
153
|
+
meta,
|
|
154
|
+
create,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
exports.rules = rules;
|
|
159
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @cspell/eslint-plugin v5.18.5
|
|
3
|
+
* Copyright 2022 Jason Dent <jason@streetsidesoftware.nl>
|
|
4
|
+
* Released under the MIT License
|
|
5
|
+
* https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-eslint-plugin#readme
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import assert from 'assert';
|
|
9
|
+
import { format } from 'util';
|
|
10
|
+
import { createTextDocument, DocumentValidator } from 'cspell-lib';
|
|
11
|
+
|
|
12
|
+
const meta = {
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'CSpell',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const defaultSettings = {
|
|
18
|
+
patterns: [
|
|
19
|
+
// @todo: be able to use cooked / transformed strings.
|
|
20
|
+
// {
|
|
21
|
+
// // Do not block unicode escape sequences.
|
|
22
|
+
// name: 'js-unicode-escape',
|
|
23
|
+
// pattern: /$^/g,
|
|
24
|
+
// },
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
const log = () => undefined;
|
|
28
|
+
function create(context) {
|
|
29
|
+
const doc = createTextDocument({ uri: context.getFilename(), content: context.getSourceCode().getText() });
|
|
30
|
+
const validator = new DocumentValidator(doc, {}, defaultSettings);
|
|
31
|
+
validator.prepareSync();
|
|
32
|
+
log(`
|
|
33
|
+
|
|
34
|
+
id: ${context.id}
|
|
35
|
+
cwd: ${context.getCwd()}
|
|
36
|
+
filename: ${context.getFilename()}
|
|
37
|
+
physicalFilename: ${context.getPhysicalFilename()}
|
|
38
|
+
scope: ${context.getScope().type}
|
|
39
|
+
`);
|
|
40
|
+
function checkLiteral(node) {
|
|
41
|
+
if (typeof node.value === 'string') {
|
|
42
|
+
checkNodeText(node, node.value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function checkTemplateElement(node) {
|
|
46
|
+
// console.log('Template: %o', node.value);
|
|
47
|
+
checkNodeText(node, node.value.cooked || node.value.raw);
|
|
48
|
+
}
|
|
49
|
+
function checkIdentifier(node) {
|
|
50
|
+
checkNodeText(node, node.name);
|
|
51
|
+
}
|
|
52
|
+
function checkComment(node) {
|
|
53
|
+
checkNodeText(node, node.value);
|
|
54
|
+
format('%o', node);
|
|
55
|
+
}
|
|
56
|
+
function checkNodeText(node, text) {
|
|
57
|
+
if (!node.range)
|
|
58
|
+
return;
|
|
59
|
+
const adj = node.type === 'Literal' ? 1 : 0;
|
|
60
|
+
const range = [node.range[0] + adj, node.range[1] - adj];
|
|
61
|
+
const scope = inheritance(node);
|
|
62
|
+
const result = validator.checkText(range, text, scope);
|
|
63
|
+
result.forEach((issue) => reportIssue(issue));
|
|
64
|
+
}
|
|
65
|
+
function reportIssue(issue) {
|
|
66
|
+
// const messageId = issue.isFlagged ? 'cspell-forbidden-word' : 'cspell-unknown-word';
|
|
67
|
+
const messageType = issue.isFlagged ? 'Forbidden' : 'Unknown';
|
|
68
|
+
const message = `${messageType} word: "${issue.text}"`;
|
|
69
|
+
const code = context.getSourceCode();
|
|
70
|
+
const start = code.getLocFromIndex(issue.offset);
|
|
71
|
+
const end = code.getLocFromIndex(issue.offset + (issue.length || issue.text.length));
|
|
72
|
+
const loc = { start, end };
|
|
73
|
+
const des = {
|
|
74
|
+
message,
|
|
75
|
+
loc,
|
|
76
|
+
};
|
|
77
|
+
context.report(des);
|
|
78
|
+
}
|
|
79
|
+
context
|
|
80
|
+
.getSourceCode()
|
|
81
|
+
.getAllComments()
|
|
82
|
+
.forEach(function (commentNode) {
|
|
83
|
+
checkComment(commentNode);
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
Literal: checkLiteral,
|
|
87
|
+
TemplateElement: checkTemplateElement,
|
|
88
|
+
Identifier: checkIdentifier,
|
|
89
|
+
};
|
|
90
|
+
function mapNode(node, index, nodes) {
|
|
91
|
+
const child = nodes[index + 1];
|
|
92
|
+
if (node.type === 'ImportSpecifier') {
|
|
93
|
+
const extra = node.imported === child ? '.imported' : node.local === child ? '.local' : '';
|
|
94
|
+
return node.type + extra;
|
|
95
|
+
}
|
|
96
|
+
if (node.type === 'ImportDeclaration') {
|
|
97
|
+
const extra = node.source === child ? '.source' : '';
|
|
98
|
+
return node.type + extra;
|
|
99
|
+
}
|
|
100
|
+
if (node.type === 'Property') {
|
|
101
|
+
const extra = node.key === child ? 'key' : node.value === child ? 'value' : '';
|
|
102
|
+
return [node.type, node.kind, extra].join('.');
|
|
103
|
+
}
|
|
104
|
+
if (node.type === 'MemberExpression') {
|
|
105
|
+
const extra = node.property === child ? 'property' : node.object === child ? 'object' : '';
|
|
106
|
+
return node.type + '.' + extra;
|
|
107
|
+
}
|
|
108
|
+
if (node.type === 'ArrowFunctionExpression') {
|
|
109
|
+
const extra = node.body === child ? 'body' : 'param';
|
|
110
|
+
return node.type + '.' + extra;
|
|
111
|
+
}
|
|
112
|
+
if (node.type === 'FunctionDeclaration') {
|
|
113
|
+
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'params';
|
|
114
|
+
return node.type + '.' + extra;
|
|
115
|
+
}
|
|
116
|
+
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
|
|
117
|
+
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'superClass';
|
|
118
|
+
return node.type + '.' + extra;
|
|
119
|
+
}
|
|
120
|
+
if (node.type === 'Literal') {
|
|
121
|
+
return tagLiteral(node);
|
|
122
|
+
}
|
|
123
|
+
return node.type;
|
|
124
|
+
}
|
|
125
|
+
function inheritance(node) {
|
|
126
|
+
const a = [...context.getAncestors(), node];
|
|
127
|
+
return a.map(mapNode);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function tagLiteral(node) {
|
|
131
|
+
var _a;
|
|
132
|
+
assert(node.type === 'Literal');
|
|
133
|
+
const kind = typeof node.value;
|
|
134
|
+
const extra = kind === 'string'
|
|
135
|
+
? ((_a = node.raw) === null || _a === void 0 ? void 0 : _a[0]) === '"'
|
|
136
|
+
? 'string.double'
|
|
137
|
+
: 'string.single'
|
|
138
|
+
: node.value === null
|
|
139
|
+
? 'null'
|
|
140
|
+
: kind;
|
|
141
|
+
return node.type + '.' + extra;
|
|
142
|
+
}
|
|
143
|
+
const rules = {
|
|
144
|
+
cspell: {
|
|
145
|
+
meta,
|
|
146
|
+
create,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export { rules };
|
|
151
|
+
//# sourceMappingURL=index.mjs.map
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cspell/eslint-plugin",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "5.18.5",
|
|
7
|
+
"description": "[WIP] CSpell ESLint plugin",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"cspell",
|
|
10
|
+
"eslint",
|
|
11
|
+
"plugin",
|
|
12
|
+
"spell",
|
|
13
|
+
"spell checker",
|
|
14
|
+
"spelling"
|
|
15
|
+
],
|
|
16
|
+
"author": "Jason Dent <jason@streetsidesoftware.nl>",
|
|
17
|
+
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-eslint-plugin#readme",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"exports": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"module": "dist/index.mjs",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"!**/__mocks__",
|
|
31
|
+
"!**/*.test.*",
|
|
32
|
+
"!**/*.spec.*",
|
|
33
|
+
"!**/*.map"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "rollup --config rollup.config.ts --configPlugin typescript",
|
|
37
|
+
"watch": "npm run build -- --watch",
|
|
38
|
+
"clean": "rimraf dist coverage .tsbuildinfo",
|
|
39
|
+
"clean-build": "npm run clean && npm run build",
|
|
40
|
+
"coverage": "echo coverage",
|
|
41
|
+
"test-watch": "npm run test -- --watch",
|
|
42
|
+
"test": "npx mocha --timeout 10000 \"dist/**/*.test.js\""
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/streetsidesoftware/cspell.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/streetsidesoftware/cspell/labels/cspell-gitignore"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=12.13.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@rollup/plugin-commonjs": "^21.0.2",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
57
|
+
"@rollup/plugin-typescript": "^8.3.1",
|
|
58
|
+
"@types/eslint": "^8.4.1",
|
|
59
|
+
"@types/estree": "^0.0.51",
|
|
60
|
+
"@types/node": "^17.0.21",
|
|
61
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
62
|
+
"@typescript-eslint/types": "^5.14.0",
|
|
63
|
+
"@typescript-eslint/typescript-estree": "^5.14.0",
|
|
64
|
+
"eslint": "^8.10.0",
|
|
65
|
+
"mocha": "^9.2.1",
|
|
66
|
+
"rimraf": "^3.0.2",
|
|
67
|
+
"rollup": "^2.70.0",
|
|
68
|
+
"rollup-plugin-dts": "^4.2.0"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"cspell-lib": "^5.18.5"
|
|
72
|
+
}
|
|
73
|
+
}
|