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.
Files changed (34) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +3 -0
  3. package/lib/{types/CancellationToken.d.ts → CancellationToken.d.ts} +4 -4
  4. package/lib/CancellationToken.js +28 -27
  5. package/lib/{types/FilesRegister.d.ts → FilesRegister.d.ts} +9 -14
  6. package/lib/FilesRegister.js +24 -24
  7. package/lib/{types/FilesWatcher.d.ts → FilesWatcher.d.ts} +4 -7
  8. package/lib/FilesWatcher.js +27 -29
  9. package/lib/FsHelper.d.ts +5 -0
  10. package/lib/FsHelper.js +20 -0
  11. package/lib/IncrementalChecker.d.ts +34 -0
  12. package/lib/IncrementalChecker.js +97 -109
  13. package/lib/{types/Message.d.ts → Message.d.ts} +0 -0
  14. package/lib/{types/NormalizedMessage.d.ts → NormalizedMessage.d.ts} +16 -23
  15. package/lib/NormalizedMessage.js +76 -86
  16. package/lib/{types/VueProgram.d.ts → VueProgram.d.ts} +0 -0
  17. package/lib/VueProgram.js +62 -77
  18. package/lib/{types/WorkResult.d.ts → WorkResult.d.ts} +6 -6
  19. package/lib/WorkResult.js +22 -25
  20. package/lib/{types/WorkSet.d.ts → WorkSet.d.ts} +6 -6
  21. package/lib/WorkSet.js +6 -7
  22. package/lib/{types/cluster.d.ts → cluster.d.ts} +0 -0
  23. package/lib/cluster.js +19 -19
  24. package/lib/{types/formatter → formatter}/codeframeFormatter.d.ts +0 -0
  25. package/lib/formatter/codeframeFormatter.js +17 -16
  26. package/lib/{types/formatter → formatter}/defaultFormatter.d.ts +0 -0
  27. package/lib/formatter/defaultFormatter.js +9 -9
  28. package/lib/index.d.ts +98 -0
  29. package/lib/index.js +183 -192
  30. package/lib/{types/service.d.ts → service.d.ts} +0 -0
  31. package/lib/service.js +11 -11
  32. package/package.json +14 -18
  33. package/lib/types/IncrementalChecker.d.ts +0 -43
  34. 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
