sindresorhus/eslint-plugin-unicorn

Rule proposal: consistent class member order

Open

#1,110 创建于 2021年2月18日

在 GitHub 查看
 (5 评论) (2 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
help wantednew rule

描述

Enforce statements in this order

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
   }
}

贡献者指南