fork-ts-checker-webpack-plugin 0.4.14 → 0.5.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/CHANGELOG.md +23 -0
- package/README.md +3 -0
- package/lib/{types/CancellationToken.d.ts → CancellationToken.d.ts} +4 -4
- package/lib/CancellationToken.js +28 -27
- package/lib/{types/FilesRegister.d.ts → FilesRegister.d.ts} +9 -14
- package/lib/FilesRegister.js +24 -24
- package/lib/{types/FilesWatcher.d.ts → FilesWatcher.d.ts} +4 -7
- package/lib/FilesWatcher.js +27 -29
- package/lib/FsHelper.d.ts +5 -0
- package/lib/FsHelper.js +20 -0
- package/lib/IncrementalChecker.d.ts +34 -0
- package/lib/IncrementalChecker.js +97 -109
- package/lib/{types/Message.d.ts → Message.d.ts} +0 -0
- package/lib/{types/NormalizedMessage.d.ts → NormalizedMessage.d.ts} +16 -23
- package/lib/NormalizedMessage.js +76 -86
- package/lib/{types/VueProgram.d.ts → VueProgram.d.ts} +0 -0
- package/lib/VueProgram.js +62 -77
- package/lib/{types/WorkResult.d.ts → WorkResult.d.ts} +6 -6
- package/lib/WorkResult.js +22 -25
- package/lib/{types/WorkSet.d.ts → WorkSet.d.ts} +6 -6
- package/lib/WorkSet.js +6 -7
- package/lib/{types/cluster.d.ts → cluster.d.ts} +0 -0
- package/lib/cluster.js +19 -19
- package/lib/{types/formatter → formatter}/codeframeFormatter.d.ts +0 -0
- package/lib/formatter/codeframeFormatter.js +17 -16
- package/lib/{types/formatter → formatter}/defaultFormatter.d.ts +0 -0
- package/lib/formatter/defaultFormatter.js +9 -9
- package/lib/index.d.ts +98 -0
- package/lib/index.js +183 -192
- package/lib/{types/service.d.ts → service.d.ts} +0 -0
- package/lib/service.js +11 -11
- package/package.json +14 -18
- package/lib/types/IncrementalChecker.d.ts +0 -43
- package/lib/types/index.d.ts +0 -101
|
@@ -1,66 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const ts = require("typescript");
|
|
6
|
+
const FilesRegister_1 = require("./FilesRegister");
|
|
7
|
+
const FilesWatcher_1 = require("./FilesWatcher");
|
|
8
|
+
const WorkSet_1 = require("./WorkSet");
|
|
9
|
+
const NormalizedMessage_1 = require("./NormalizedMessage");
|
|
10
|
+
const minimatch = require("minimatch");
|
|
11
|
+
const VueProgram_1 = require("./VueProgram");
|
|
12
|
+
const FsHelper_1 = require("./FsHelper");
|
|
13
|
+
class IncrementalChecker {
|
|
14
|
+
constructor(programConfigFile, compilerOptions, linterConfigFile, linterAutoFix, watchPaths, workNumber = 0, workDivision = 1, checkSyntacticErrors = false, vue = false) {
|
|
26
15
|
this.programConfigFile = programConfigFile;
|
|
27
16
|
this.compilerOptions = compilerOptions;
|
|
28
17
|
this.linterConfigFile = linterConfigFile;
|
|
18
|
+
this.linterAutoFix = linterAutoFix;
|
|
29
19
|
this.watchPaths = watchPaths;
|
|
30
|
-
this.workNumber = workNumber
|
|
31
|
-
this.workDivision = workDivision
|
|
32
|
-
this.checkSyntacticErrors = checkSyntacticErrors
|
|
33
|
-
this.vue = vue
|
|
34
|
-
// Use empty array of exclusions in general to avoid having
|
|
35
|
-
// to check of its existence later on.
|
|
36
|
-
this.linterExclusions = [];
|
|
20
|
+
this.workNumber = workNumber;
|
|
21
|
+
this.workDivision = workDivision;
|
|
22
|
+
this.checkSyntacticErrors = checkSyntacticErrors;
|
|
23
|
+
this.vue = vue;
|
|
37
24
|
// it's shared between compilations
|
|
38
|
-
this.files = new FilesRegister_1.FilesRegister(
|
|
25
|
+
this.files = new FilesRegister_1.FilesRegister(() => ({
|
|
39
26
|
// data shape
|
|
40
27
|
source: undefined,
|
|
41
28
|
linted: false,
|
|
42
29
|
lints: []
|
|
43
|
-
})
|
|
30
|
+
}));
|
|
31
|
+
// Use empty array of exclusions in general to avoid having
|
|
32
|
+
// to check of its existence later on.
|
|
33
|
+
this.linterExclusions = [];
|
|
44
34
|
}
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
static loadProgramConfig(configFile, compilerOptions) {
|
|
36
|
+
const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
|
|
47
37
|
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
|
|
48
|
-
tsconfig.compilerOptions =
|
|
49
|
-
|
|
38
|
+
tsconfig.compilerOptions = Object.assign({}, tsconfig.compilerOptions, compilerOptions);
|
|
39
|
+
const parsed = ts.parseJsonConfigFileContent(tsconfig, ts.sys, path.dirname(configFile));
|
|
50
40
|
return parsed;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
}
|
|
42
|
+
static loadLinterConfig(configFile) {
|
|
43
|
+
const tslint = require('tslint');
|
|
54
44
|
return tslint.Configuration.loadConfigurationFromPath(configFile);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
host.getSourceFile =
|
|
45
|
+
}
|
|
46
|
+
static createProgram(programConfig, files, watcher, oldProgram) {
|
|
47
|
+
const host = ts.createCompilerHost(programConfig.options);
|
|
48
|
+
const realGetSourceFile = host.getSourceFile;
|
|
49
|
+
host.getSourceFile = (filePath, languageVersion, onError) => {
|
|
60
50
|
// first check if watcher is watching file - if not - check it's mtime
|
|
61
51
|
if (!watcher.isWatchingFile(filePath)) {
|
|
62
52
|
try {
|
|
63
|
-
|
|
53
|
+
const stats = fs.statSync(filePath);
|
|
64
54
|
files.setMtime(filePath, stats.mtime.valueOf());
|
|
65
55
|
}
|
|
66
56
|
catch (e) {
|
|
@@ -70,7 +60,7 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
70
60
|
}
|
|
71
61
|
// get source file only if there is no source in files register
|
|
72
62
|
if (!files.has(filePath) || !files.getData(filePath).source) {
|
|
73
|
-
files.mutateData(filePath,
|
|
63
|
+
files.mutateData(filePath, data => {
|
|
74
64
|
data.source = realGetSourceFile(filePath, languageVersion, onError);
|
|
75
65
|
});
|
|
76
66
|
}
|
|
@@ -78,28 +68,30 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
78
68
|
};
|
|
79
69
|
return ts.createProgram(programConfig.fileNames, programConfig.options, host, oldProgram // re-use old program
|
|
80
70
|
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return new tslint.Linter({ fix:
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
71
|
+
}
|
|
72
|
+
createLinter(program) {
|
|
73
|
+
const tslint = require('tslint');
|
|
74
|
+
return new tslint.Linter({ fix: this.linterAutoFix }, program);
|
|
75
|
+
}
|
|
76
|
+
hasLinter() {
|
|
77
|
+
return !!this.linter;
|
|
78
|
+
}
|
|
79
|
+
static isFileExcluded(filePath, linterExclusions) {
|
|
80
|
+
return (filePath.endsWith('.d.ts') ||
|
|
81
|
+
linterExclusions.some(matcher => matcher.match(filePath)));
|
|
82
|
+
}
|
|
83
|
+
nextIteration() {
|
|
92
84
|
if (!this.watcher) {
|
|
93
|
-
|
|
85
|
+
const watchExtensions = this.vue
|
|
94
86
|
? ['.ts', '.tsx', '.vue']
|
|
95
87
|
: ['.ts', '.tsx'];
|
|
96
88
|
this.watcher = new FilesWatcher_1.FilesWatcher(this.watchPaths, watchExtensions);
|
|
97
89
|
// connect watcher with register
|
|
98
|
-
this.watcher.on('change',
|
|
99
|
-
|
|
90
|
+
this.watcher.on('change', (filePath, stats) => {
|
|
91
|
+
this.files.setMtime(filePath, stats.mtime.valueOf());
|
|
100
92
|
});
|
|
101
|
-
this.watcher.on('unlink',
|
|
102
|
-
|
|
93
|
+
this.watcher.on('unlink', (filePath) => {
|
|
94
|
+
this.files.remove(filePath);
|
|
103
95
|
});
|
|
104
96
|
this.watcher.watch();
|
|
105
97
|
}
|
|
@@ -110,74 +102,73 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
110
102
|
// Pre-build minimatch patterns to avoid additional overhead later on.
|
|
111
103
|
// Note: Resolving the path is required to properly match against the full file paths,
|
|
112
104
|
// and also deals with potential cross-platform problems regarding path separators.
|
|
113
|
-
this.linterExclusions = this.linterConfig.linterOptions.exclude.map(
|
|
105
|
+
this.linterExclusions = this.linterConfig.linterOptions.exclude.map(pattern => new minimatch.Minimatch(path.resolve(pattern)));
|
|
114
106
|
}
|
|
115
107
|
}
|
|
116
108
|
this.program = this.vue ? this.loadVueProgram() : this.loadDefaultProgram();
|
|
117
109
|
if (this.linterConfig) {
|
|
118
|
-
this.linter =
|
|
110
|
+
this.linter = this.createLinter(this.program);
|
|
119
111
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
112
|
+
}
|
|
113
|
+
loadVueProgram() {
|
|
122
114
|
this.programConfig =
|
|
123
115
|
this.programConfig ||
|
|
124
116
|
VueProgram_1.VueProgram.loadProgramConfig(this.programConfigFile, this.compilerOptions);
|
|
125
117
|
return VueProgram_1.VueProgram.createProgram(this.programConfig, path.dirname(this.programConfigFile), this.files, this.watcher, this.program);
|
|
126
|
-
}
|
|
127
|
-
|
|
118
|
+
}
|
|
119
|
+
loadDefaultProgram() {
|
|
128
120
|
this.programConfig =
|
|
129
121
|
this.programConfig ||
|
|
130
122
|
IncrementalChecker.loadProgramConfig(this.programConfigFile, this.compilerOptions);
|
|
131
123
|
return IncrementalChecker.createProgram(this.programConfig, this.files, this.watcher, this.program);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
124
|
+
}
|
|
125
|
+
getDiagnostics(cancellationToken) {
|
|
126
|
+
const { program } = this;
|
|
127
|
+
if (!program) {
|
|
128
|
+
throw new Error('Invoked called before program initialized');
|
|
129
|
+
}
|
|
130
|
+
const diagnostics = [];
|
|
139
131
|
// select files to check (it's semantic check - we have to include all files :/)
|
|
140
|
-
|
|
132
|
+
const filesToCheck = program.getSourceFiles();
|
|
141
133
|
// calculate subset of work to do
|
|
142
|
-
|
|
134
|
+
const workSet = new WorkSet_1.WorkSet(filesToCheck, this.workNumber, this.workDivision);
|
|
143
135
|
// check given work set
|
|
144
|
-
workSet.forEach(
|
|
136
|
+
workSet.forEach(sourceFile => {
|
|
145
137
|
if (cancellationToken) {
|
|
146
138
|
cancellationToken.throwIfCancellationRequested();
|
|
147
139
|
}
|
|
148
|
-
|
|
140
|
+
const diagnosticsToRegister = this
|
|
149
141
|
.checkSyntacticErrors
|
|
150
|
-
?
|
|
151
|
-
.
|
|
152
|
-
.concat(
|
|
153
|
-
:
|
|
154
|
-
diagnostics.push
|
|
142
|
+
? program
|
|
143
|
+
.getSemanticDiagnostics(sourceFile, cancellationToken)
|
|
144
|
+
.concat(program.getSyntacticDiagnostics(sourceFile, cancellationToken))
|
|
145
|
+
: program.getSemanticDiagnostics(sourceFile, cancellationToken);
|
|
146
|
+
diagnostics.push(...diagnosticsToRegister);
|
|
155
147
|
});
|
|
156
148
|
// normalize and deduplicate diagnostics
|
|
157
149
|
return NormalizedMessage_1.NormalizedMessage.deduplicate(diagnostics.map(NormalizedMessage_1.NormalizedMessage.createFromDiagnostic));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!
|
|
150
|
+
}
|
|
151
|
+
getLints(cancellationToken) {
|
|
152
|
+
const { linter } = this;
|
|
153
|
+
if (!linter) {
|
|
162
154
|
throw new Error('Cannot get lints - checker has no linter.');
|
|
163
155
|
}
|
|
164
156
|
// select files to lint
|
|
165
|
-
|
|
157
|
+
const filesToLint = this.files
|
|
166
158
|
.keys()
|
|
167
|
-
.filter(
|
|
168
|
-
|
|
169
|
-
!IncrementalChecker.isFileExcluded(filePath, _this.linterExclusions);
|
|
170
|
-
});
|
|
159
|
+
.filter(filePath => !this.files.getData(filePath).linted &&
|
|
160
|
+
!IncrementalChecker.isFileExcluded(filePath, this.linterExclusions));
|
|
171
161
|
// calculate subset of work to do
|
|
172
|
-
|
|
162
|
+
const workSet = new WorkSet_1.WorkSet(filesToLint, this.workNumber, this.workDivision);
|
|
173
163
|
// lint given work set
|
|
174
|
-
workSet.forEach(
|
|
164
|
+
workSet.forEach(fileName => {
|
|
175
165
|
cancellationToken.throwIfCancellationRequested();
|
|
176
166
|
try {
|
|
177
|
-
|
|
167
|
+
// Assertion: `.lint` second parameter can be undefined
|
|
168
|
+
linter.lint(fileName, undefined, this.linterConfig);
|
|
178
169
|
}
|
|
179
170
|
catch (e) {
|
|
180
|
-
if (
|
|
171
|
+
if (FsHelper_1.FsHelper.existsSync(fileName) &&
|
|
181
172
|
// check the error type due to file system lag
|
|
182
173
|
!(e instanceof Error) &&
|
|
183
174
|
!(e.constructor.name === 'FatalError') &&
|
|
@@ -188,28 +179,25 @@ var IncrementalChecker = /** @class */ (function () {
|
|
|
188
179
|
}
|
|
189
180
|
});
|
|
190
181
|
// set lints in files register
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
182
|
+
linter.getResult().failures.forEach(lint => {
|
|
183
|
+
const filePath = lint.getFileName();
|
|
184
|
+
this.files.mutateData(filePath, data => {
|
|
194
185
|
data.linted = true;
|
|
195
186
|
data.lints.push(lint);
|
|
196
187
|
});
|
|
197
188
|
});
|
|
198
189
|
// set all files as linted
|
|
199
|
-
this.files.keys().forEach(
|
|
200
|
-
|
|
190
|
+
this.files.keys().forEach(filePath => {
|
|
191
|
+
this.files.mutateData(filePath, data => {
|
|
201
192
|
data.linted = true;
|
|
202
193
|
});
|
|
203
194
|
});
|
|
204
195
|
// get all lints
|
|
205
|
-
|
|
196
|
+
const lints = this.files
|
|
206
197
|
.keys()
|
|
207
|
-
.reduce(
|
|
208
|
-
return innerLints.concat(_this.files.getData(filePath).lints);
|
|
209
|
-
}, []);
|
|
198
|
+
.reduce((innerLints, filePath) => innerLints.concat(this.files.getData(filePath).lints), []);
|
|
210
199
|
// normalize and deduplicate lints
|
|
211
200
|
return NormalizedMessage_1.NormalizedMessage.deduplicate(lints.map(NormalizedMessage_1.NormalizedMessage.createFromLint));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
}());
|
|
201
|
+
}
|
|
202
|
+
}
|
|
215
203
|
exports.IncrementalChecker = IncrementalChecker;
|
|
File without changes
|
|
@@ -7,22 +7,22 @@ interface NormalizedMessageJson {
|
|
|
7
7
|
code: string | number;
|
|
8
8
|
severity: Severity;
|
|
9
9
|
content: string;
|
|
10
|
-
file
|
|
11
|
-
line
|
|
12
|
-
character
|
|
10
|
+
file?: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
character?: number;
|
|
13
13
|
}
|
|
14
14
|
export declare class NormalizedMessage {
|
|
15
|
-
static TYPE_DIAGNOSTIC: ErrorType;
|
|
16
|
-
static TYPE_LINT: ErrorType;
|
|
17
|
-
static SEVERITY_ERROR: Severity;
|
|
18
|
-
static SEVERITY_WARNING: Severity;
|
|
19
|
-
type: ErrorType;
|
|
20
|
-
code: string | number;
|
|
21
|
-
severity: Severity;
|
|
22
|
-
content: string;
|
|
23
|
-
file
|
|
24
|
-
line
|
|
25
|
-
character
|
|
15
|
+
static readonly TYPE_DIAGNOSTIC: ErrorType;
|
|
16
|
+
static readonly TYPE_LINT: ErrorType;
|
|
17
|
+
static readonly SEVERITY_ERROR: Severity;
|
|
18
|
+
static readonly SEVERITY_WARNING: Severity;
|
|
19
|
+
readonly type: ErrorType;
|
|
20
|
+
readonly code: string | number;
|
|
21
|
+
readonly severity: Severity;
|
|
22
|
+
readonly content: string;
|
|
23
|
+
readonly file?: string;
|
|
24
|
+
readonly line?: number;
|
|
25
|
+
readonly character?: number;
|
|
26
26
|
constructor(data: NormalizedMessageJson);
|
|
27
27
|
static createFromDiagnostic(diagnostic: Diagnostic): NormalizedMessage;
|
|
28
28
|
static createFromLint(lint: RuleFailure): NormalizedMessage;
|
|
@@ -32,20 +32,13 @@ export declare class NormalizedMessage {
|
|
|
32
32
|
static deduplicate(messages: NormalizedMessage[]): NormalizedMessage[];
|
|
33
33
|
static compareTypes(typeA: ErrorType, typeB: ErrorType): number;
|
|
34
34
|
static compareSeverities(severityA: Severity, severityB: Severity): number;
|
|
35
|
-
static compareOptionalStrings(stringA
|
|
36
|
-
static compareNumbers(numberA
|
|
35
|
+
static compareOptionalStrings(stringA?: string, stringB?: string): number;
|
|
36
|
+
static compareNumbers(numberA?: number, numberB?: number): number;
|
|
37
37
|
toJSON(): NormalizedMessageJson;
|
|
38
|
-
getType(): ErrorType;
|
|
39
38
|
isDiagnosticType(): boolean;
|
|
40
39
|
isLintType(): boolean;
|
|
41
|
-
getCode(): string | number;
|
|
42
40
|
getFormattedCode(): string | number;
|
|
43
|
-
getSeverity(): Severity;
|
|
44
41
|
isErrorSeverity(): boolean;
|
|
45
42
|
isWarningSeverity(): boolean;
|
|
46
|
-
getContent(): string;
|
|
47
|
-
getFile(): string;
|
|
48
|
-
getLine(): number;
|
|
49
|
-
getCharacter(): number;
|
|
50
43
|
}
|
|
51
44
|
export {};
|
package/lib/NormalizedMessage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const typescript_1 = require("typescript");
|
|
4
|
+
class NormalizedMessage {
|
|
5
|
+
constructor(data) {
|
|
6
6
|
this.type = data.type;
|
|
7
7
|
this.code = data.code;
|
|
8
8
|
this.severity = data.severity;
|
|
@@ -12,13 +12,16 @@ var NormalizedMessage = /** @class */ (function () {
|
|
|
12
12
|
this.character = data.character;
|
|
13
13
|
}
|
|
14
14
|
// message types
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
static createFromDiagnostic(diagnostic) {
|
|
16
|
+
let file;
|
|
17
|
+
let line;
|
|
18
|
+
let character;
|
|
19
19
|
if (diagnostic.file) {
|
|
20
20
|
file = diagnostic.file.fileName;
|
|
21
|
-
|
|
21
|
+
if (diagnostic.start === undefined) {
|
|
22
|
+
throw new Error('Expected diagnostics to have start');
|
|
23
|
+
}
|
|
24
|
+
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
22
25
|
line = position.line + 1;
|
|
23
26
|
character = position.character + 1;
|
|
24
27
|
}
|
|
@@ -27,13 +30,13 @@ var NormalizedMessage = /** @class */ (function () {
|
|
|
27
30
|
code: diagnostic.code,
|
|
28
31
|
severity: typescript_1.DiagnosticCategory[diagnostic.category].toLowerCase(),
|
|
29
32
|
content: typescript_1.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
|
|
30
|
-
file
|
|
31
|
-
line
|
|
32
|
-
character
|
|
33
|
+
file,
|
|
34
|
+
line,
|
|
35
|
+
character
|
|
33
36
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
}
|
|
38
|
+
static createFromLint(lint) {
|
|
39
|
+
const position = lint.getStartPosition().getLineAndCharacter();
|
|
37
40
|
return new NormalizedMessage({
|
|
38
41
|
type: NormalizedMessage.TYPE_LINT,
|
|
39
42
|
code: lint.getRuleName(),
|
|
@@ -43,54 +46,54 @@ var NormalizedMessage = /** @class */ (function () {
|
|
|
43
46
|
line: position.line + 1,
|
|
44
47
|
character: position.character + 1
|
|
45
48
|
});
|
|
46
|
-
}
|
|
47
|
-
|
|
49
|
+
}
|
|
50
|
+
static createFromJSON(json) {
|
|
48
51
|
return new NormalizedMessage(json);
|
|
49
|
-
}
|
|
50
|
-
|
|
52
|
+
}
|
|
53
|
+
static compare(messageA, messageB) {
|
|
51
54
|
if (!(messageA instanceof NormalizedMessage)) {
|
|
52
55
|
return -1;
|
|
53
56
|
}
|
|
54
57
|
if (!(messageB instanceof NormalizedMessage)) {
|
|
55
58
|
return 1;
|
|
56
59
|
}
|
|
57
|
-
return (NormalizedMessage.compareTypes(messageA.
|
|
58
|
-
NormalizedMessage.compareOptionalStrings(messageA.
|
|
59
|
-
NormalizedMessage.compareSeverities(messageA.
|
|
60
|
-
NormalizedMessage.compareNumbers(messageA.
|
|
61
|
-
NormalizedMessage.compareNumbers(messageA.
|
|
60
|
+
return (NormalizedMessage.compareTypes(messageA.type, messageB.type) ||
|
|
61
|
+
NormalizedMessage.compareOptionalStrings(messageA.file, messageB.file) ||
|
|
62
|
+
NormalizedMessage.compareSeverities(messageA.severity, messageB.severity) ||
|
|
63
|
+
NormalizedMessage.compareNumbers(messageA.line, messageB.line) ||
|
|
64
|
+
NormalizedMessage.compareNumbers(messageA.character, messageB.character) ||
|
|
62
65
|
// code can be string (lint failure) or number (typescript error) - should the following line cater for this in some way?
|
|
63
|
-
NormalizedMessage.compareOptionalStrings(messageA.
|
|
64
|
-
NormalizedMessage.compareOptionalStrings(messageA.
|
|
66
|
+
NormalizedMessage.compareOptionalStrings(messageA.code, messageB.code) ||
|
|
67
|
+
NormalizedMessage.compareOptionalStrings(messageA.content, messageB.content) ||
|
|
65
68
|
0 /* EqualTo */);
|
|
66
|
-
}
|
|
67
|
-
|
|
69
|
+
}
|
|
70
|
+
static equals(messageA, messageB) {
|
|
68
71
|
return this.compare(messageA, messageB) === 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return messages.sort(NormalizedMessage.compare).filter(
|
|
72
|
+
}
|
|
73
|
+
static deduplicate(messages) {
|
|
74
|
+
return messages.sort(NormalizedMessage.compare).filter((message, index) => {
|
|
72
75
|
return (index === 0 || !NormalizedMessage.equals(message, messages[index - 1]));
|
|
73
76
|
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
}
|
|
78
|
+
static compareTypes(typeA, typeB) {
|
|
79
|
+
const priorities = [typeA, typeB].map(type => {
|
|
77
80
|
return [
|
|
78
81
|
NormalizedMessage.TYPE_LINT /* 0 */,
|
|
79
82
|
NormalizedMessage.TYPE_DIAGNOSTIC /* 1 */
|
|
80
83
|
].indexOf(type);
|
|
81
84
|
});
|
|
82
85
|
return priorities[0] - priorities[1];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
}
|
|
87
|
+
static compareSeverities(severityA, severityB) {
|
|
88
|
+
const priorities = [severityA, severityB].map(type => {
|
|
86
89
|
return [
|
|
87
90
|
NormalizedMessage.SEVERITY_WARNING /* 0 */,
|
|
88
91
|
NormalizedMessage.SEVERITY_ERROR /* 1 */
|
|
89
92
|
].indexOf(type);
|
|
90
93
|
});
|
|
91
94
|
return priorities[0] - priorities[1];
|
|
92
|
-
}
|
|
93
|
-
|
|
95
|
+
}
|
|
96
|
+
static compareOptionalStrings(stringA, stringB) {
|
|
94
97
|
if (stringA === stringB) {
|
|
95
98
|
return 0;
|
|
96
99
|
}
|
|
@@ -101,11 +104,20 @@ var NormalizedMessage = /** @class */ (function () {
|
|
|
101
104
|
return 1;
|
|
102
105
|
}
|
|
103
106
|
return stringA.toString().localeCompare(stringB.toString());
|
|
104
|
-
}
|
|
105
|
-
|
|
107
|
+
}
|
|
108
|
+
static compareNumbers(numberA, numberB) {
|
|
109
|
+
if (numberA === numberB) {
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
if (numberA === undefined || numberA === null) {
|
|
113
|
+
return -1;
|
|
114
|
+
}
|
|
115
|
+
if (numberB === undefined || numberB === null) {
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
106
118
|
return numberA - numberB;
|
|
107
|
-
}
|
|
108
|
-
|
|
119
|
+
}
|
|
120
|
+
toJSON() {
|
|
109
121
|
return {
|
|
110
122
|
type: this.type,
|
|
111
123
|
code: this.code,
|
|
@@ -115,48 +127,26 @@ var NormalizedMessage = /** @class */ (function () {
|
|
|
115
127
|
line: this.line,
|
|
116
128
|
character: this.character
|
|
117
129
|
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return this.type;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return NormalizedMessage.
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return this.
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return this.
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
NormalizedMessage.prototype.isWarningSeverity = function () {
|
|
141
|
-
return this.getSeverity() === NormalizedMessage.SEVERITY_WARNING;
|
|
142
|
-
};
|
|
143
|
-
NormalizedMessage.prototype.getContent = function () {
|
|
144
|
-
return this.content;
|
|
145
|
-
};
|
|
146
|
-
NormalizedMessage.prototype.getFile = function () {
|
|
147
|
-
return this.file;
|
|
148
|
-
};
|
|
149
|
-
NormalizedMessage.prototype.getLine = function () {
|
|
150
|
-
return this.line;
|
|
151
|
-
};
|
|
152
|
-
NormalizedMessage.prototype.getCharacter = function () {
|
|
153
|
-
return this.character;
|
|
154
|
-
};
|
|
155
|
-
NormalizedMessage.TYPE_DIAGNOSTIC = 'diagnostic';
|
|
156
|
-
NormalizedMessage.TYPE_LINT = 'lint';
|
|
157
|
-
// severity types
|
|
158
|
-
NormalizedMessage.SEVERITY_ERROR = 'error';
|
|
159
|
-
NormalizedMessage.SEVERITY_WARNING = 'warning';
|
|
160
|
-
return NormalizedMessage;
|
|
161
|
-
}());
|
|
130
|
+
}
|
|
131
|
+
isDiagnosticType() {
|
|
132
|
+
return NormalizedMessage.TYPE_DIAGNOSTIC === this.type;
|
|
133
|
+
}
|
|
134
|
+
isLintType() {
|
|
135
|
+
return NormalizedMessage.TYPE_LINT === this.type;
|
|
136
|
+
}
|
|
137
|
+
getFormattedCode() {
|
|
138
|
+
return this.isDiagnosticType() ? 'TS' + this.code : this.code;
|
|
139
|
+
}
|
|
140
|
+
isErrorSeverity() {
|
|
141
|
+
return this.severity === NormalizedMessage.SEVERITY_ERROR;
|
|
142
|
+
}
|
|
143
|
+
isWarningSeverity() {
|
|
144
|
+
return this.severity === NormalizedMessage.SEVERITY_WARNING;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
NormalizedMessage.TYPE_DIAGNOSTIC = 'diagnostic';
|
|
148
|
+
NormalizedMessage.TYPE_LINT = 'lint';
|
|
149
|
+
// severity types
|
|
150
|
+
NormalizedMessage.SEVERITY_ERROR = 'error';
|
|
151
|
+
NormalizedMessage.SEVERITY_WARNING = 'warning';
|
|
162
152
|
exports.NormalizedMessage = NormalizedMessage;
|
|
File without changes
|