Skip to content

Commit 5955ae9

Browse files
committed
chore: keep TS typed prop sorting check behind an option
1 parent 1519630 commit 5955ae9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/rules/sort-prop-types.js

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ module.exports = {
5252
sortShapeProp: {
5353
type: 'boolean',
5454
},
55+
allowTypescript: {
56+
type: 'boolean',
57+
},
5558
},
5659
additionalProperties: false,
5760
}],
@@ -64,6 +67,7 @@ module.exports = {
6467
const ignoreCase = configuration.ignoreCase || false;
6568
const noSortAlphabetically = configuration.noSortAlphabetically || false;
6669
const sortShapeProp = configuration.sortShapeProp || false;
70+
const allowTypescript = configuration.allowTypescript || false;
6771

6872
const typeAnnotations = new Map();
6973

@@ -218,6 +222,9 @@ module.exports = {
218222
}
219223

220224
function handleFunctionComponent(node) {
225+
if (!allowTypescript) {
226+
return;
227+
}
221228
const firstArg = node.params[0].typeAnnotation && node.params[0].typeAnnotation.typeAnnotation;
222229
if (firstArg && firstArg.type === 'TSTypeReference') {
223230
const propType = typeAnnotations.get(firstArg.typeName.name)

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

+16
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,19 @@ ruleTester.run('sort-prop-types', rule, {
480480
});
481481
`,
482482
options: [{ callbacksLast: true, noSortAlphabetically: true }],
483+
},
484+
{
485+
code: `
486+
type Props = {
487+
zzz: string;
488+
aaa: string;
489+
}
490+
function Foo(props: Props) {
491+
return null;
492+
}
493+
`,
494+
features: ['ts', 'no-babel'],
495+
options: [{ allowTypescript: false }],
483496
}
484497
)),
485498
invalid: parsers.all([].concat(
@@ -2271,6 +2284,7 @@ ruleTester.run('sort-prop-types', rule, {
22712284
}
22722285
`,
22732286
features: ['ts', 'no-babel'],
2287+
options: [{ allowTypescript: true }],
22742288
errors: [
22752289
{
22762290
messageId: 'propsNotSorted',
@@ -2300,6 +2314,7 @@ ruleTester.run('sort-prop-types', rule, {
23002314
}
23012315
`,
23022316
features: ['ts', 'no-babel'],
2317+
options: [{ allowTypescript: true }],
23032318
errors: [
23042319
{
23052320
messageId: 'propsNotSorted',
@@ -2327,6 +2342,7 @@ ruleTester.run('sort-prop-types', rule, {
23272342
}
23282343
`,
23292344
features: ['ts', 'no-babel'],
2345+
options: [{ allowTypescript: true }],
23302346
errors: [
23312347
{
23322348
messageId: 'propsNotSorted',

0 commit comments

Comments
 (0)