- var fs = require("fs");
15
- var endsWith = require("lodash/endsWith");
16
- var path = require("path");
17
- var ts = require("typescript");
18
- var FilesRegister_1 = require("./FilesRegister");
19
- var FilesWatcher_1 = require("./FilesWatcher");
20
- var WorkSet_1 = require("./WorkSet");
21
- var NormalizedMessage_1 = require("./NormalizedMessage");
22
- var minimatch = require("minimatch");
23
- var VueProgram_1 = require("./VueProgram");
24
- var IncrementalChecker = /** @class */ (function () {
25
- function IncrementalChecker(programConfigFile, compilerOptions, linterConfigFile, watchPaths, workNumber, workDivision, checkSyntacticErrors, vue) {
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 || 0;
31
- this.workDivision = workDivision || 1;
32
- this.checkSyntacticErrors = checkSyntacticErrors || false;
33
- this.vue = vue || false;
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(function () { return ({
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
- IncrementalChecker.loadProgramConfig = function (configFile, compilerOptions) {
46
- var tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
35
+ static loadProgramConfig(configFile, compilerOptions) {
36
+ const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
47
37
  tsconfig.compilerOptions = tsconfig.compilerOptions || {};
48
- tsconfig.compilerOptions = __assign({}, tsconfig.compilerOptions, compilerOptions);
49
- var parsed = ts.parseJsonConfigFileContent(tsconfig, ts.sys, path.dirname(configFile));
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
- IncrementalChecker.loadLinterConfig = function (configFile) {
53
- var tslint = require('tslint');
41
+ }
42
+ static loadLinterConfig(configFile) {
43
+ const tslint = require('tslint');
54
44
  return tslint.Configuration.loadConfigurationFromPath(configFile);
55
- };
56
- IncrementalChecker.createProgram = function (programConfig, files, watcher, oldProgram) {
57
- var host = ts.createCompilerHost(programConfig.options);
58
- var realGetSourceFile = host.getSourceFile;
59
- host.getSourceFile = function (filePath, languageVersion, onError) {
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
- var stats = fs.statSync(filePath);
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, function (data) {
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
- IncrementalChecker.createLinter = function (program) {
83
- var tslint = require('tslint');
84
- return new tslint.Linter({ fix: false }, program);
85
- };
86
- IncrementalChecker.isFileExcluded = function (filePath, linterExclusions) {
87
- return (endsWith(filePath, '.d.ts') ||
88
- linterExclusions.some(function (matcher) { return matcher.match(filePath); }));
89
- };
90
- IncrementalChecker.prototype.nextIteration = function () {
91
- var _this = this;
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
- var watchExtensions = this.vue
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', function (filePath, stats) {
99
- _this.files.setMtime(filePath, stats.mtime.valueOf());
90
+ this.watcher.on('change', (filePath, stats) => {
91
+ this.files.setMtime(filePath, stats.mtime.valueOf());
100
92
  });
101
- this.watcher.on('unlink', function (filePath) {
102
- _this.files.remove(filePath);
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(function (pattern) { return new minimatch.Minimatch(path.resolve(pattern)); });
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 = IncrementalChecker.createLinter(this.program);
110
+ this.linter = this.createLinter(this.program);
119
111
  }
120
- };
121
- IncrementalChecker.prototype.loadVueProgram = function () {
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
- IncrementalChecker.prototype.loadDefaultProgram = function () {
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
- IncrementalChecker.prototype.hasLinter = function () {
134
- return this.linter !== undefined;
135
- };
136
- IncrementalChecker.prototype.getDiagnostics = function (cancellationToken) {
137
- var _this = this;
138
- var diagnostics = [];
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
- var filesToCheck = this.program.getSourceFiles();
132
+ const filesToCheck = program.getSourceFiles();
141
133
  // calculate subset of work to do
142
- var workSet = new WorkSet_1.WorkSet(filesToCheck, this.workNumber, this.workDivision);
134
+ const workSet = new WorkSet_1.WorkSet(filesToCheck, this.workNumber, this.workDivision);
143
135
  // check given work set
144
- workSet.forEach(function (sourceFile) {
136
+ workSet.forEach(sourceFile => {
145
137
  if (cancellationToken) {
146
138
  cancellationToken.throwIfCancellationRequested();
147
139
  }
148
- var diagnosticsToRegister = _this
140
+ const diagnosticsToRegister = this
149
141
  .checkSyntacticErrors
150
- ? []
151
- .concat(_this.program.getSemanticDiagnostics(sourceFile, cancellationToken))
152
- .concat(_this.program.getSyntacticDiagnostics(sourceFile, cancellationToken))
153
- : _this.program.getSemanticDiagnostics(sourceFile, cancellationToken);
154
- diagnostics.push.apply(diagnostics, diagnosticsToRegister);
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
- IncrementalChecker.prototype.getLints = function (cancellationToken) {
160
- var _this = this;
161
- if (!this.hasLinter()) {
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
- var filesToLint = this.files
157
+ const filesToLint = this.files
166
158
  .keys()
167
- .filter(function (filePath) {
168
- return !_this.files.getData(filePath).linted &&
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
- var workSet = new WorkSet_1.WorkSet(filesToLint, this.workNumber, this.workDivision);
162
+ const workSet = new WorkSet_1.WorkSet(filesToLint, this.workNumber, this.workDivision);
173
163
  // lint given work set
174
- workSet.forEach(function (fileName) {
164
+ workSet.forEach(fileName => {
175
165
  cancellationToken.throwIfCancellationRequested();
176
166
  try {
177
- _this.linter.lint(fileName, undefined, _this.linterConfig);
167
+ // Assertion: `.lint` second parameter can be undefined
168
+ linter.lint(fileName, undefined, this.linterConfig);
178
169
  }
179
170
  catch (e) {
180
- if (fs.existsSync(fileName) &&
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
- this.linter.getResult().failures.forEach(function (lint) {
192
- var filePath = lint.getFileName();
193
- _this.files.mutateData(filePath, function (data) {
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(function (filePath) {
200
- _this.files.mutateData(filePath, function (data) {
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
- var lints = this.files
196
+ const lints = this.files
206
197
  .keys()
207
- .reduce(function (innerLints, filePath) {
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
- return IncrementalChecker;
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: string;
11
- line: number;
12
- character: number;
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: string;
24
- line: number;
25
- character: number;
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: string, stringB: string): number;
36
- static compareNumbers(numberA: number, numberB: number): number;
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 {};
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var typescript_1 = require("typescript");
4
- var NormalizedMessage = /** @class */ (function () {
5
- function NormalizedMessage(data) {
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
- NormalizedMessage.createFromDiagnostic = function (diagnostic) {
16
- var file;
17
- var line;
18
- var character;
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
- var position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
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: file,
31
- line: line,
32
- character: character
33
+ file,
34
+ line,
35
+ character
33
36
  });
34
- };
35
- NormalizedMessage.createFromLint = function (lint) {
36
- var position = lint.getStartPosition().getLineAndCharacter();
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
- NormalizedMessage.createFromJSON = function (json) {
49
+ }
50
+ static createFromJSON(json) {
48
51
  return new NormalizedMessage(json);
49
- };
50
- NormalizedMessage.compare = function (messageA, messageB) {
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.getType(), messageB.getType()) ||
58
- NormalizedMessage.compareOptionalStrings(messageA.getFile(), messageB.getFile()) ||
59
- NormalizedMessage.compareSeverities(messageA.getSeverity(), messageB.getSeverity()) ||
60
- NormalizedMessage.compareNumbers(messageA.getLine(), messageB.getLine()) ||
61
- NormalizedMessage.compareNumbers(messageA.getCharacter(), messageB.getCharacter()) ||
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.getCode(), messageB.getCode()) ||
64
- NormalizedMessage.compareOptionalStrings(messageA.getContent(), messageB.getContent()) ||
66
+ NormalizedMessage.compareOptionalStrings(messageA.code, messageB.code) ||
67
+ NormalizedMessage.compareOptionalStrings(messageA.content, messageB.content) ||
65
68
  0 /* EqualTo */);
66
- };
67
- NormalizedMessage.equals = function (messageA, messageB) {
69
+ }
70
+ static equals(messageA, messageB) {
68
71
  return this.compare(messageA, messageB) === 0;
69
- };
70
- NormalizedMessage.deduplicate = function (messages) {
71
- return messages.sort(NormalizedMessage.compare).filter(function (message, index) {
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
- NormalizedMessage.compareTypes = function (typeA, typeB) {
76
- var priorities = [typeA, typeB].map(function (type) {
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
- NormalizedMessage.compareSeverities = function (severityA, severityB) {
85
- var priorities = [severityA, severityB].map(function (type) {
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
- NormalizedMessage.compareOptionalStrings = function (stringA, stringB) {
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
- NormalizedMessage.compareNumbers = function (numberA, numberB) {
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
- NormalizedMessage.prototype.toJSON = function () {
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
- NormalizedMessage.prototype.getType = function () {
120
- return this.type;
121
- };
122
- NormalizedMessage.prototype.isDiagnosticType = function () {
123
- return NormalizedMessage.TYPE_DIAGNOSTIC === this.getType();
124
- };
125
- NormalizedMessage.prototype.isLintType = function () {
126
- return NormalizedMessage.TYPE_LINT === this.getType();
127
- };
128
- NormalizedMessage.prototype.getCode = function () {
129
- return this.code;
130
- };
131
- NormalizedMessage.prototype.getFormattedCode = function () {
132
- return this.isDiagnosticType() ? 'TS' + this.getCode() : this.getCode();
133
- };
134
- NormalizedMessage.prototype.getSeverity = function () {
135
- return this.severity;
136
- };
137
- NormalizedMessage.prototype.isErrorSeverity = function () {
138
- return this.getSeverity() === NormalizedMessage.SEVERITY_ERROR;
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