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
[class-methods-use-this] Allow when required by interface #1103
Comments
How come you want to use this rule? As an aside - if you change it from a method to a property ( |
Mostly for testability. Methods that don't use |
Like @BBosman, I also find it strange that my implementations of interface methods get an error on the I wanted to use an interface so that I can plug in behaviour with specific implementation classes. However, these classes don't need |
As with anything in this repo, unless we (the maintainers) have said it's not a good fit, then it's welcome to be PR'd. To me though, it seems like a bit of a code smell, or a linting config smell. I'd lean toward the latter - you're purposely using a coding style which causes a lint rule to fire, so the lint rule is probably a bad fit. |
I think what suggested by @BBosman is actually required.
for both situations, the rule I think ignoring these situations should be the default behavior of this rule but right now is it possible to extend this rule and add options for ignoring interface/inheritance situations?? It's obvious we need it bad! |
I would like to bring up that many OOP paradigms using interfaces or overridden methods will result in methods that don't need access to an instance state, but must be an instance method. A good example would be used in an IoC container. Say the container is expected to have an implementation of a Logger contract. That default implementation could simply send to the console host object which does not require holding a state of any kind on the contract's implementation. If this was replaced with a file logger it would require a state, but not the default. The default case would never use a I would think the default behavior should be to ignore methods that implement an interface method or overridden a base class method. |
This is definitely missed. When using Angular there are many interfaces your components or classes might implement, but it often is not really required to reference Straight from the angular example code:
You don't have the choice to implement this kind of method in a static way even though it never uses |
We have the same issue when using class decorators in StencilJS. Most of the time in this methods we don't use A fix could be either one of these:
|
@bradzacher In the near future Typescript will have support for the |
Related: #52 |
Please don't @ tag maintainers, as it just creates notification spam for the volunteer maintainers. We are a community run project. The volunteer maintainers spend most of their time triaging issues and reviewing PRs. This means that most issues will not progress unless a member of the community steps up and champions it. If this issue is important to you - consider being that champion. |
@bradzacher fair enough that the community can't expect new features to appear out of thin air. But you were active in this discussion and asked questions and objected to answers people made. So since this is still a discussion and the rest of the community can't know who unsubscribed from an issue or not I think it's not wrong to tag people who participated in this issue... |
Repro
I'd like to request a
@typescript/class-methods-use-this
version ofclass-methods-use-this
, which takes interfaces into account. If an interface requires a (public) method to be there, then the rule should allow it, even though it's not actually referencingthis
.Expected Result
This to not flag
class-methods-use-this
.Actual Result
Getting a
class-methods-use-this
violation on thedoSomething
method.Additional Info
If this is impossible to do, I would also be happy with an
allowPublic
setting for that rule, that just skips checking public methods for usage ofthis
.Versions
@typescript-eslint/eslint-plugin
2.4.0
@typescript-eslint/parser
2.4.0
TypeScript
3.6.4
ESLint
6.5.1
node
10.15.0
npm
6.12.0
The text was updated successfully, but these errors were encountered: