sindresorhus/eslint-plugin-unicorn
在 GitHub 查看Rule proposal: consistent class member order
Open
#1,110 创建于 2021年2月18日
help wantednew rule
描述
Enforce statements in this order
- Private field
- Public field
- Static field
- constructor
- Private method
- Public method
- Static method
- Static block(https://github.com/tc39/proposal-class-static-block)
Originally posted by @fisker in https://github.com/sindresorhus/eslint-plugin-unicorn/issues/990#issuecomment-753474656
Can you open a separate issue for the class member order rule idea? Similar rule for TS: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md
Originally posted by @sindresorhus in https://github.com/sindresorhus/eslint-plugin-unicorn/issues/990#issuecomment-755267134
Rule name class-body-order is the original idea, I'm open to better suggestions.
Fail
Cases not in order as example in Pass.
Pass
class Unicorn {
#privateField = 1;
publicField= 1;
static staticField = 1;
constructor() {}
#privateMethod() {}
publicMethod() {}
static staticMethod() {}
static {
// static block
}
}