Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .npmignore

This file was deleted.

Binary file removed fork-ts-checker-webpack-plugin-v0.4.11.tgz
Binary file not shown.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "tsc --version && tsc --project \"./src\"",
"test:unit": "mocha -R spec ./test/unit --exit",
"test:integration": "mocha -R spec ./test/integration --exit && rimraf tmp",
"test:integration": "mocha -R spec ./test/integration --exit",
"test": "npm run build && npm run test:unit && npm run test:integration",
"test:watch": "mocha -R spec --watch ./test/unit",
"test:coverage": "rimraf coverage && istanbul cover -root lib --include-all-sources mocha -- -R spec ./test/unit ./test/integration",
Expand Down Expand Up @@ -51,11 +51,9 @@
"devDependencies": {
"@types/babel-code-frame": "^6.20.1",
"@types/chokidar": "^1.7.5",
"@types/lodash": "^4.14.117",
"@types/micromatch": "^3.1.0",
"@types/minimatch": "^3.0.1",
"@types/node": "^8.0.26",
"@types/resolve": "0.0.4",
"@types/webpack": "^4.4.9",
"chai": "^3.5.0",
"css-loader": "^0.28.7",
Expand Down Expand Up @@ -88,10 +86,8 @@
"babel-code-frame": "^6.22.0",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"lodash": "^4.17.11",
"micromatch": "^3.1.10",
"minimatch": "^3.0.4",
"resolve": "^1.5.0",
"tapable": "^1.0.0"
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion src/CancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CancellationToken {
isCancelled: boolean;
cancellationFileName: string;
lastCancellationCheckTime: number;
constructor(cancellationFileName: string, isCancelled: boolean) {
constructor(cancellationFileName?: string, isCancelled?: boolean) {
this.isCancelled = !!isCancelled;
this.cancellationFileName =
cancellationFileName || crypto.randomBytes(64).toString('hex');
Expand Down
6 changes: 3 additions & 3 deletions src/FilesRegister.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as ts from 'typescript';

interface DataShape {
source: ts.SourceFile;
export interface DataShape {
source?: ts.SourceFile;
linted: boolean;
lints: any[];
}

export class FilesRegister {
files: { [filePath: string]: { mtime: number; data: DataShape } };
files: { [filePath: string]: { mtime?: number; data: DataShape } };
dataFactory: (_data?: any) => DataShape; // It doesn't seem that the _data parameter is ever used?

constructor(dataFactory: (_data?: any) => DataShape) {
Expand Down
3 changes: 1 addition & 2 deletions src/FilesWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as chokidar from 'chokidar';
import * as path from 'path';
import startsWith = require('lodash/startsWith');

export class FilesWatcher {
watchPaths: string[];
Expand Down Expand Up @@ -47,7 +46,7 @@ export class FilesWatcher {
return (
this.isWatching() &&
this.isFileSupported(filePath) &&
this.watchPaths.some(watchPath => startsWith(filePath, watchPath))
this.watchPaths.some(watchPath => filePath.startsWith(watchPath))
);
}

Expand Down
62 changes: 31 additions & 31 deletions src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from 'fs';
import endsWith = require('lodash/endsWith');
import * as path from 'path';
import * as ts from 'typescript';
import { Configuration, Linter } from 'tslint'; // Imported for types alone; actual requires take place in methods below
import { Configuration, Linter, RuleFailure } from 'tslint'; // Imported for types alone; actual requires take place in methods below
import { FilesRegister } from './FilesRegister';
import { FilesWatcher } from './FilesWatcher';
import { WorkSet } from './WorkSet';
Expand Down Expand Up @@ -31,13 +30,13 @@ export class IncrementalChecker {
checkSyntacticErrors: boolean;
files: FilesRegister;

linter: Linter;
linterConfig: ConfigurationFile;
linter?: Linter;
linterConfig?: ConfigurationFile;
linterExclusions: minimatch.IMinimatch[];

program: ts.Program;
programConfig: ts.ParsedCommandLine;
watcher: FilesWatcher;
program?: ts.Program;
programConfig?: ts.ParsedCommandLine;
watcher?: FilesWatcher;

vue: boolean;

Expand Down Expand Up @@ -146,12 +145,16 @@ export class IncrementalChecker {
return new tslint.Linter({ fix: this.linterAutoFix }, program);
}

hasLinter(): boolean {
return !!this.linter;
}

static isFileExcluded(
filePath: string,
linterExclusions: minimatch.IMinimatch[]
): boolean {
return (
endsWith(filePath, '.d.ts') ||
filePath.endsWith('.d.ts') ||
linterExclusions.some(matcher => matcher.match(filePath))
);
}
Expand Down Expand Up @@ -195,7 +198,7 @@ export class IncrementalChecker {
this.program = this.vue ? this.loadVueProgram() : this.loadDefaultProgram();

if (this.linterConfig) {
this.linter = this.createLinter(this.program);
this.linter = this.createLinter(this.program!);
}
}

Expand All @@ -211,8 +214,8 @@ export class IncrementalChecker {
this.programConfig,
path.dirname(this.programConfigFile),
this.files,
this.watcher,
this.program
this.watcher!,
this.program!
);
}

Expand All @@ -227,19 +230,19 @@ export class IncrementalChecker {
return IncrementalChecker.createProgram(
this.programConfig,
this.files,
this.watcher,
this.program
this.watcher!,
this.program!
);
}

hasLinter() {
return this.linter !== undefined;
}

getDiagnostics(cancellationToken: CancellationToken) {
const { program } = this;
if (!program) {
throw new Error('Invoked called before program initialized');
}
const diagnostics: ts.Diagnostic[] = [];
// select files to check (it's semantic check - we have to include all files :/)
const filesToCheck = this.program.getSourceFiles();
const filesToCheck = program.getSourceFiles();

// calculate subset of work to do
const workSet = new WorkSet(
Expand All @@ -256,17 +259,14 @@ export class IncrementalChecker {

const diagnosticsToRegister: ReadonlyArray<ts.Diagnostic> = this
.checkSyntacticErrors
? []
.concat(
this.program.getSemanticDiagnostics(sourceFile, cancellationToken)
)
.concat(
this.program.getSyntacticDiagnostics(
sourceFile,
cancellationToken
? program.getSemanticDiagnostics(sourceFile, cancellationToken)
.concat(
program.getSyntacticDiagnostics(
sourceFile,
cancellationToken
)
)
: this.program.getSemanticDiagnostics(sourceFile, cancellationToken);
)
: program.getSemanticDiagnostics(sourceFile, cancellationToken);

diagnostics.push.apply(diagnostics, diagnosticsToRegister);
});
Expand All @@ -278,7 +278,7 @@ export class IncrementalChecker {
}

getLints(cancellationToken: CancellationToken) {
if (!this.hasLinter()) {
if (!this.linter) {
throw new Error('Cannot get lints - checker has no linter.');
}

Expand All @@ -303,7 +303,7 @@ export class IncrementalChecker {
cancellationToken.throwIfCancellationRequested();

try {
this.linter.lint(fileName, undefined, this.linterConfig);
this.linter!.lint(fileName, undefined!, this.linterConfig); // REVIEW: this shouldn't work?
} catch (e) {
if (
fs.existsSync(fileName) &&
Expand Down Expand Up @@ -341,7 +341,7 @@ export class IncrementalChecker {
.reduce(
(innerLints, filePath) =>
innerLints.concat(this.files.getData(filePath).lints),
[]
[] as RuleFailure[]
);

// normalize and deduplicate lints
Expand Down
34 changes: 23 additions & 11 deletions src/NormalizedMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ interface NormalizedMessageJson {
code: string | number;
severity: Severity;
content: string;
file: string;
line: number;
character: number;
file?: string;
line?: number;
character?: number;
}

export class NormalizedMessage {
Expand All @@ -30,9 +30,9 @@ export class NormalizedMessage {
code: string | number;
severity: Severity;
content: string;
file: string;
line: number;
character: number;
file?: string;
line?: number;
character?: number;

constructor(data: NormalizedMessageJson) {
this.type = data.type;
Expand All @@ -46,11 +46,14 @@ export class NormalizedMessage {

// message types
static createFromDiagnostic(diagnostic: Diagnostic) {
let file: string;
let line: number;
let character: number;
let file: string | undefined;
let line: number | undefined;
let character: number | undefined;
if (diagnostic.file) {
file = diagnostic.file.fileName;
if (!diagnostic.start) {
throw new Error('Expected diagnostics to have start');
}
const position = diagnostic.file.getLineAndCharacterOfPosition(
diagnostic.start
);
Expand Down Expand Up @@ -162,7 +165,7 @@ export class NormalizedMessage {
return priorities[0] - priorities[1];
}

static compareOptionalStrings(stringA: string, stringB: string) {
static compareOptionalStrings(stringA?: string, stringB?: string) {
if (stringA === stringB) {
return 0;
}
Expand All @@ -176,7 +179,16 @@ export class NormalizedMessage {
return stringA.toString().localeCompare(stringB.toString());
}

static compareNumbers(numberA: number, numberB: number) {
static compareNumbers(numberA?: number, numberB?: number) {
if (numberA === numberB) {
return 0;
}
if (numberA === undefined || numberA === null) {
return -1;
}
if (numberB === undefined || numberB === null) {
return 1;
}
return numberA - numberB;
}

Expand Down
4 changes: 2 additions & 2 deletions src/VueProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class VueProgram {
? options.paths[`${correctWildcard}/*`]
: undefined;
const substitution = pattern
? options.paths[`${correctWildcard}/*`][0].replace('*', '')
? options.paths![`${correctWildcard}/*`][0].replace('*', '')
: 'src';
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
} else if (isRelative) {
Expand Down Expand Up @@ -234,7 +234,7 @@ export class VueProgram {
);
}

private static getScriptKindByLang(lang: string) {
private static getScriptKindByLang(lang?: string) {
if (lang === 'ts') {
return ts.ScriptKind.TS;
} else if (lang === 'tsx') {
Expand Down
4 changes: 2 additions & 2 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NormalizedMessage } from './NormalizedMessage';
import { Message } from './Message';

// fork workers...
const division = parseInt(process.env.WORK_DIVISION, 10);
const division = parseInt(process.env.WORK_DIVISION || '', 10);
const workers: childProcess.ChildProcess[] = [];

for (let num = 0; num < division; num++) {
Expand Down Expand Up @@ -61,7 +61,7 @@ workers.forEach(worker => {
merged.lints = NormalizedMessage.deduplicate(merged.lints);

try {
process.send(merged);
process.send!(merged);
} catch (e) {
// channel closed...
process.exit();
Expand Down
11 changes: 6 additions & 5 deletions src/formatter/codeframeFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ export function createCodeframeFormatter(options: any) {
: colors.bold.red;
const positionColor = colors.dim;

const file = message.getFile();
const source =
message.getFile() &&
fs.existsSync(message.getFile()) &&
fs.readFileSync(message.getFile(), 'utf-8');
file &&
fs.existsSync(file) &&
fs.readFileSync(file, 'utf-8');
let frame = '';

if (source) {
frame = codeFrame(
source,
message.line,
message.character,
message.line!, // Assetions: `codeFrame` allows passing undefined, typings are incorrect
message.character!,
Object.assign({}, options || {}, { highlightCode: useColors })
)
.split('\n')
Expand Down
Loading