Skip to content

Commit c984b4f

Browse files
committed
chore: allow babel in tc
1 parent f7447b7 commit c984b4f

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/rules/sort-prop-types.js

+23
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ module.exports = {
7272
const typeAnnotations = new Map();
7373

7474
function getKey(node) {
75+
if (node.type === 'ObjectTypeProperty') {
76+
return context.getSourceCode().getFirstToken(node).value;
77+
}
7578
if (node.key && node.key.value) {
7679
return node.key.value;
7780
}
@@ -236,6 +239,16 @@ module.exports = {
236239
if (firstArg.members) {
237240
checkSorted(firstArg.members);
238241
}
242+
} else if (firstArg && firstArg.type === 'GenericTypeAnnotation') {
243+
const propType = typeAnnotations.get(firstArg.id.name)
244+
&& typeAnnotations.get(firstArg.id.name)[0];
245+
if (propType && propType.properties) {
246+
checkSorted(propType.properties);
247+
}
248+
} else if (firstArg && firstArg.type === 'ObjectTypeAnnotation') {
249+
if (firstArg.properties) {
250+
checkSorted(firstArg.properties);
251+
}
239252
}
240253
}
241254

@@ -296,6 +309,16 @@ module.exports = {
296309
}
297310
},
298311

312+
TypeAlias(node) {
313+
if (node.right.type === 'ObjectTypeAnnotation') {
314+
const currentNode = [].concat(
315+
typeAnnotations.get(node.id.name) || [],
316+
node.right
317+
);
318+
typeAnnotations.set(node.id.name, currentNode);
319+
}
320+
},
321+
299322
TSTypeAliasDeclaration(node) {
300323
if (node.typeAnnotation.type === 'TSTypeLiteral' || node.typeAnnotation.type === 'ObjectTypeAnnotation') {
301324
const currentNode = [].concat(

tests/lib/rules/sort-prop-types.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -2283,14 +2283,13 @@ ruleTester.run('sort-prop-types', rule, {
22832283
return null;
22842284
}
22852285
`,
2286-
features: ['ts', 'no-babel'],
2286+
features: ['types'],
22872287
options: [{ checkTypes: true }],
22882288
errors: [
22892289
{
22902290
messageId: 'propsNotSorted',
22912291
line: 4,
22922292
column: 11,
2293-
type: 'TSPropertySignature',
22942293
},
22952294
],
22962295
},
@@ -2313,14 +2312,13 @@ ruleTester.run('sort-prop-types', rule, {
23132312
return null;
23142313
}
23152314
`,
2316-
features: ['ts', 'no-babel'],
2315+
features: ['types'],
23172316
options: [{ checkTypes: true }],
23182317
errors: [
23192318
{
23202319
messageId: 'propsNotSorted',
23212320
line: 4,
23222321
column: 11,
2323-
type: 'TSPropertySignature',
23242322
},
23252323
],
23262324
},
@@ -2341,14 +2339,13 @@ ruleTester.run('sort-prop-types', rule, {
23412339
return null;
23422340
}
23432341
`,
2344-
features: ['ts', 'no-babel'],
2342+
features: ['types'],
23452343
options: [{ checkTypes: true }],
23462344
errors: [
23472345
{
23482346
messageId: 'propsNotSorted',
23492347
line: 4,
23502348
column: 11,
2351-
type: 'TSPropertySignature',
23522349
},
23532350
],
23542351
}

0 commit comments

Comments
 (0)