bryanrsmith / eslint-plugin-sort-class-members

An ESLint rule for enforcing consistent ES6 class member order
119 stars 21 forks source link

Support to match methods/properties by keywords instead of name #56

Open fabio-bertone opened 4 years ago

fabio-bertone commented 4 years ago

Currently there are no rules that cover methods used with private, public keywords in TS. I'd like the feature to sort public methods before private methods without having to use underscore as a prefix for private names.

I'm proposing a rule that looks at the keyword used to order properties and methods in a class.

This should pass with the order

[
  "[static-properties]",
  "[static-methods]",
   "[properties]",
   "[private-properties]", //new
   "constructor",
   "[methods]",
   "[private-methods]" //new
]

class Foo {
  public bar = 'Im a public string';
  baz = 'Im also a public string';

  private foobar = 'Im a private string';

  someMethod() { //public }

  public somePublicMethod() { //public }

  private somePrivateMethod() { //private }
}
bryanrsmith commented 4 years ago

No objection here! I don't have bandwidth to add this myself, but I'd be happy to take a PR for it.