Closed AkatQuas closed 2 years ago
Thanks @AkatQuas! I'm away on vacation right now, but will try to get to this next week. Sorry for the delay!
Thank you for working on this @AkatQuas! I believe I've resolved the problem in a backwards-compatible fashion on main. I've also added tests for both current and legacy babel parsers, as well as the typescript parser. The fix is included in eslint-plugin-sort-class-members@1.15.1
. Please let me know how it works for you!
Thanks for the great work!
I found when parsed by '@typescript-eslint/parser', a private property such as private _c = 1;
is parsed to be like the following:
<ref *1> {
type: 'PropertyDefinition',
key: {
type: 'Identifier',
name: '_c',
range: [Array],
loc: [Object],
parent: [Circular *1]
},
value: {
type: 'Literal',
value: 8,
raw: '8',
range: [Array],
loc: [Object],
parent: [Circular *1]
},
computed: false,
static: false,
readonly: undefined,
declare: false,
override: false,
range: [ 195, 210 ],
loc: { start: [Object], end: [Object] },
accessibility: 'private',
parent: {
type: 'ClassBody',
body: [Array],
range: [Array],
loc: [Object],
parent: [Object]
}
}
It doesn't have a key PrivateIdentifier
node, but it has a property accessibility: 'private'
.
So this node is not parsed as a private property. Sadly.
I'm a little confused.
Yes, typescript's private
accessibility modifier is a different feature than ES private fields. There's some discussion in this PR, which was closed due to inactivity: https://github.com/bryanrsmith/eslint-plugin-sort-class-members/pull/68
That makes senes.
The private name, which is prefixed with #
, would be different from the original one if we really test the accessiblity modifier in Typescript.
I would follow a custom convention to name private property or method prefixed with _
to avoid it.
@babel/eslint-parser
has some breaking change in private property between7.16.0+
and7.15.8
.So the
private
condition need some modifications.