class-methods-use-this rule doesn't consider existence of getters and setters
See original GitHub issueCurrently class-methods-use-this rule is ignoring existence of getters and setters in javascript.
Let’s consider an approach to have proper getter and setter for an object.
// originally bar was a storage engine
let bar;
class Foo {
get bar() {
return bar;
}
set bar(value) {
bar = value;
}
}
After that, eslint was starting to complain that get bar() should use this.
I read the manual which says if method doesn’t use this, it should be a static method. Which doesn’t make much sense for getters, since static getter won’t be executed for instantiated class.
Then, to comply to eslint rule, I’ll need to not use getter or setter and stick to the setBar(), getBar() methods which can be fine, but I think eslint should be wise enough to detect getters special type of functions.
I checked the rule code, and it seems like the isInstanceMethod() function should be changed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
python classes getters and setters static method and class ...
A static method can't access # any of the objects attributes, it's really only included for grouping # related functions to their classes....
Read more >Can datatype redefine getter/setter?
Currently I'm generating Getter and Setter in class generation code but that expands class definition. Is there a way to specify custom datatype...
Read more >Guide to Java Reflection - Baeldung
In this tutorial, we will explore Java reflection, which allows us to inspect and/or modify runtime attributes of classes, interfaces, ...
Read more >11. Methods and @property - Advance Python Tutorials
mehodsEx.py # below x will be used by static method # if we do not define it, ... python methodEx.py method: 14 classmethod:...
Read more >Effective Dart: Design
Use the same name for the same thing, throughout your code. If a precedent already exists outside your API that users are likely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the rule is working as intended, as this is an edge case. I’d say the only possibility here is add an option that allows you to opt out of checking accessor properties.
When extending Errors you want to add a getter for the name and maybe also add some attributes that you do not want to be allowed to be changed at all. So you wouldn’t add a setter for these entries.