From 8c31700735832e96aee81ebc8d2953818bcd5096 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Wed, 5 Feb 2020 00:43:25 +0200 Subject: [PATCH] Enable @typescript-eslint/space-before-function-paren, @typescript-eslint/no-unused-expressions (#36569) * use @typescript-eslint/no-unused-expressions instead of no-unused-expressions * enable @typescript-eslint/space-before-function-paren --- .eslintrc.json | 12 +++++++++++- package.json | 14 +++++++------- src/compiler/checker.ts | 2 +- src/compiler/watch.ts | 2 +- src/harness/harnessUtils.ts | 4 ++-- .../fixClassIncorrectlyImplementsInterface.ts | 4 ++-- src/services/codefixes/fixSpelling.ts | 2 +- .../codefixes/fixStrictClassInitialization.ts | 10 +++++----- .../refactors/generateGetAccessorAndSetAccessor.ts | 6 +++--- src/testRunner/externalCompileRunner.ts | 6 +++--- src/testRunner/rwcRunner.ts | 4 ++-- .../unittests/services/languageService.ts | 2 +- src/testRunner/unittests/tsserver/session.ts | 2 +- 13 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6eb16b973f2..2a8eba04bcf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -26,6 +26,10 @@ "@typescript-eslint/no-inferrable-types": "error", "@typescript-eslint/no-misused-new": "error", "@typescript-eslint/no-this-alias": "error", + + "no-unused-expressions": "off", + "@typescript-eslint/no-unused-expressions": ["error", { "allowTernary": true }], + "@typescript-eslint/prefer-for-of": "error", "@typescript-eslint/prefer-function-type": "error", "@typescript-eslint/prefer-namespace-keyword": "error", @@ -36,6 +40,13 @@ "semi": "off", "@typescript-eslint/semi": "error", + "space-before-function-paren": "off", + "@typescript-eslint/space-before-function-paren": ["error", { + "asyncArrow": "always", + "anonymous": "always", + "named": "never" + }], + "@typescript-eslint/triple-slash-reference": "error", "@typescript-eslint/type-annotation-spacing": "error", "@typescript-eslint/unified-signatures": "error", @@ -97,7 +108,6 @@ "no-trailing-spaces": "error", "no-undef-init": "error", "no-unsafe-finally": "error", - "no-unused-expressions": ["error", { "allowTernary": true }], "no-unused-labels": "error", "no-var": "error", "object-shorthand": "error", diff --git a/package.json b/package.json index 80fc7f1fefb..5777c3c17fe 100644 --- a/package.json +++ b/package.json @@ -54,9 +54,9 @@ "@types/through2": "latest", "@types/travis-fold": "latest", "@types/xml2js": "^0.4.0", - "@typescript-eslint/eslint-plugin": "2.3.2", - "@typescript-eslint/experimental-utils": "2.3.2", - "@typescript-eslint/parser": "2.3.2", + "@typescript-eslint/eslint-plugin": "2.18.0", + "@typescript-eslint/experimental-utils": "2.18.0", + "@typescript-eslint/parser": "2.18.0", "async": "latest", "azure-devops-node-api": "^8.0.0", "browser-resolve": "^1.11.2", @@ -65,10 +65,10 @@ "chalk": "latest", "convert-source-map": "latest", "del": "5.1.0", - "eslint": "6.5.1", - "eslint-formatter-autolinkable-stylish": "1.0.3", - "eslint-plugin-import": "2.18.2", - "eslint-plugin-jsdoc": "15.9.9", + "eslint": "6.8.0", + "eslint-formatter-autolinkable-stylish": "1.1.1", + "eslint-plugin-import": "2.20.0", + "eslint-plugin-jsdoc": "21.0.0", "eslint-plugin-no-null": "1.0.2", "fancy-log": "latest", "fs-extra": "^6.0.1", diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ad3f3b71f29..f50ee294fe7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23216,7 +23216,7 @@ namespace ts { return true; } - function getThisParameterFromNodeContext (node: Node) { + function getThisParameterFromNodeContext(node: Node) { const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false); return thisContainer && isFunctionLike(thisContainer) ? getThisParameter(thisContainer) : undefined; } diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 40669728984..16c72126092 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -360,7 +360,7 @@ namespace ts { const getDefaultLibLocation = memoize(() => getDirectoryPath(normalizePath(system.getExecutingFilePath()))); let host: DirectoryStructureHost = system; // TODO: `host` is unused! - // eslint-disable-next-line no-unused-expressions + // eslint-disable-next-line @typescript-eslint/no-unused-expressions host; return { useCaseSensitiveFileNames: () => system.useCaseSensitiveFileNames, diff --git a/src/harness/harnessUtils.ts b/src/harness/harnessUtils.ts index a51cba0b7b9..23c715a58e2 100644 --- a/src/harness/harnessUtils.ts +++ b/src/harness/harnessUtils.ts @@ -54,7 +54,7 @@ namespace Utils { export function memoize(f: T, memoKey: (...anything: any[]) => string): T { const cache = ts.createMap(); - return (function(this: any, ...args: any[]) { + return (function (this: any, ...args: any[]) { const key = memoKey(...args); if (cache.has(key)) { return cache.get(key); @@ -395,4 +395,4 @@ namespace Utils { function isHarness(line: string) { return /[\\/]src[\\/]harness[\\/]|[\\/]run\.js/.test(line); } -} \ No newline at end of file +} diff --git a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts index 0735e85bc70..874a8b443bf 100644 --- a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts +++ b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts @@ -33,7 +33,7 @@ namespace ts.codefix { return Debug.assertDefined(getContainingClass(getTokenAtPosition(sourceFile, pos)), "There should be a containing class"); } - function symbolPointsToNonPrivateMember (symbol: Symbol) { + function symbolPointsToNonPrivateMember(symbol: Symbol) { return !symbol.valueDeclaration || !(getModifierFlags(symbol.valueDeclaration) & ModifierFlags.Private); } @@ -83,7 +83,7 @@ namespace ts.codefix { } } - function getHeritageClauseSymbolTable (classDeclaration: ClassLikeDeclaration, checker: TypeChecker): SymbolTable { + function getHeritageClauseSymbolTable(classDeclaration: ClassLikeDeclaration, checker: TypeChecker): SymbolTable { const heritageClauseNode = getEffectiveBaseTypeNode(classDeclaration); if (!heritageClauseNode) return createSymbolTable(); const heritageClauseType = checker.getTypeAtLocation(heritageClauseNode) as InterfaceType; diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index 037f00462c0..637f7751e6b 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -92,7 +92,7 @@ namespace ts.codefix { return flags; } - function getResolvedSourceFileFromImportDeclaration (sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined { + function getResolvedSourceFileFromImportDeclaration(sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined { if (!importDeclaration || !isStringLiteralLike(importDeclaration.moduleSpecifier)) return undefined; const resolvedModule = getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text); diff --git a/src/services/codefixes/fixStrictClassInitialization.ts b/src/services/codefixes/fixStrictClassInitialization.ts index 15c57c604dd..f3286246e16 100644 --- a/src/services/codefixes/fixStrictClassInitialization.ts +++ b/src/services/codefixes/fixStrictClassInitialization.ts @@ -47,12 +47,12 @@ namespace ts.codefix { }, }); - function getPropertyDeclaration (sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined { + function getPropertyDeclaration(sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined { const token = getTokenAtPosition(sourceFile, pos); return isIdentifier(token) ? cast(token.parent, isPropertyDeclaration) : undefined; } - function getActionForAddMissingDefiniteAssignmentAssertion (context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction { + function getActionForAddMissingDefiniteAssignmentAssertion(context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction { const changes = textChanges.ChangeTracker.with(context, t => addDefiniteAssignmentAssertion(t, context.sourceFile, propertyDeclaration)); return createCodeFixAction(fixName, changes, [Diagnostics.Add_definite_assignment_assertion_to_property_0, propertyDeclaration.getText()], fixIdAddDefiniteAssignmentAssertions, Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties); } @@ -70,7 +70,7 @@ namespace ts.codefix { changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property); } - function getActionForAddMissingUndefinedType (context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction { + function getActionForAddMissingUndefinedType(context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction { const changes = textChanges.ChangeTracker.with(context, t => addUndefinedType(t, context.sourceFile, propertyDeclaration)); return createCodeFixAction(fixName, changes, [Diagnostics.Add_undefined_type_to_property_0, propertyDeclaration.name.getText()], fixIdAddUndefinedType, Diagnostics.Add_undefined_type_to_all_uninitialized_properties); } @@ -91,7 +91,7 @@ namespace ts.codefix { return createCodeFixAction(fixName, changes, [Diagnostics.Add_initializer_to_property_0, propertyDeclaration.name.getText()], fixIdAddInitializer, Diagnostics.Add_initializers_to_all_uninitialized_properties); } - function addInitializer (changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void { + function addInitializer(changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void { const property = updateProperty( propertyDeclaration, propertyDeclaration.decorators, @@ -108,7 +108,7 @@ namespace ts.codefix { return getDefaultValueFromType(checker, checker.getTypeFromTypeNode(propertyDeclaration.type!)); // TODO: GH#18217 } - function getDefaultValueFromType (checker: TypeChecker, type: Type): Expression | undefined { + function getDefaultValueFromType(checker: TypeChecker, type: Type): Expression | undefined { if (type.flags & TypeFlags.BooleanLiteral) { return (type === checker.getFalseType() || type === checker.getFalseType(/*fresh*/ true)) ? createFalse() : createTrue(); } diff --git a/src/services/refactors/generateGetAccessorAndSetAccessor.ts b/src/services/refactors/generateGetAccessorAndSetAccessor.ts index a1bd32b37fc..3a00f528bef 100644 --- a/src/services/refactors/generateGetAccessorAndSetAccessor.ts +++ b/src/services/refactors/generateGetAccessorAndSetAccessor.ts @@ -87,7 +87,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { return { renameFilename, renameLocation, edits }; } - function isConvertibleName (name: DeclarationName): name is AcceptedNameType { + function isConvertibleName(name: DeclarationName): name is AcceptedNameType { return isIdentifier(name) || isStringLiteral(name); } @@ -95,11 +95,11 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { return isParameterPropertyDeclaration(node, node.parent) || isPropertyDeclaration(node) || isPropertyAssignment(node); } - function createPropertyName (name: string, originalName: AcceptedNameType) { + function createPropertyName(name: string, originalName: AcceptedNameType) { return isIdentifier(originalName) ? createIdentifier(name) : createLiteral(name); } - function createAccessorAccessExpression (fieldName: AcceptedNameType, isStatic: boolean, container: ContainerDeclaration) { + function createAccessorAccessExpression(fieldName: AcceptedNameType, isStatic: boolean, container: ContainerDeclaration) { const leftHead = isStatic ? (container).name! : createThis(); // TODO: GH#18217 return isIdentifier(fieldName) ? createPropertyAccess(leftHead, fieldName) : createElementAccess(leftHead, createLiteral(fieldName)); } diff --git a/src/testRunner/externalCompileRunner.ts b/src/testRunner/externalCompileRunner.ts index bda806f3156..e42a9bc42cc 100644 --- a/src/testRunner/externalCompileRunner.ts +++ b/src/testRunner/externalCompileRunner.ts @@ -30,7 +30,7 @@ namespace Harness { // eslint-disable-next-line @typescript-eslint/no-this-alias const cls = this; - describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) { + describe(`${this.kind()} code samples`, function (this: Mocha.ISuiteCallbackContext) { this.timeout(600_000); // 10 minutes for (const test of testList) { cls.runTest(typeof test === "string" ? test : test.file); @@ -41,7 +41,7 @@ namespace Harness { // eslint-disable-next-line @typescript-eslint/no-this-alias const cls = this; const timeout = 600_000; // 10 minutes - describe(directoryName, function(this: Mocha.ISuiteCallbackContext) { + describe(directoryName, function (this: Mocha.ISuiteCallbackContext) { this.timeout(timeout); const cp: typeof import("child_process") = require("child_process"); @@ -123,7 +123,7 @@ ${stripAbsoluteImportPaths(result.stderr.toString().replace(/\r\n/g, "\n"))}`; // eslint-disable-next-line @typescript-eslint/no-this-alias const cls = this; - describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) { + describe(`${this.kind()} code samples`, function (this: Mocha.ISuiteCallbackContext) { this.timeout(cls.timeout); // 20 minutes before(() => { cls.exec("docker", ["build", ".", "-t", "typescript/typescript"], { cwd: IO.getWorkspaceRoot() }); // cached because workspace is hashed to determine cacheability diff --git a/src/testRunner/rwcRunner.ts b/src/testRunner/rwcRunner.ts index 0a3e0e090b7..a50447b2d00 100644 --- a/src/testRunner/rwcRunner.ts +++ b/src/testRunner/rwcRunner.ts @@ -47,7 +47,7 @@ namespace RWC { caseSensitive = false; }); - it("can compile", function(this: Mocha.ITestCallbackContext) { + it("can compile", function (this: Mocha.ITestCallbackContext) { this.timeout(800_000); // Allow long timeouts for RWC compilations let opts!: ts.ParsedCommandLine; @@ -145,7 +145,7 @@ namespace RWC { }); - it("has the expected emitted code", function(this: Mocha.ITestCallbackContext) { + it("has the expected emitted code", function (this: Mocha.ITestCallbackContext) { this.timeout(100_000); // Allow longer timeouts for RWC js verification Harness.Baseline.runMultifileBaseline(baseName, "", () => { return Harness.Compiler.iterateOutputs(compilerResult.js.values()); diff --git a/src/testRunner/unittests/services/languageService.ts b/src/testRunner/unittests/services/languageService.ts index 557ed9370c1..48e35916de4 100644 --- a/src/testRunner/unittests/services/languageService.ts +++ b/src/testRunner/unittests/services/languageService.ts @@ -46,7 +46,7 @@ export function Component(x: Config): any;` it("should be able to create a language service which can respond to deinition requests without throwing", () => { const languageService = createLanguageService(); const definitions = languageService.getDefinitionAtPosition("foo.ts", 160); // 160 is the latter `vueTemplateHtml` position - expect(definitions).to.exist; // eslint-disable-line no-unused-expressions + expect(definitions).to.exist; // eslint-disable-line @typescript-eslint/no-unused-expressions }); it("getEmitOutput on language service has way to force dts emit", () => { diff --git a/src/testRunner/unittests/tsserver/session.ts b/src/testRunner/unittests/tsserver/session.ts index 258ac29d26f..b41df99f4a2 100644 --- a/src/testRunner/unittests/tsserver/session.ts +++ b/src/testRunner/unittests/tsserver/session.ts @@ -343,7 +343,7 @@ namespace ts.server { session.send = Session.prototype.send; assert(session.send); - expect(session.send(msg)).to.not.exist; // eslint-disable-line no-unused-expressions + expect(session.send(msg)).to.not.exist; // eslint-disable-line @typescript-eslint/no-unused-expressions expect(lastWrittenToHost).to.equal(resultMsg); }); });