Skip to content

finnish doesn't work for functions without an explicit return type #57

@JasonWeinzierl

Description

@JasonWeinzierl

This will get flagged by the finnish rule:

function getNumber(): Observable<number> {
	return of(42);
}

but this will not get flagged:

function getNumber() {
	return of(42);
}

This is likely due to couldReturnType not being able to handle implicit return types.

tsTypeNode = tsNode.type ?? tsNode.body;

If type is null (no explicit return type) and body is a Block instead of something like a CallExpression, then the type checker will not be able to determine the type of tsTypeNode and so couldReturnType will always return false. This is currently impacts the finnish, no-finnish, and no-misused-observables rules.

Implicit return types don't have test coverage in the finnish test suite, so this bug was never discovered (or ignored?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions