Open RuiGau opened 6 years ago
If you handle accessor-pairs
separately, then they won't be matched by your conventional-public-non-static-nor-accessor-nor-constructor-methods
groups. I tested with this configuration:
'sort-class-members/sort-class-members': [
2,
{
accessorPairPositioning: 'getThenSet',
groups: {
'accessor-pairs': [
{ accessorPair: true },
],
methods: [
{
sort: 'alphabetical',
type: 'method',
},
],
properties: [
{
sort: 'alphabetical',
type: 'property',
},
],
'static-methods': [
{
sort: 'alphabetical',
static: true,
type: 'method',
},
],
'static-properties': [
{
sort: 'alphabetical',
static: true,
type: 'property',
},
],
},
order: [
'[static-properties]',
'[static-methods]',
'[properties]',
'constructor',
'[accessor-pairs]',
'[methods]',
],
},
],
and this class:
export abstract class Foo<T> {
protected abstract readonly _foo: T;
public readonly bar: string;
public readonly baz: string;
protected constructor(bar: string) {
this.bar = bar;
this.baz = bar.trim();
}
protected abstract parse(baz?: string): T;
protected abstract stringify(): string;
public abstract get zebra(): Foo<T>['_foo'];
public abstract set zebra(value: T);
}
and you can see from my screenshot that even though zebra()
would be fine alphabetically, there's an error because getters/setters should be above methods.
Firstly, thanks for the awesome plugin 👍 .
My goal
I would like to sort public not static not constructor not accessor methods alphabetically in ES6 classes.
What I tried
How can I match methods that are not accessors in "groups" ?
I would like to set a configuration like that
to place this slot like that
But this only matches public non static non constructor methods, it still matches getters and setters.
Can i create such a group ? Or maybe I'm doing it wrong and there's a simpler way I don't find ?