Skip to content

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Aug 28, 2024

Enables the allowExpressions config option of the ESLint rule @typescript-eslint/explicit-function-return-type. See rule documentation here. This has the following effect:

// These were already allowed
node.addEventListener('click', () => undefined);

node.addEventListener('click', function () {});

const foo = arr.map(i => i * i);

// Newly allowed
const obj = {
  foo: (bar: string) => bar,
}

// Still forbidden
const fn = (bar: string) => bar;

This is motivated because this rule was disabled here in #37, and I think the rule is excessive in such cases.

Incidentally, removes an // eslint-disable directive by replacing an empty function () => {} with () => undefined.

@rekmarks rekmarks requested a review from a team as a code owner August 28, 2024 16:06
@rekmarks rekmarks force-pushed the rekm/update-explicit-function-return-type branch from 87554b1 to 6d8af58 Compare August 28, 2024 16:07
@rekmarks rekmarks force-pushed the rekm/update-explicit-function-return-type branch from 6d8af58 to ba0717b Compare August 28, 2024 16:10
@rekmarks rekmarks enabled auto-merge (squash) August 28, 2024 16:12
Comment on lines +16 to +18
teardown(): void {
return undefined;
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rekmarks This is not a blocker, just curiosity about the reasons for this?

As far as the runtime is concerned, they are equivalent, as long as the runtime is optimizing for no-op returning undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should prefer code of equivalent behavior and complexity over lint exceptions when possible. Lint rules exist for a reason, and the more exceptions we add, the more we compromise the stylistic and behavioral patterns we want to enforce with our lint rules. Lint exceptions should therefore only be used when necessary.

Copy link
Contributor

@SMotaal SMotaal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rekmarks rekmarks merged commit 3a91315 into main Aug 28, 2024
@rekmarks rekmarks deleted the rekm/update-explicit-function-return-type branch August 28, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants