Skip to content

Commit bd2e975

Browse files
author
Andy
authored
Enable 'no-empty' tslint rule (microsoft#19769)
* Enable 'no-empty' tslint rule * Fix bug
1 parent 2a6684f commit bd2e975

15 files changed

+35
-62
lines changed

Gulpfile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
7474
}
7575
});
7676

77-
function exec(cmd: string, args: string[], complete: () => void = (() => { }), error: (e: any, status: number) => void = (() => { })) {
77+
const noop = () => {}; // tslint:disable-line no-empty
78+
function exec(cmd: string, args: string[], complete: () => void = noop, error: (e: any, status: number) => void = noop) {
7879
console.log(`${cmd} ${args.join(" ")}`);
7980
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
8081
const subshellFlag = isWin ? "/c" : "-c";

src/compiler/core.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ namespace ts {
13411341
}
13421342

13431343
/** Does nothing. */
1344-
export function noop(): void { }
1344+
export function noop(_?: {} | null | undefined): void { } // tslint:disable-line no-empty
13451345

13461346
/** Do nothing and return false */
13471347
export function returnFalse(): false { return false; }
@@ -2659,8 +2659,7 @@ namespace ts {
26592659
}
26602660
}
26612661

2662-
function Signature() {
2663-
}
2662+
function Signature() {} // tslint:disable-line no-empty
26642663

26652664
function Node(this: Node, kind: SyntaxKind, pos: number, end: number) {
26662665
this.id = 0;
@@ -2931,7 +2930,7 @@ namespace ts {
29312930
return (arg: T) => f(arg) && g(arg);
29322931
}
29332932

2934-
export function assertTypeIsNever(_: never): void { }
2933+
export function assertTypeIsNever(_: never): void { } // tslint:disable-line no-empty
29352934

29362935
export interface FileAndDirectoryExistence {
29372936
fileExists: boolean;

src/compiler/performance.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ namespace ts {
1010
namespace ts.performance {
1111
declare const onProfilerEvent: { (markName: string): void; profiler: boolean; };
1212

13-
const profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true
14-
? onProfilerEvent
15-
: (_markName: string) => { };
13+
const profilerEvent: (markName: string) => void = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true ? onProfilerEvent : noop;
1614

1715
let enabled = false;
1816
let profilerStart = 0;

src/compiler/sys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ namespace ts {
511511
return stat.size;
512512
}
513513
}
514-
catch (e) { }
514+
catch { /*ignore*/ }
515515
return 0;
516516
},
517517
exit(exitCode?: number): void {
@@ -525,7 +525,7 @@ namespace ts {
525525
try {
526526
require("source-map-support").install();
527527
}
528-
catch (e) {
528+
catch {
529529
// Could not enable source maps.
530530
}
531531
},

src/harness/harness.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,7 @@ namespace Harness {
555555
try {
556556
fs.unlinkSync(path);
557557
}
558-
catch (e) {
559-
}
558+
catch { /*ignore*/ }
560559
}
561560

562561
export function directoryExists(path: string): boolean {
@@ -615,7 +614,7 @@ namespace Harness {
615614

616615
namespace Http {
617616
function waitForXHR(xhr: XMLHttpRequest) {
618-
while (xhr.readyState !== 4) { }
617+
while (xhr.readyState !== 4) { } // tslint:disable-line no-empty
619618
return { status: xhr.status, responseText: xhr.responseText };
620619
}
621620

src/harness/harnessLanguageService.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ namespace Harness.LanguageService {
166166
throw new Error("No script with name '" + fileName + "'");
167167
}
168168

169-
public openFile(_fileName: string, _content?: string, _scriptKindName?: string): void {
170-
}
169+
public openFile(_fileName: string, _content?: string, _scriptKindName?: string): void { /*overridden*/ }
171170

172171
/**
173172
* @param line 0 based index
@@ -237,9 +236,9 @@ namespace Harness.LanguageService {
237236
}
238237

239238

240-
log(_: string): void { }
241-
trace(_: string): void { }
242-
error(_: string): void { }
239+
log = ts.noop;
240+
trace = ts.noop;
241+
error = ts.noop;
243242
}
244243

245244
export class NativeLanguageServiceAdapter implements LanguageServiceAdapter {
@@ -596,13 +595,8 @@ namespace Harness.LanguageService {
596595
super(cancellationToken, settings);
597596
}
598597

599-
onMessage(): void {
600-
601-
}
602-
603-
writeMessage(): void {
604-
605-
}
598+
onMessage = ts.noop;
599+
writeMessage = ts.noop;
606600

607601
setClient(client: ts.server.SessionClient) {
608602
this.client = client;
@@ -628,13 +622,8 @@ namespace Harness.LanguageService {
628622
this.newLine = this.host.getNewLine();
629623
}
630624

631-
onMessage(): void {
632-
633-
}
634-
635-
writeMessage(_message: string): void {
636-
}
637-
625+
onMessage = ts.noop;
626+
writeMessage = ts.noop; // overridden
638627
write(message: string): void {
639628
this.writeMessage(message);
640629
}
@@ -648,8 +637,7 @@ namespace Harness.LanguageService {
648637
return snapshot && snapshot.getText(0, snapshot.getLength());
649638
}
650639

651-
writeFile(): void {
652-
}
640+
writeFile = ts.noop;
653641

654642
resolvePath(path: string): string {
655643
return path;
@@ -668,8 +656,7 @@ namespace Harness.LanguageService {
668656
return "";
669657
}
670658

671-
exit(): void {
672-
}
659+
exit = ts.noop;
673660

674661
createDirectory(_directoryName: string): void {
675662
return ts.notImplemented();
@@ -697,8 +684,7 @@ namespace Harness.LanguageService {
697684
return { close: ts.noop };
698685
}
699686

700-
close(): void {
701-
}
687+
close = ts.noop;
702688

703689
info(message: string): void {
704690
this.host.log(message);

src/harness/projectsRunner.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class ProjectRunner extends RunnerBase {
396396
});
397397

398398
// Dont allow config files since we are compiling existing source options
399-
return compileProjectFiles(compilerResult.moduleKind, compilerResult.configFileSourceFiles, getInputFiles, getSourceFileText, writeFile, compilerResult.compilerOptions);
399+
return compileProjectFiles(compilerResult.moduleKind, compilerResult.configFileSourceFiles, getInputFiles, getSourceFileText, /*writeFile*/ ts.noop, compilerResult.compilerOptions);
400400

401401
function findOutputDtsFile(fileName: string) {
402402
return ts.forEach(compilerResult.outputFiles, outputFile => outputFile.emittedFileName === fileName ? outputFile : undefined);
@@ -416,9 +416,6 @@ class ProjectRunner extends RunnerBase {
416416
}
417417
return undefined;
418418
}
419-
420-
function writeFile() {
421-
}
422419
}
423420

424421
function getErrorsBaseline(compilerResult: CompileProjectFilesResult) {

src/harness/runnerbase.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ type CompilerTestKind = "conformance" | "compiler";
66
type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server";
77

88
abstract class RunnerBase {
9-
constructor() { }
10-
119
// contains the tests to run
1210
public tests: string[] = [];
1311

src/harness/unittests/extractTestHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace ts {
126126

127127
const sourceFile = program.getSourceFile(path);
128128
const context: RefactorContext = {
129-
cancellationToken: { throwIfCancellationRequested() { }, isCancellationRequested() { return false; } },
129+
cancellationToken: { throwIfCancellationRequested: noop, isCancellationRequested: returnFalse },
130130
newLineCharacter,
131131
program,
132132
file: sourceFile,
@@ -190,7 +190,7 @@ namespace ts {
190190
const program = projectService.inferredProjects[0].getLanguageService().getProgram();
191191
const sourceFile = program.getSourceFile(f.path);
192192
const context: RefactorContext = {
193-
cancellationToken: { throwIfCancellationRequested() { }, isCancellationRequested() { return false; } },
193+
cancellationToken: { throwIfCancellationRequested: noop, isCancellationRequested: returnFalse },
194194
newLineCharacter,
195195
program,
196196
file: sourceFile,

src/harness/unittests/hostNewLineSupport.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ namespace ts {
55
function snapFor(path: string): IScriptSnapshot {
66
if (path === "lib.d.ts") {
77
return {
8-
dispose() {},
8+
dispose: noop,
99
getChangeRange() { return undefined; },
1010
getLength() { return 0; },
11-
getText(_start, _end) {
11+
getText() {
1212
return "";
1313
}
1414
};
1515
}
1616
const result = forEach(files, f => f.unitName === path ? f : undefined);
1717
if (result) {
1818
return {
19-
dispose() {},
19+
dispose: noop,
2020
getChangeRange() { return undefined; },
2121
getLength() { return result.content.length; },
2222
getText(start, end) {

0 commit comments

Comments
 (0)