@tsslint/core 0.0.13 → 1.0.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/index.d.ts +2 -1
- package/index.js +56 -39
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type * as ts from 'typescript';
|
|
|
3
3
|
export type Linter = ReturnType<typeof createLinter>;
|
|
4
4
|
export declare function createLinter(ctx: ProjectContext, config: Config, withStack: boolean): {
|
|
5
5
|
lint(fileName: string): ts.DiagnosticWithLocation[];
|
|
6
|
-
|
|
6
|
+
hasCodeFixes(fileName: string): boolean;
|
|
7
|
+
getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[]): ts.CodeFixAction[];
|
|
7
8
|
};
|
|
8
9
|
export declare function combineCodeFixes(fileName: string, fixes: ts.CodeFixAction[]): ts.TextChange[];
|
|
9
10
|
export declare function applyTextChanges(baseSnapshot: ts.IScriptSnapshot, textChanges: ts.TextChange[]): ts.IScriptSnapshot;
|
package/index.js
CHANGED
|
@@ -40,7 +40,13 @@ function createLinter(ctx, config, withStack) {
|
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
42
42
|
currentRuleId = id;
|
|
43
|
-
|
|
43
|
+
try {
|
|
44
|
+
rule(rulesContext);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.error(`An unexpected error occurred in rule "${id}" in file ${fileName}.`);
|
|
48
|
+
console.error(err);
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
for (const plugin of plugins) {
|
|
46
52
|
if (plugin.resolveDiagnostics) {
|
|
@@ -70,44 +76,7 @@ function createLinter(ctx, config, withStack) {
|
|
|
70
76
|
};
|
|
71
77
|
const stacks = trace ? ErrorStackParser.parse(new Error()) : [];
|
|
72
78
|
if (stacks.length >= 3) {
|
|
73
|
-
|
|
74
|
-
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
75
|
-
let fileName = stack.fileName.replace(/\\/g, '/');
|
|
76
|
-
if (fileName.startsWith('file://')) {
|
|
77
|
-
fileName = fileName.substring('file://'.length);
|
|
78
|
-
}
|
|
79
|
-
if (fileName.includes('http-url:')) {
|
|
80
|
-
fileName = fileName.split('http-url:')[1];
|
|
81
|
-
}
|
|
82
|
-
if (!sourceFiles.has(fileName)) {
|
|
83
|
-
const text = ctx.languageServiceHost.readFile(fileName) ?? '';
|
|
84
|
-
sourceFiles.set(fileName, ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true));
|
|
85
|
-
}
|
|
86
|
-
const stackFile = sourceFiles.get(fileName);
|
|
87
|
-
let pos = 0;
|
|
88
|
-
try {
|
|
89
|
-
pos = stackFile?.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1) ?? 0;
|
|
90
|
-
}
|
|
91
|
-
catch { }
|
|
92
|
-
if (withStack) {
|
|
93
|
-
error.relatedInformation?.push({
|
|
94
|
-
category: ts.DiagnosticCategory.Message,
|
|
95
|
-
code: 0,
|
|
96
|
-
file: stackFile,
|
|
97
|
-
start: pos,
|
|
98
|
-
length: 0,
|
|
99
|
-
messageText: '',
|
|
100
|
-
});
|
|
101
|
-
error.relatedInformation?.push({
|
|
102
|
-
category: ts.DiagnosticCategory.Message,
|
|
103
|
-
code: 0,
|
|
104
|
-
file: configSourceFile,
|
|
105
|
-
start: 0,
|
|
106
|
-
length: 0,
|
|
107
|
-
messageText: '',
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
79
|
+
pushRelatedInformation(error, stacks[2]);
|
|
111
80
|
}
|
|
112
81
|
result.push(error);
|
|
113
82
|
return {
|
|
@@ -134,6 +103,54 @@ function createLinter(ctx, config, withStack) {
|
|
|
134
103
|
},
|
|
135
104
|
};
|
|
136
105
|
}
|
|
106
|
+
function pushRelatedInformation(error, stack) {
|
|
107
|
+
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
108
|
+
let fileName = stack.fileName.replace(/\\/g, '/');
|
|
109
|
+
if (fileName.startsWith('file://')) {
|
|
110
|
+
fileName = fileName.substring('file://'.length);
|
|
111
|
+
}
|
|
112
|
+
if (fileName.includes('http-url:')) {
|
|
113
|
+
fileName = fileName.split('http-url:')[1];
|
|
114
|
+
}
|
|
115
|
+
if (!sourceFiles.has(fileName)) {
|
|
116
|
+
const text = ctx.languageServiceHost.readFile(fileName) ?? '';
|
|
117
|
+
sourceFiles.set(fileName, ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true));
|
|
118
|
+
}
|
|
119
|
+
const stackFile = sourceFiles.get(fileName);
|
|
120
|
+
let pos = 0;
|
|
121
|
+
try {
|
|
122
|
+
pos = stackFile?.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1) ?? 0;
|
|
123
|
+
}
|
|
124
|
+
catch { }
|
|
125
|
+
if (withStack) {
|
|
126
|
+
error.relatedInformation?.push({
|
|
127
|
+
category: ts.DiagnosticCategory.Message,
|
|
128
|
+
code: 0,
|
|
129
|
+
file: stackFile,
|
|
130
|
+
start: pos,
|
|
131
|
+
length: 0,
|
|
132
|
+
messageText: '',
|
|
133
|
+
});
|
|
134
|
+
error.relatedInformation?.push({
|
|
135
|
+
category: ts.DiagnosticCategory.Message,
|
|
136
|
+
code: 0,
|
|
137
|
+
file: configSourceFile,
|
|
138
|
+
start: 0,
|
|
139
|
+
length: 0,
|
|
140
|
+
messageText: '',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
hasCodeFixes(fileName) {
|
|
147
|
+
const fixesMap = getFileFixes(fileName);
|
|
148
|
+
for (const [_ruleId, fixes] of fixesMap) {
|
|
149
|
+
if (fixes.length) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
137
154
|
},
|
|
138
155
|
getCodeFixes(fileName, start, end, diagnostics) {
|
|
139
156
|
const fixesMap = getFileFixes(fileName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"error-stack-parser": "^2.1.4",
|
|
16
|
-
"source-map-support": "^0.5.
|
|
16
|
+
"source-map-support": "^0.5.21"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@tsslint/config": "
|
|
19
|
+
"@tsslint/config": "1.0.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "124aa300b4fb4d4c414f585cc0d4afddc4f343bf"
|
|
22
22
|
}
|