Skip to content

Enable @typescript-eslint/space-before-function-paren, @typescript-eslint/no-unused-expressions #36569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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: 11 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/harness/harnessUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Utils {
export function memoize<T extends ts.AnyFunction>(f: T, memoKey: (...anything: any[]) => string): T {
const cache = ts.createMap<any>();

return <any>(function(this: any, ...args: any[]) {
return <any>(function (this: any, ...args: any[]) {
const key = memoKey(...args);
if (cache.has(key)) {
return cache.get(key);
Expand Down Expand Up @@ -395,4 +395,4 @@ namespace Utils {
function isHarness(line: string) {
return /[\\/]src[\\/]harness[\\/]|[\\/]run\.js/.test(line);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/fixSpelling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/services/codefixes/fixStrictClassInitialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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,
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/refactors/generateGetAccessorAndSetAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ 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);
}

function isAcceptedDeclaration(node: Node): node is AcceptedDeclaration {
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 ? (<ClassLikeDeclaration>container).name! : createThis(); // TODO: GH#18217
return isIdentifier(fieldName) ? createPropertyAccess(leftHead, fieldName) : createElementAccess(leftHead, createLiteral(fieldName));
}
Expand Down
6 changes: 3 additions & 3 deletions src/testRunner/externalCompileRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/rwcRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/services/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down