sindresorhus/eslint-plugin-unicorn

Rule proposal: consistent class member order

Open

#1,110 opened on Feb 18, 2021

View on GitHub
 (5 comments) (2 reactions) (0 assignees)JavaScript (5,022 stars) (468 forks)user submission
help wantednew rule

Description

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

Contributor guide