Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Consider using @typescript-eslint/class-methods-use-this #344

Open
slifty opened this issue Apr 2, 2024 · 1 comment · May be fixed by #358
Open

Consider using @typescript-eslint/class-methods-use-this #344

slifty opened this issue Apr 2, 2024 · 1 comment · May be fixed by #358

Comments

@slifty
Copy link

slifty commented Apr 2, 2024

There is a new @typescript-eslint/class-methods-use-this rule which makes it possible to disable the rule in the case of overrides and interface.

For example, using this (with the updated options) prevents the pesky situation where an abstract class defines some abstract methods which do NOT necessarily use this, but which need to be class methods due to the abstract class definition.

slifty added a commit to slifty/aprilbot that referenced this issue Apr 2, 2024
This boilerplate creates some basic AprilBot functionality for
connecting to slack and handling some basic types of interactions.

I had to create types for the event handlers for now, though I opened an
issue in the Slack sdk in the hopes they might add types [1] to their
events.

This also swaps out the class-methods-use-this lint rule for a smarter
variety, which is probably something that the upstream maintainer should
consider adding as well [2].

[1] slackapi/node-slack-sdk#1768
[2] iamturns/eslint-config-airbnb-typescript#344
Kenneth-Sills added a commit to Kenneth-Sills/eslint-config-airbnb-typescript-original that referenced this issue Aug 5, 2024
By default, this does not deviate in behavior from the original rule.
It does, however, provide users with additional configuration options
to disable errors when `this` is not used in classes that
implement interfaces or methods that explicitly override parent methods.

The configuration we provide has been left at the default, though,
since those rules are arguably over-permissive in the pursuit of not
requiring type information.

Closes iamturns#344.
@Kenneth-Sills Kenneth-Sills linked a pull request Aug 5, 2024 that will close this issue
@Kenneth-Sills
Copy link

Submitted PR #358 to swap the rule over. But the configuration options mentioned are still off by default.

typescript-eslint is doing their best to avoid type information being required where it's not required, but in this case saying that any class implementing an interface no longer needs any method to use this is just a wide net. I'm more amenable to ignoring methods with override, but I'll leave that up to the project maintainer @iamturns.

jrolfs pushed a commit to jrolfs/eslint-config-airbnb-typescript that referenced this issue Aug 16, 2024
By default, this does not deviate in behavior from the original rule.
It does, however, provide users with additional configuration options
to disable errors when `this` is not used in classes that
implement interfaces or methods that explicitly override parent methods.

The configuration we provide has been left at the default, though,
since those rules are arguably over-permissive in the pursuit of not
requiring type information.

Closes iamturns#344.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants