Skip to content

Commit 8c31700

Browse files
authored
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
1 parent 7726464 commit 8c31700

13 files changed

+40
-30
lines changed

.eslintrc.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"@typescript-eslint/no-inferrable-types": "error",
2727
"@typescript-eslint/no-misused-new": "error",
2828
"@typescript-eslint/no-this-alias": "error",
29+
30+
"no-unused-expressions": "off",
31+
"@typescript-eslint/no-unused-expressions": ["error", { "allowTernary": true }],
32+
2933
"@typescript-eslint/prefer-for-of": "error",
3034
"@typescript-eslint/prefer-function-type": "error",
3135
"@typescript-eslint/prefer-namespace-keyword": "error",
@@ -36,6 +40,13 @@
3640
"semi": "off",
3741
"@typescript-eslint/semi": "error",
3842

43+
"space-before-function-paren": "off",
44+
"@typescript-eslint/space-before-function-paren": ["error", {
45+
"asyncArrow": "always",
46+
"anonymous": "always",
47+
"named": "never"
48+
}],
49+
3950
"@typescript-eslint/triple-slash-reference": "error",
4051
"@typescript-eslint/type-annotation-spacing": "error",
4152
"@typescript-eslint/unified-signatures": "error",
@@ -97,7 +108,6 @@
97108
"no-trailing-spaces": "error",
98109
"no-undef-init": "error",
99110
"no-unsafe-finally": "error",
100-
"no-unused-expressions": ["error", { "allowTernary": true }],
101111
"no-unused-labels": "error",
102112
"no-var": "error",
103113
"object-shorthand": "error",

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
"@types/through2": "latest",
5555
"@types/travis-fold": "latest",
5656
"@types/xml2js": "^0.4.0",
57-
"@typescript-eslint/eslint-plugin": "2.3.2",
58-
"@typescript-eslint/experimental-utils": "2.3.2",
59-
"@typescript-eslint/parser": "2.3.2",
57+
"@typescript-eslint/eslint-plugin": "2.18.0",
58+
"@typescript-eslint/experimental-utils": "2.18.0",
59+
"@typescript-eslint/parser": "2.18.0",
6060
"async": "latest",
6161
"azure-devops-node-api": "^8.0.0",
6262
"browser-resolve": "^1.11.2",
@@ -65,10 +65,10 @@
6565
"chalk": "latest",
6666
"convert-source-map": "latest",
6767
"del": "5.1.0",
68-
"eslint": "6.5.1",
69-
"eslint-formatter-autolinkable-stylish": "1.0.3",
70-
"eslint-plugin-import": "2.18.2",
71-
"eslint-plugin-jsdoc": "15.9.9",
68+
"eslint": "6.8.0",
69+
"eslint-formatter-autolinkable-stylish": "1.1.1",
70+
"eslint-plugin-import": "2.20.0",
71+
"eslint-plugin-jsdoc": "21.0.0",
7272
"eslint-plugin-no-null": "1.0.2",
7373
"fancy-log": "latest",
7474
"fs-extra": "^6.0.1",

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23216,7 +23216,7 @@ namespace ts {
2321623216
return true;
2321723217
}
2321823218

