@tsslint/core 0.0.3
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 +174 -0
- package/package.json +21 -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
package/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
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.getBuiltInPlugins = void 0;
|
|
27
|
+
const ErrorStackParser = __importStar(require("error-stack-parser"));
|
|
28
|
+
function getBuiltInPlugins(withStack) {
|
|
29
|
+
if (withStack) {
|
|
30
|
+
require('source-map-support').install();
|
|
31
|
+
}
|
|
32
|
+
return [
|
|
33
|
+
ctx => {
|
|
34
|
+
const ts = ctx.typescript;
|
|
35
|
+
const fileFixes = new Map();
|
|
36
|
+
const sourceFiles = new Map();
|
|
37
|
+
const configSourceFile = ts.createSourceFile(ctx.configFile, ts.sys.readFile(ctx.configFile) ?? '', ts.ScriptTarget.Latest, true);
|
|
38
|
+
return {
|
|
39
|
+
lint(sourceFile, rules) {
|
|
40
|
+
const rulesContext = {
|
|
41
|
+
...ctx,
|
|
42
|
+
sourceFile,
|
|
43
|
+
reportError,
|
|
44
|
+
reportWarning,
|
|
45
|
+
reportSuggestion,
|
|
46
|
+
};
|
|
47
|
+
const token = ctx.languageServiceHost.getCancellationToken?.();
|
|
48
|
+
const result = [];
|
|
49
|
+
const fixes = getFileFixes(sourceFile.fileName);
|
|
50
|
+
fixes.clear();
|
|
51
|
+
let currentRuleId;
|
|
52
|
+
for (const [id, rule] of Object.entries(rules)) {
|
|
53
|
+
if (token?.isCancellationRequested()) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
currentRuleId = id;
|
|
57
|
+
rule(rulesContext);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
function reportError(message, start, end, trace = true) {
|
|
61
|
+
return report(ts.DiagnosticCategory.Error, message, start, end, trace);
|
|
62
|
+
}
|
|
63
|
+
function reportWarning(message, start, end, trace = true) {
|
|
64
|
+
return report(ts.DiagnosticCategory.Warning, message, start, end, trace);
|
|
65
|
+
}
|
|
66
|
+
function reportSuggestion(message, start, end, trace = true) {
|
|
67
|
+
return report(ts.DiagnosticCategory.Suggestion, message, start, end, trace);
|
|
68
|
+
}
|
|
69
|
+
function report(category, message, start, end, trace) {
|
|
70
|
+
const error = {
|
|
71
|
+
category,
|
|
72
|
+
code: currentRuleId,
|
|
73
|
+
messageText: message,
|
|
74
|
+
file: sourceFile,
|
|
75
|
+
start,
|
|
76
|
+
length: end - start,
|
|
77
|
+
source: 'tsslint',
|
|
78
|
+
relatedInformation: [],
|
|
79
|
+
};
|
|
80
|
+
const stacks = trace ? ErrorStackParser.parse(new Error()) : [];
|
|
81
|
+
if (stacks.length >= 3) {
|
|
82
|
+
const stack = stacks[2];
|
|
83
|
+
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
84
|
+
let fileName = stack.fileName.replace(/\\/g, '/');
|
|
85
|
+
if (fileName.startsWith('file://')) {
|
|
86
|
+
fileName = fileName.substring('file://'.length);
|
|
87
|
+
}
|
|
88
|
+
if (!sourceFiles.has(fileName)) {
|
|
89
|
+
const text = ctx.languageServiceHost.readFile(fileName) ?? '';
|
|
90
|
+
sourceFiles.set(fileName, ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true));
|
|
91
|
+
}
|
|
92
|
+
const stackFile = sourceFiles.get(fileName);
|
|
93
|
+
const pos = stackFile?.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1);
|
|
94
|
+
if (withStack) {
|
|
95
|
+
error.relatedInformation?.push({
|
|
96
|
+
category: ts.DiagnosticCategory.Message,
|
|
97
|
+
code: 0,
|
|
98
|
+
file: stackFile,
|
|
99
|
+
start: pos,
|
|
100
|
+
length: 0,
|
|
101
|
+
messageText: '',
|
|
102
|
+
});
|
|
103
|
+
error.relatedInformation?.push({
|
|
104
|
+
category: ts.DiagnosticCategory.Message,
|
|
105
|
+
code: 0,
|
|
106
|
+
file: configSourceFile,
|
|
107
|
+
start: 0,
|
|
108
|
+
length: 0,
|
|
109
|
+
messageText: '',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
result.push(error);
|
|
115
|
+
return {
|
|
116
|
+
withDeprecated() {
|
|
117
|
+
error.reportsDeprecated = true;
|
|
118
|
+
return this;
|
|
119
|
+
},
|
|
120
|
+
withUnnecessary() {
|
|
121
|
+
error.reportsUnnecessary = true;
|
|
122
|
+
return this;
|
|
123
|
+
},
|
|
124
|
+
withFix(title, getEdits) {
|
|
125
|
+
if (!fixes.has(currentRuleId)) {
|
|
126
|
+
fixes.set(currentRuleId, []);
|
|
127
|
+
}
|
|
128
|
+
fixes.get(currentRuleId).push(({
|
|
129
|
+
diagnostic: error,
|
|
130
|
+
title,
|
|
131
|
+
start,
|
|
132
|
+
end,
|
|
133
|
+
getEdits,
|
|
134
|
+
}));
|
|
135
|
+
return this;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
getFixes(fileName, start, end, diagnostics) {
|
|
141
|
+
const fixesMap = getFileFixes(fileName);
|
|
142
|
+
const result = [];
|
|
143
|
+
for (const [_ruleId, fixes] of fixesMap) {
|
|
144
|
+
for (let i = 0; i < fixes.length; i++) {
|
|
145
|
+
const fix = fixes[i];
|
|
146
|
+
if (diagnostics && !diagnostics.includes(fix.diagnostic)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if ((fix.start >= start && fix.start <= end) ||
|
|
150
|
+
(fix.end >= start && fix.end <= end) ||
|
|
151
|
+
(start >= fix.start && start <= fix.end) ||
|
|
152
|
+
(end >= fix.start && end <= fix.end)) {
|
|
153
|
+
result.push({
|
|
154
|
+
fixName: `tsslint: ${fix.title}`,
|
|
155
|
+
description: fix.title,
|
|
156
|
+
changes: fix.getEdits(),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
function getFileFixes(fileName) {
|
|
165
|
+
if (!fileFixes.has(fileName)) {
|
|
166
|
+
fileFixes.set(fileName, new Map());
|
|
167
|
+
}
|
|
168
|
+
return fileFixes.get(fileName);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
exports.getBuiltInPlugins = getBuiltInPlugins;
|
|
174
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsslint/core",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"**/*.js",
|
|
7
|
+
"**/*.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/johnsoncodehk/tsslint.git",
|
|
12
|
+
"directory": "packages/core"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"error-stack-parser": "^2.1.4",
|
|
16
|
+
"source-map-support": "^0.5.19"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tsslint/config": "0.0.3"
|
|
20
|
+
}
|
|
21
|
+
}
|