Rule proposal: Require declaring class members upfront
See original GitHub issueDeclaring the members upfront as class fields makes code more readable and can prevent typos. We would also allow initializing in the constructor, but I think we should auto-fix to class field as it’s neater.
Inspired by https://github.com/eslint/eslint/issues/11540.
Any suggestions on the rule name?
Fail
class X {
func setName(name) {
this.name = name;
}
func say() {
console.log(this.name);
}
}
Pass
class X {
name;
func setName(name) {
this.name = name;
}
func say() {
console.log(this.name);
}
}
How it would prevent typos:
class X {
name;
func setName(name) {
this.name = name;
}
func say() {
// This would have resulted in `undefined` being printed without this rule.
console.log(this.myName); // ESLint error
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Streamlining the Medicaid, Children's Health Insurance ...
This rulemaking proposes changes to simplify the processes for eligible individuals to enroll and retain eligibility in Medicaid, the Children's ...
Read more >Shortening the Securities Transaction Settlement Cycle
The Commission proposes to require compliance with each of the proposed rules and rule amendments by March 31, 2024. The. Commission solicits ...
Read more >1.3.1 Class Action Litigation Often Requires Large Up-Front ...
Some class actions involve too much work and too many up-front costs to be handled by a small law office alone. For example,...
Read more >SO YOU WANT TO START A LOCAL AUTO CLUB OR ...
Below highlights the basic requirements and benefits of starting a club: Basic Requirements ... the ground rules up front for members.
Read more >Share Class Election Sample Clauses | Law Insider
Should the Selling Group Member wish to customize its Upfront Selling Commission, ... that are required to be signed by the Trustee under...
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
Yes, it’s clear, let’s add this rule.
I’ll add proposal about the member order later, on vacation.
Ah, no. Sorry for being unclear. It’s more like
no-undef
. By “upfront”, I meant that the members must be declared before being used.