23219-
function getThisParameterFromNodeContext (node: Node) {
23219+
function getThisParameterFromNodeContext(node: Node) {
2322023220
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
2322123221
return thisContainer && isFunctionLike(thisContainer) ? getThisParameter(thisContainer) : undefined;
2322223222
}

src/compiler/watch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ namespace ts {
360360
const getDefaultLibLocation = memoize(() => getDirectoryPath(normalizePath(system.getExecutingFilePath())));
361361
let host: DirectoryStructureHost = system;
362362
// TODO: `host` is unused!
363-
// eslint-disable-next-line no-unused-expressions
363+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
364364
host;
365365
return {
366366
useCaseSensitiveFileNames: () => system.useCaseSensitiveFileNames,

src/harness/harnessUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace Utils {
5454
export function memoize<T extends ts.AnyFunction>(f: T, memoKey: (...anything: any[]) => string): T {
5555
const cache = ts.createMap<any>();
5656

57-
return <any>(function(this: any, ...args: any[]) {
57+
return <any>(function (this: any, ...args: any[]) {
5858
const key = memoKey(...args);
5959
if (cache.has(key)) {
6060
return cache.get(key);
@@ -395,4 +395,4 @@ namespace Utils {
395395
function isHarness(line: string) {
396396
return /[\\/]src[\\/]harness[\\/]|[\\/]run\.js/.test(line);
397397
}
398-
}
398+
}

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts.codefix {
3333
return Debug.assertDefined(getContainingClass(getTokenAtPosition(sourceFile, pos)), "There should be a containing class");
3434
}
3535

36-
function symbolPointsToNonPrivateMember (symbol: Symbol) {
36+
function symbolPointsToNonPrivateMember(symbol: Symbol) {
3737
return !symbol.valueDeclaration || !(getModifierFlags(symbol.valueDeclaration) & ModifierFlags.Private);
3838
}
3939

@@ -83,7 +83,7 @@ namespace ts.codefix {
8383
}
8484
}
8585

86-
function getHeritageClauseSymbolTable (classDeclaration: ClassLikeDeclaration, checker: TypeChecker): SymbolTable {
86+
function getHeritageClauseSymbolTable(classDeclaration: ClassLikeDeclaration, checker: TypeChecker): SymbolTable {
8787
const heritageClauseNode = getEffectiveBaseTypeNode(classDeclaration);
8888
if (!heritageClauseNode) return createSymbolTable();
8989
const heritageClauseType = checker.getTypeAtLocation(heritageClauseNode) as InterfaceType;

src/services/codefixes/fixSpelling.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace ts.codefix {
9292
return flags;
9393
}
9494

95-
function getResolvedSourceFileFromImportDeclaration (sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined {
95+
function getResolvedSourceFileFromImportDeclaration(sourceFile: SourceFile, context: CodeFixContextBase, importDeclaration: ImportDeclaration): SourceFile | undefined {
9696
if (!importDeclaration || !isStringLiteralLike(importDeclaration.moduleSpecifier)) return undefined;
9797

9898
const resolvedModule = getResolvedModule(sourceFile, importDeclaration.moduleSpecifier.text);

src/services/codefixes/fixStrictClassInitialization.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ namespace ts.codefix {
4747
},
4848
});
4949

50-
function getPropertyDeclaration (sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined {
50+
function getPropertyDeclaration(sourceFile: SourceFile, pos: number): PropertyDeclaration | undefined {
5151
const token = getTokenAtPosition(sourceFile, pos);
5252
return isIdentifier(token) ? cast(token.parent, isPropertyDeclaration) : undefined;
5353
}
5454

55-
function getActionForAddMissingDefiniteAssignmentAssertion (context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
55+
function getActionForAddMissingDefiniteAssignmentAssertion(context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
5656
const changes = textChanges.ChangeTracker.with(context, t => addDefiniteAssignmentAssertion(t, context.sourceFile, propertyDeclaration));
5757
return createCodeFixAction(fixName, changes, [Diagnostics.Add_definite_assignment_assertion_to_property_0, propertyDeclaration.getText()], fixIdAddDefiniteAssignmentAssertions, Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
5858
}
@@ -70,7 +70,7 @@ namespace ts.codefix {
7070
changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property);
7171
}
7272

73-
function getActionForAddMissingUndefinedType (context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
73+
function getActionForAddMissingUndefinedType(context: CodeFixContext, propertyDeclaration: PropertyDeclaration): CodeFixAction {
7474
const changes = textChanges.ChangeTracker.with(context, t => addUndefinedType(t, context.sourceFile, propertyDeclaration));
7575
return createCodeFixAction(fixName, changes, [Diagnostics.Add_undefined_type_to_property_0, propertyDeclaration.name.getText()], fixIdAddUndefinedType, Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
7676
}
@@ -91,7 +91,7 @@ namespace ts.codefix {
9191
return createCodeFixAction(fixName, changes, [Diagnostics.Add_initializer_to_property_0, propertyDeclaration.name.getText()], fixIdAddInitializer, Diagnostics.Add_initializers_to_all_uninitialized_properties);
9292
}
9393

94-
function addInitializer (changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void {
94+
function addInitializer(changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void {
9595
const property = updateProperty(
9696
propertyDeclaration,
9797
propertyDeclaration.decorators,
@@ -108,7 +108,7 @@ namespace ts.codefix {
108108
return getDefaultValueFromType(checker, checker.getTypeFromTypeNode(propertyDeclaration.type!)); // TODO: GH#18217
109109
}
110110

111-
function getDefaultValueFromType (checker: TypeChecker, type: Type): Expression | undefined {
111+
function getDefaultValueFromType(checker: TypeChecker, type: Type): Expression | undefined {
112112
if (type.flags & TypeFlags.BooleanLiteral) {
113113
return (type === checker.getFalseType() || type === checker.getFalseType(/*fresh*/ true)) ? createFalse() : createTrue();
114114
}

src/services/refactors/generateGetAccessorAndSetAccessor.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
8787
return { renameFilename, renameLocation, edits };
8888
}
8989

90-
function isConvertibleName (name: DeclarationName): name is AcceptedNameType {
90+
function isConvertibleName(name: DeclarationName): name is AcceptedNameType {
9191
return isIdentifier(name) || isStringLiteral(name);
9292
}
9393

9494
function isAcceptedDeclaration(node: Node): node is AcceptedDeclaration {
9595
return isParameterPropertyDeclaration(node, node.parent) || isPropertyDeclaration(node) || isPropertyAssignment(node);
9696
}
9797

98-
function createPropertyName (name: string, originalName: AcceptedNameType) {
98+
function createPropertyName(name: string, originalName: AcceptedNameType) {
9999
return isIdentifier(originalName) ? createIdentifier(name) : createLiteral(name);
100100
}
101101

102-
function createAccessorAccessExpression (fieldName: AcceptedNameType, isStatic: boolean, container: ContainerDeclaration) {
102+
function createAccessorAccessExpression(fieldName: AcceptedNameType, isStatic: boolean, container: ContainerDeclaration) {
103103
const leftHead = isStatic ? (<ClassLikeDeclaration>container).name! : createThis(); // TODO: GH#18217
104104
return isIdentifier(fieldName) ? createPropertyAccess(leftHead, fieldName) : createElementAccess(leftHead, createLiteral(fieldName));
105105
}

src/testRunner/externalCompileRunner.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Harness {
3030

3131
// eslint-disable-next-line @typescript-eslint/no-this-alias
3232
const cls = this;
33-
describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) {
33+
describe(`${this.kind()} code samples`, function (this: Mocha.ISuiteCallbackContext) {
3434
this.timeout(600_000); // 10 minutes
3535
for (const test of testList) {
3636
cls.runTest(typeof test === "string" ? test : test.file);
@@ -41,7 +41,7 @@ namespace Harness {
4141
// eslint-disable-next-line @typescript-eslint/no-this-alias
4242
const cls = this;
4343
const timeout = 600_000; // 10 minutes
44-
describe(directoryName, function(this: Mocha.ISuiteCallbackContext) {
44+
describe(directoryName, function (this: Mocha.ISuiteCallbackContext) {
4545
this.timeout(timeout);
4646
const cp: typeof import("child_process") = require("child_process");
4747

@@ -123,7 +123,7 @@ ${stripAbsoluteImportPaths(result.stderr.toString().replace(/\r\n/g, "\n"))}`;
123123

124124
// eslint-disable-next-line @typescript-eslint/no-this-alias
125125
const cls = this;
126-
describe(`${this.kind()} code samples`, function(this: Mocha.ISuiteCallbackContext) {
126+
describe(`${this.kind()} code samples`, function (this: Mocha.ISuiteCallbackContext) {
127127
this.timeout(cls.timeout); // 20 minutes
128128
before(() => {
129129
cls.exec("docker", ["build", ".", "-t", "typescript/typescript"], { cwd: IO.getWorkspaceRoot() }); // cached because workspace is hashed to determine cacheability

src/testRunner/rwcRunner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace RWC {
4747
caseSensitive = false;
4848
});
4949

50-
it("can compile", function(this: Mocha.ITestCallbackContext) {
50+
it("can compile", function (this: Mocha.ITestCallbackContext) {
5151
this.timeout(800_000); // Allow long timeouts for RWC compilations
5252
let opts!: ts.ParsedCommandLine;
5353

@@ -145,7 +145,7 @@ namespace RWC {
145145
});
146146

147147

148-
it("has the expected emitted code", function(this: Mocha.ITestCallbackContext) {
148+
it("has the expected emitted code", function (this: Mocha.ITestCallbackContext) {
149149
this.timeout(100_000); // Allow longer timeouts for RWC js verification
150150
Harness.Baseline.runMultifileBaseline(baseName, "", () => {
151151
return Harness.Compiler.iterateOutputs(compilerResult.js.values());

src/testRunner/unittests/services/languageService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function Component(x: Config): any;`
4646
it("should be able to create a language service which can respond to deinition requests without throwing", () => {
4747
const languageService = createLanguageService();
4848
const definitions = languageService.getDefinitionAtPosition("foo.ts", 160); // 160 is the latter `vueTemplateHtml` position
49-
expect(definitions).to.exist; // eslint-disable-line no-unused-expressions
49+
expect(definitions).to.exist; // eslint-disable-line @typescript-eslint/no-unused-expressions
5050
});
5151

5252
it("getEmitOutput on language service has way to force dts emit", () => {

src/testRunner/unittests/tsserver/session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ namespace ts.server {
343343

344344
session.send = Session.prototype.send;
345345
assert(session.send);
346-
expect(session.send(msg)).to.not.exist; // eslint-disable-line no-unused-expressions
346+
expect(session.send(msg)).to.not.exist; // eslint-disable-line @typescript-eslint/no-unused-expressions
347347
expect(lastWrittenToHost).to.equal(resultMsg);
348348
});
349349
});

0 commit comments

Comments
 (0)