@volar/eslint 2.2.0-alpha.12
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/index.d.ts +3 -0
- package/index.js +110 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Johnson Chu
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LanguagePlugin } from '@volar/language-core';
|
|
2
|
+
import type { Linter } from 'eslint';
|
|
3
|
+
export declare function createProcessor(languagePlugins: LanguagePlugin[], caseSensitive: boolean, extensionsMap?: Record<string, string>, supportsAutofix?: boolean): Linter.Processor;
|
package/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProcessor = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
+
const windowsPath = /\\/g;
|
|
7
|
+
function createProcessor(languagePlugins, caseSensitive, extensionsMap = {
|
|
8
|
+
'javascript': '.js',
|
|
9
|
+
'typescript': '.ts',
|
|
10
|
+
'javascriptreact': '.jsx',
|
|
11
|
+
'typescriptreact': '.tsx',
|
|
12
|
+
'css': '.css',
|
|
13
|
+
'less': '.less',
|
|
14
|
+
'scss': '.scss',
|
|
15
|
+
'sass': '.sass',
|
|
16
|
+
'postcss': '.pcss',
|
|
17
|
+
'stylus': '.styl',
|
|
18
|
+
'html': '.html',
|
|
19
|
+
'pug': '.pug',
|
|
20
|
+
'json': '.json',
|
|
21
|
+
'jsonc': '.json',
|
|
22
|
+
'yaml': '.yaml',
|
|
23
|
+
'markdown': '.md',
|
|
24
|
+
}, supportsAutofix = true) {
|
|
25
|
+
const language = (0, language_core_1.createLanguage)(languagePlugins, caseSensitive, () => { });
|
|
26
|
+
const documents = new language_core_1.FileMap(caseSensitive);
|
|
27
|
+
return {
|
|
28
|
+
supportsAutofix,
|
|
29
|
+
preprocess(text, filename) {
|
|
30
|
+
filename = filename.replace(windowsPath, '/');
|
|
31
|
+
const files = [];
|
|
32
|
+
const sourceScript = language.scripts.set(filename, {
|
|
33
|
+
getLength() {
|
|
34
|
+
return text.length;
|
|
35
|
+
},
|
|
36
|
+
getText(start, end) {
|
|
37
|
+
return text.substring(start, end);
|
|
38
|
+
},
|
|
39
|
+
getChangeRange() {
|
|
40
|
+
return undefined;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
if (sourceScript?.generated) {
|
|
44
|
+
const codes = [];
|
|
45
|
+
const embeddedDocuments = [];
|
|
46
|
+
for (const code of (0, language_core_1.forEachEmbeddedCode)(sourceScript.generated.root)) {
|
|
47
|
+
if (code.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data))) {
|
|
48
|
+
const ext = extensionsMap[code.languageId];
|
|
49
|
+
if (!ext) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
files.push({
|
|
53
|
+
filename: filename + ext,
|
|
54
|
+
text: code.snapshot.getText(0, code.snapshot.getLength()),
|
|
55
|
+
});
|
|
56
|
+
codes.push(code);
|
|
57
|
+
embeddedDocuments.push(vscode_languageserver_textdocument_1.TextDocument.create(filename + ext, code.languageId, 0, code.snapshot.getText(0, code.snapshot.getLength())));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
documents.set(filename, {
|
|
61
|
+
sourceDocument: vscode_languageserver_textdocument_1.TextDocument.create(filename, sourceScript.languageId, 0, text),
|
|
62
|
+
embeddedDocuments,
|
|
63
|
+
codes,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return files;
|
|
67
|
+
},
|
|
68
|
+
postprocess(messagesArr, filename) {
|
|
69
|
+
filename = filename.replace(windowsPath, '/');
|
|
70
|
+
const docs = documents.get(filename);
|
|
71
|
+
if (docs) {
|
|
72
|
+
const { codes, sourceDocument, embeddedDocuments } = docs;
|
|
73
|
+
for (let i = 0; i < messagesArr.length; i++) {
|
|
74
|
+
const code = codes[i];
|
|
75
|
+
const map = language.maps.get(code);
|
|
76
|
+
if (!map) {
|
|
77
|
+
messagesArr[i].length = 0;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const embeddedDocument = embeddedDocuments[i];
|
|
81
|
+
messagesArr[i] = messagesArr[i].filter(message => {
|
|
82
|
+
const start = embeddedDocument.offsetAt({ line: message.line - 1, character: message.column - 1 });
|
|
83
|
+
const end = embeddedDocument.offsetAt({ line: (message.endLine ?? message.line) - 1, character: (message.endColumn ?? message.column) - 1 });
|
|
84
|
+
for (const [sourceStart, mapping] of map.getSourceOffsets(start)) {
|
|
85
|
+
if ((0, language_core_1.isDiagnosticsEnabled)(mapping.data)) {
|
|
86
|
+
for (const [sourceEnd, mapping] of map.getSourceOffsets(end)) {
|
|
87
|
+
if ((0, language_core_1.isDiagnosticsEnabled)(mapping.data)) {
|
|
88
|
+
const sourcePosition = sourceDocument.positionAt(sourceStart);
|
|
89
|
+
const sourceEndPosition = sourceDocument.positionAt(sourceEnd);
|
|
90
|
+
message.line = sourcePosition.line + 1;
|
|
91
|
+
message.column = sourcePosition.character + 1;
|
|
92
|
+
message.endLine = sourceEndPosition.line + 1;
|
|
93
|
+
message.endColumn = sourceEndPosition.character + 1;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return messagesArr.flat();
|
|
104
|
+
}
|
|
105
|
+
return [];
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
exports.createProcessor = createProcessor;
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volar/eslint",
|
|
3
|
+
"version": "2.2.0-alpha.12",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"**/*.js",
|
|
7
|
+
"**/*.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/volarjs/volar.js.git",
|
|
12
|
+
"directory": "packages/eslint"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@types/eslint": "^8.56.10",
|
|
16
|
+
"@volar/language-core": "2.2.0-alpha.12",
|
|
17
|
+
"vscode-languageserver-textdocument": "^1.0.11"
|
|
18
|
+
}
|
|
19
|
+
}
|