@tsslint/core 1.0.0 → 1.0.2
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 +1 -0
- package/index.js +76 -45
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ 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
|
+
hasCodeFixes(fileName: string): boolean;
|
|
6
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[];
|
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) {
|
|
@@ -48,16 +54,16 @@ function createLinter(ctx, config, withStack) {
|
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
return result;
|
|
51
|
-
function reportError(message, start, end,
|
|
52
|
-
return report(ts.DiagnosticCategory.Error, message, start, end,
|
|
57
|
+
function reportError(message, start, end, traceOffset = 0) {
|
|
58
|
+
return report(ts.DiagnosticCategory.Error, message, start, end, traceOffset);
|
|
53
59
|
}
|
|
54
|
-
function reportWarning(message, start, end,
|
|
55
|
-
return report(ts.DiagnosticCategory.Warning, message, start, end,
|
|
60
|
+
function reportWarning(message, start, end, traceOffset = 0) {
|
|
61
|
+
return report(ts.DiagnosticCategory.Warning, message, start, end, traceOffset);
|
|
56
62
|
}
|
|
57
|
-
function reportSuggestion(message, start, end,
|
|
58
|
-
return report(ts.DiagnosticCategory.Suggestion, message, start, end,
|
|
63
|
+
function reportSuggestion(message, start, end, traceOffset = 0) {
|
|
64
|
+
return report(ts.DiagnosticCategory.Suggestion, message, start, end, traceOffset);
|
|
59
65
|
}
|
|
60
|
-
function report(category, message, start, end,
|
|
66
|
+
function report(category, message, start, end, traceOffset) {
|
|
61
67
|
const error = {
|
|
62
68
|
category,
|
|
63
69
|
code: currentRuleId,
|
|
@@ -68,46 +74,33 @@ function createLinter(ctx, config, withStack) {
|
|
|
68
74
|
source: 'tsslint',
|
|
69
75
|
relatedInformation: [],
|
|
70
76
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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;
|
|
77
|
+
if (withStack) {
|
|
78
|
+
const stacks = traceOffset === false
|
|
79
|
+
? []
|
|
80
|
+
: ErrorStackParser.parse(new Error());
|
|
81
|
+
if (typeof traceOffset === 'number') {
|
|
82
|
+
const baseOffset = 2 + traceOffset;
|
|
83
|
+
if (config.debug) {
|
|
84
|
+
for (let i = baseOffset; i < stacks.length; i++) {
|
|
85
|
+
pushRelatedInformation(error, stacks[i]);
|
|
86
|
+
}
|
|
90
87
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
});
|
|
88
|
+
else {
|
|
89
|
+
if (stacks.length > baseOffset) {
|
|
90
|
+
pushRelatedInformation(error, stacks[baseOffset]);
|
|
91
|
+
}
|
|
109
92
|
}
|
|
110
93
|
}
|
|
94
|
+
if (withStack) {
|
|
95
|
+
error.relatedInformation?.push({
|
|
96
|
+
category: ts.DiagnosticCategory.Message,
|
|
97
|
+
code: 0,
|
|
98
|
+
file: configSourceFile,
|
|
99
|
+
start: 0,
|
|
100
|
+
length: 0,
|
|
101
|
+
messageText: 'TSSLint configuration file',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
111
104
|
}
|
|
112
105
|
result.push(error);
|
|
113
106
|
return {
|
|
@@ -134,6 +127,44 @@ function createLinter(ctx, config, withStack) {
|
|
|
134
127
|
},
|
|
135
128
|
};
|
|
136
129
|
}
|
|
130
|
+
function pushRelatedInformation(error, stack) {
|
|
131
|
+
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
132
|
+
let fileName = stack.fileName.replace(/\\/g, '/');
|
|
133
|
+
if (fileName.startsWith('file://')) {
|
|
134
|
+
fileName = fileName.substring('file://'.length);
|
|
135
|
+
}
|
|
136
|
+
if (fileName.includes('http-url:')) {
|
|
137
|
+
fileName = fileName.split('http-url:')[1];
|
|
138
|
+
}
|
|
139
|
+
if (!sourceFiles.has(fileName)) {
|
|
140
|
+
const text = ctx.languageServiceHost.readFile(fileName) ?? '';
|
|
141
|
+
sourceFiles.set(fileName, ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true));
|
|
142
|
+
}
|
|
143
|
+
const stackFile = sourceFiles.get(fileName);
|
|
144
|
+
let pos = 0;
|
|
145
|
+
try {
|
|
146
|
+
pos = stackFile?.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1) ?? 0;
|
|
147
|
+
}
|
|
148
|
+
catch { }
|
|
149
|
+
error.relatedInformation?.push({
|
|
150
|
+
category: ts.DiagnosticCategory.Message,
|
|
151
|
+
code: 0,
|
|
152
|
+
file: stackFile,
|
|
153
|
+
start: pos,
|
|
154
|
+
length: 0,
|
|
155
|
+
messageText: 'Reported at',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
hasCodeFixes(fileName) {
|
|
161
|
+
const fixesMap = getFileFixes(fileName);
|
|
162
|
+
for (const [_ruleId, fixes] of fixesMap) {
|
|
163
|
+
if (fixes.length) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
137
168
|
},
|
|
138
169
|
getCodeFixes(fileName, start, end, diagnostics) {
|
|
139
170
|
const fixesMap = getFileFixes(fileName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"source-map-support": "^0.5.21"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@tsslint/config": "1.0.
|
|
19
|
+
"@tsslint/config": "1.0.2"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "e9bbdd4eba295de6bcb663e02c305f2b48893d6f"
|
|
22
22
|
}
|