Reputation: 2977
I'm trying to have a strict ordering in typescript classes, forcing a precise order for groups and especially I'd like to force alphabetic order.
I'm following this doc to achieve what I need: https://typescript-eslint-armano.netlify.app/rules/member-ordering/#sorting-alphabetically-within-member-groups
This is the member-ordering config extracted by my .eslintrc config
"@typescript-eslint/member-ordering": [
"error",
{
"default": {
"memberTypes": [
"public-static-field",
"protected-static-field",
"private-static-field",
"public-instance-field",
"public-decorated-field",
"public-abstract-field",
"protected-instance-field",
"protected-decorated-field",
"protected-abstract-field",
"private-instance-field",
"private-decorated-field",
"private-abstract-field",
"static-field",
"public-field",
"instance-field",
"protected-field",
"private-field",
"abstract-field",
"constructor",
"public-static-method",
"protected-static-method",
"private-static-method",
"public-method",
"protected-method",
"private-method"
],
"order": "alphabetically"
}
}
],
This doesn't produce any errors in my class, whereas I would expect 2 errors: wrong member ordering (private should go after public) and wrong alphabetic order.
Eslint is running fine, since I'm getting other errors, such as naming-convention and others
Upvotes: 8
Views: 11273
Reputation: 1
Try this list as per https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/member-ordering.md#default-configuration:
// Index signature
"signature",
"call-signature",
// Fields
"public-static-field",
"protected-static-field",
"private-static-field",
"#private-static-field",
"public-decorated-field",
"protected-decorated-field",
"private-decorated-field",
"public-instance-field",
"protected-instance-field",
"private-instance-field",
"#private-instance-field",
"public-abstract-field",
"protected-abstract-field",
"public-field",
"protected-field",
"private-field",
"#private-field",
"static-field",
"instance-field",
"abstract-field",
"decorated-field",
"field",
// Static initialization
"static-initialization",
// Constructors
"public-constructor",
"protected-constructor",
"private-constructor",
"constructor",
// Getters
"public-static-get",
"protected-static-get",
"private-static-get",
"#private-static-get",
"public-decorated-get",
"protected-decorated-get",
"private-decorated-get",
"public-instance-get",
"protected-instance-get",
"private-instance-get",
"#private-instance-get",
"public-abstract-get",
"protected-abstract-get",
"public-get",
"protected-get",
"private-get",
"#private-get",
"static-get",
"instance-get",
"abstract-get",
"decorated-get",
"get",
// Setters
"public-static-set",
"protected-static-set",
"private-static-set",
"#private-static-set",
"public-decorated-set",
"protected-decorated-set",
"private-decorated-set",
"public-instance-set",
"protected-instance-set",
"private-instance-set",
"#private-instance-set",
"public-abstract-set",
"protected-abstract-set",
"public-set",
"protected-set",
"private-set",
"#private-set",
"static-set",
"instance-set",
"abstract-set",
"decorated-set",
"set",
// Methods
"public-static-method",
"protected-static-method",
"private-static-method",
"#private-static-method",
"public-decorated-method",
"protected-decorated-method",
"private-decorated-method",
"public-instance-method",
"protected-instance-method",
"private-instance-method",
"#private-instance-method",
"public-abstract-method",
"protected-abstract-method",
"public-method",
"protected-method",
"private-method",
"#private-method",
"static-method",
"instance-method",
"abstract-method",
"decorated-method",
"method"
Upvotes: -3
Reputation: 2977
It appears that separating memberTypes
and ordering
in two categories, works.
It appeared to me that the docs put the two props together, but maybe it's a bug.
And in my editor:
Upvotes: 6