mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Enable 'no-empty' tslint rule (#19769)
* Enable 'no-empty' tslint rule * Fix bug
This commit is contained in:
+2
-1
@@ -74,7 +74,8 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
|
||||
}
|
||||
});
|
||||
|
||||
function exec(cmd: string, args: string[], complete: () => void = (() => { }), error: (e: any, status: number) => void = (() => { })) {
|
||||
const noop = () => {}; // tslint:disable-line no-empty
|
||||
function exec(cmd: string, args: string[], complete: () => void = noop, error: (e: any, status: number) => void = noop) {
|
||||
console.log(`${cmd} ${args.join(" ")}`);
|
||||
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
|
||||
const subshellFlag = isWin ? "/c" : "-c";
|
||||
|
||||
@@ -1341,7 +1341,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/** Does nothing. */
|
||||
export function noop(): void { }
|
||||
export function noop(_?: {} | null | undefined): void { } // tslint:disable-line no-empty
|
||||
|
||||
/** Do nothing and return false */
|
||||
export function returnFalse(): false { return false; }
|
||||
@@ -2659,8 +2659,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function Signature() {
|
||||
}
|
||||
function Signature() {} // tslint:disable-line no-empty
|
||||
|
||||
function Node(this: Node, kind: SyntaxKind, pos: number, end: number) {
|
||||
this.id = 0;
|
||||
@@ -2931,7 +2930,7 @@ namespace ts {
|
||||
return (arg: T) => f(arg) && g(arg);
|
||||
}
|
||||
|
||||
export function assertTypeIsNever(_: never): void { }
|
||||
export function assertTypeIsNever(_: never): void { } // tslint:disable-line no-empty
|
||||
|
||||
export interface FileAndDirectoryExistence {
|
||||
fileExists: boolean;
|
||||
|
||||
@@ -10,9 +10,7 @@ namespace ts {
|
||||
namespace ts.performance {
|
||||
declare const onProfilerEvent: { (markName: string): void; profiler: boolean; };
|
||||
|
||||
const profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true
|
||||
? onProfilerEvent
|
||||
: (_markName: string) => { };
|
||||
const profilerEvent: (markName: string) => void = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true ? onProfilerEvent : noop;
|
||||
|
||||
let enabled = false;
|
||||
let profilerStart = 0;
|
||||
|
||||
+2
-2
@@ -511,7 +511,7 @@ namespace ts {
|
||||
return stat.size;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
catch { /*ignore*/ }
|
||||
return 0;
|
||||
},
|
||||
exit(exitCode?: number): void {
|
||||
@@ -525,7 +525,7 @@ namespace ts {
|
||||
try {
|
||||
require("source-map-support").install();
|
||||
}
|
||||
catch (e) {
|
||||
catch {
|
||||
// Could not enable source maps.
|
||||
}
|
||||
},
|
||||
|
||||
@@ -555,8 +555,7 @@ namespace Harness {
|
||||
try {
|
||||
fs.unlinkSync(path);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
catch { /*ignore*/ }
|
||||
}
|
||||
|
||||
export function directoryExists(path: string): boolean {
|
||||
@@ -615,7 +614,7 @@ namespace Harness {
|
||||
|
||||
namespace Http {
|
||||
function waitForXHR(xhr: XMLHttpRequest) {
|
||||
while (xhr.readyState !== 4) { }
|
||||
while (xhr.readyState !== 4) { } // tslint:disable-line no-empty
|
||||
return { status: xhr.status, responseText: xhr.responseText };
|
||||
}
|
||||
|
||||
|
||||
@@ -166,8 +166,7 @@ namespace Harness.LanguageService {
|
||||
throw new Error("No script with name '" + fileName + "'");
|
||||
}
|
||||
|
||||
public openFile(_fileName: string, _content?: string, _scriptKindName?: string): void {
|
||||
}
|
||||
public openFile(_fileName: string, _content?: string, _scriptKindName?: string): void { /*overridden*/ }
|
||||
|
||||
/**
|
||||
* @param line 0 based index
|
||||
@@ -237,9 +236,9 @@ namespace Harness.LanguageService {
|
||||
}
|
||||
|
||||
|
||||
log(_: string): void { }
|
||||
trace(_: string): void { }
|
||||
error(_: string): void { }
|
||||
log = ts.noop;
|
||||
trace = ts.noop;
|
||||
error = ts.noop;
|
||||
}
|
||||
|
||||
export class NativeLanguageServiceAdapter implements LanguageServiceAdapter {
|
||||
@@ -596,13 +595,8 @@ namespace Harness.LanguageService {
|
||||
super(cancellationToken, settings);
|
||||
}
|
||||
|
||||
onMessage(): void {
|
||||
|
||||
}
|
||||
|
||||
writeMessage(): void {
|
||||
|
||||
}
|
||||
onMessage = ts.noop;
|
||||
writeMessage = ts.noop;
|
||||
|
||||
setClient(client: ts.server.SessionClient) {
|
||||
this.client = client;
|
||||
@@ -628,13 +622,8 @@ namespace Harness.LanguageService {
|
||||
this.newLine = this.host.getNewLine();
|
||||
}
|
||||
|
||||
onMessage(): void {
|
||||
|
||||
}
|
||||
|
||||
writeMessage(_message: string): void {
|
||||
}
|
||||
|
||||
onMessage = ts.noop;
|
||||
writeMessage = ts.noop; // overridden
|
||||
write(message: string): void {
|
||||
this.writeMessage(message);
|
||||
}
|
||||
@@ -648,8 +637,7 @@ namespace Harness.LanguageService {
|
||||
return snapshot && snapshot.getText(0, snapshot.getLength());
|
||||
}
|
||||
|
||||
writeFile(): void {
|
||||
}
|
||||
writeFile = ts.noop;
|
||||
|
||||
resolvePath(path: string): string {
|
||||
return path;
|
||||
@@ -668,8 +656,7 @@ namespace Harness.LanguageService {
|
||||
return "";
|
||||
}
|
||||
|
||||
exit(): void {
|
||||
}
|
||||
exit = ts.noop;
|
||||
|
||||
createDirectory(_directoryName: string): void {
|
||||
return ts.notImplemented();
|
||||
@@ -697,8 +684,7 @@ namespace Harness.LanguageService {
|
||||
return { close: ts.noop };
|
||||
}
|
||||
|
||||
close(): void {
|
||||
}
|
||||
close = ts.noop;
|
||||
|
||||
info(message: string): void {
|
||||
this.host.log(message);
|
||||
|
||||
@@ -396,7 +396,7 @@ class ProjectRunner extends RunnerBase {
|
||||
});
|
||||
|
||||
// Dont allow config files since we are compiling existing source options
|
||||
return compileProjectFiles(compilerResult.moduleKind, compilerResult.configFileSourceFiles, getInputFiles, getSourceFileText, writeFile, compilerResult.compilerOptions);
|
||||
return compileProjectFiles(compilerResult.moduleKind, compilerResult.configFileSourceFiles, getInputFiles, getSourceFileText, /*writeFile*/ ts.noop, compilerResult.compilerOptions);
|
||||
|
||||
function findOutputDtsFile(fileName: string) {
|
||||
return ts.forEach(compilerResult.outputFiles, outputFile => outputFile.emittedFileName === fileName ? outputFile : undefined);
|
||||
@@ -416,9 +416,6 @@ class ProjectRunner extends RunnerBase {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function writeFile() {
|
||||
}
|
||||
}
|
||||
|
||||
function getErrorsBaseline(compilerResult: CompileProjectFilesResult) {
|
||||
|
||||
@@ -6,8 +6,6 @@ type CompilerTestKind = "conformance" | "compiler";
|
||||
type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server";
|
||||
|
||||
abstract class RunnerBase {
|
||||
constructor() { }
|
||||
|
||||
// contains the tests to run
|
||||
public tests: string[] = [];
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace ts {
|
||||
|
||||
const sourceFile = program.getSourceFile(path);
|
||||
const context: RefactorContext = {
|
||||
cancellationToken: { throwIfCancellationRequested() { }, isCancellationRequested() { return false; } },
|
||||
cancellationToken: { throwIfCancellationRequested: noop, isCancellationRequested: returnFalse },
|
||||
newLineCharacter,
|
||||
program,
|
||||
file: sourceFile,
|
||||
@@ -190,7 +190,7 @@ namespace ts {
|
||||
const program = projectService.inferredProjects[0].getLanguageService().getProgram();
|
||||
const sourceFile = program.getSourceFile(f.path);
|
||||
const context: RefactorContext = {
|
||||
cancellationToken: { throwIfCancellationRequested() { }, isCancellationRequested() { return false; } },
|
||||
cancellationToken: { throwIfCancellationRequested: noop, isCancellationRequested: returnFalse },
|
||||
newLineCharacter,
|
||||
program,
|
||||
file: sourceFile,
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace ts {
|
||||
function snapFor(path: string): IScriptSnapshot {
|
||||
if (path === "lib.d.ts") {
|
||||
return {
|
||||
dispose() {},
|
||||
dispose: noop,
|
||||
getChangeRange() { return undefined; },
|
||||
getLength() { return 0; },
|
||||
getText(_start, _end) {
|
||||
getText() {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
@@ -16,7 +16,7 @@ namespace ts {
|
||||
const result = forEach(files, f => f.unitName === path ? f : undefined);
|
||||
if (result) {
|
||||
return {
|
||||
dispose() {},
|
||||
dispose: noop,
|
||||
getChangeRange() { return undefined; },
|
||||
getLength() { return result.content.length; },
|
||||
getText(start, end) {
|
||||
|
||||
@@ -85,8 +85,7 @@ namespace ts.projectSystem {
|
||||
assert.equal(this.postExecActions.length, expectedCount, `Expected ${expectedCount} post install actions`);
|
||||
}
|
||||
|
||||
onProjectClosed() {
|
||||
}
|
||||
onProjectClosed = noop;
|
||||
|
||||
attach(projectService: server.ProjectService) {
|
||||
this.projectService = projectService;
|
||||
@@ -4717,7 +4716,7 @@ namespace ts.projectSystem {
|
||||
const host = createServerHost([f1, config]);
|
||||
const session = createSession(host, {
|
||||
canUseEvents: true,
|
||||
eventHandler: () => { },
|
||||
eventHandler: noop,
|
||||
cancellationToken
|
||||
});
|
||||
{
|
||||
@@ -4854,7 +4853,7 @@ namespace ts.projectSystem {
|
||||
const host = createServerHost([f1, config]);
|
||||
const session = createSession(host, {
|
||||
canUseEvents: true,
|
||||
eventHandler: () => { },
|
||||
eventHandler: noop,
|
||||
cancellationToken,
|
||||
throttleWaitMilliseconds: 0
|
||||
});
|
||||
|
||||
@@ -1687,8 +1687,7 @@ namespace ts.server {
|
||||
return normalizePath(name);
|
||||
}
|
||||
|
||||
exit() {
|
||||
}
|
||||
exit() { /*overridden*/ }
|
||||
|
||||
private notRequired(): HandlerResponse {
|
||||
return { responseRequired: false };
|
||||
|
||||
@@ -14,6 +14,5 @@ try {
|
||||
const watcher = fs.watch(directoryName, { recursive: true }, () => ({}));
|
||||
watcher.close();
|
||||
}
|
||||
catch (_e) {
|
||||
}
|
||||
catch { /*ignore*/ }
|
||||
process.exit(0);
|
||||
@@ -320,10 +320,9 @@ namespace ts.Completions.PathCompletions {
|
||||
else if (host.getDirectories) {
|
||||
let typeRoots: ReadonlyArray<string>;
|
||||
try {
|
||||
// Wrap in try catch because getEffectiveTypeRoots touches the filesystem
|
||||
typeRoots = getEffectiveTypeRoots(options, host);
|
||||
}
|
||||
catch (e) {}
|
||||
catch { /* Wrap in try catch because getEffectiveTypeRoots touches the filesystem */ }
|
||||
|
||||
if (typeRoots) {
|
||||
for (const root of typeRoots) {
|
||||
@@ -484,7 +483,7 @@ namespace ts.Completions.PathCompletions {
|
||||
try {
|
||||
return directoryProbablyExists(path, host);
|
||||
}
|
||||
catch (e) {}
|
||||
catch { /*ignore*/ }
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -492,7 +491,7 @@ namespace ts.Completions.PathCompletions {
|
||||
try {
|
||||
return toApply && toApply.apply(host, args);
|
||||
}
|
||||
catch (e) {}
|
||||
catch { /*ignore*/ }
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@
|
||||
"no-conditional-assignment": false,
|
||||
"no-console": false,
|
||||
"no-debugger": false,
|
||||
"no-empty": false,
|
||||
"no-empty-interface": false,
|
||||
"no-eval": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
|
||||
Reference in New Issue
Block a user