Skip to content

Commit

Permalink
Fixed TSPropertySignatures treated as methods & testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrandgirard committed Oct 3, 2023
1 parent 36c8296 commit 89aae10
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/sort-class-members.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ function getMemberInfo(node, sourceCode) {
node.type === 'ClassPrivateProperty' ||
node.type === 'PropertyDefinition' ||
node.type === 'PrivateIdentifier' ||
node.type === 'TSAbstractPropertyDefinition'
node.type === 'TSAbstractPropertyDefinition' ||
node.type === 'TSPropertySignature'
) {
type = 'property';

Expand Down
58 changes: 58 additions & 0 deletions test/rules/sort-class-members.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,27 @@ const typescriptKeywordsOptions = [
},
];

const typescriptInterfaceOptions = [
{
order: ['[properties]', '[accessors]', '[non-accessors]'],
groups: {
accessors: [
{
type: 'method',
kind: 'accessor',
},
],
'non-accessors': [
{
type: 'method',
kind: 'nonAccessor',
},
],
},
sortInterfaces: true,
},
];

ruleTester.run('sort-class-members', rule, {
valid: [
{ code: 'class A {}', options: defaultOptions },
Expand Down Expand Up @@ -1008,6 +1029,43 @@ ruleTester.run('sort-class-members', rule, {
options: typescriptKeywordsOptions,
parser: require.resolve('@typescript-eslint/parser'),
},
// Interface sorting
{
code: 'interface A { get a(); b; }',
output: 'interface A { b; get a(); }',
errors: [
{
message: 'Expected property b to come before getter a.',
type: 'TSPropertySignature',
},
],
options: typescriptInterfaceOptions,
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: 'interface A { a(); b; }',
output: 'interface A { b; a(); }',
errors: [
{
message: 'Expected property b to come before method a.',
type: 'TSPropertySignature',
},
],
options: typescriptInterfaceOptions,
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: 'interface A { a(); get b(); }',
output: 'interface A { get b(); a(); }',
errors: [
{
message: 'Expected getter b to come before method a.',
type: 'TSMethodSignature',
},
],
options: typescriptInterfaceOptions,
parser: require.resolve('@typescript-eslint/parser'),
},
],
});

Expand Down

0 comments on commit 89aae10

Please sign in to comment.