Skip to content

Commit 18ad186

Browse files
committed
Fix bug and add tests through helper function
1 parent a7957a1 commit 18ad186

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

lib/rules/prop-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ module.exports = {
862862
try {
863863
// Flow <=0.52 had 3 required TypedParameters of which the second one is the Props.
864864
// Flow >=0.53 has 2 optional TypedParameters of which the first one is the Props.
865-
propsParameterPosition = versionUtil.testFlowVersion(context, 0.53) ? 1 : 0;
865+
propsParameterPosition = versionUtil.testFlowVersion(context, '0.53.0') ? 0 : 1;
866866
} catch (e) {
867867
// In case there is no flow version defined, we can safely assume that when there are 3 Props we are dealing with version <= 0.52
868868
propsParameterPosition = node.superTypeParameters.params.length <= 2 ? 0 : 1;

tests/lib/rules/prop-types.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const settings = {
2828

2929
require('babel-eslint');
3030

31+
function withAndWithoutFlowVersion(flowVersion, test) {
32+
return [test, Object.assign({}, test, {settings: {react: {flowVersion}}})];
33+
}
34+
3135
// ------------------------------------------------------------------------------
3236
// Tests
3337
// ------------------------------------------------------------------------------
@@ -1475,7 +1479,7 @@ ruleTester.run('prop-types', rule, {
14751479
'}'
14761480
].join('\n'),
14771481
parser: 'babel-eslint'
1478-
}, {
1482+
}, ...withAndWithoutFlowVersion('0.52', {
14791483
code: [
14801484
'type Person = {',
14811485
' firstname: string',
@@ -1487,7 +1491,7 @@ ruleTester.run('prop-types', rule, {
14871491
'}'
14881492
].join('\n'),
14891493
parser: 'babel-eslint'
1490-
}, {
1494+
}), ...withAndWithoutFlowVersion('0.52', {
14911495
code: [
14921496
'type Person = {',
14931497
' firstname: string',
@@ -1500,7 +1504,7 @@ ruleTester.run('prop-types', rule, {
15001504
'}'
15011505
].join('\n'),
15021506
parser: 'babel-eslint'
1503-
}, {
1507+
}), ...withAndWithoutFlowVersion('0.52', {
15041508
code: [
15051509
'type Person = {',
15061510
' firstname: string',
@@ -1515,7 +1519,7 @@ ruleTester.run('prop-types', rule, {
15151519
'}'
15161520
].join('\n'),
15171521
parser: 'babel-eslint'
1518-
}, {
1522+
}), ...withAndWithoutFlowVersion('0.52', {
15191523
code: [
15201524
'type Props = {name: {firstname: string;};};',
15211525
'class Hello extends React.Component<void, Props, void> {',
@@ -1525,7 +1529,7 @@ ruleTester.run('prop-types', rule, {
15251529
'}'
15261530
].join('\n'),
15271531
parser: 'babel-eslint'
1528-
}, {
1532+
}), ...withAndWithoutFlowVersion('0.52', {
15291533
code: [
15301534
'import type Props from "fake";',
15311535
'class Hello extends React.Component<void, Props, void> {',
@@ -1535,7 +1539,7 @@ ruleTester.run('prop-types', rule, {
15351539
'}'
15361540
].join('\n'),
15371541
parser: 'babel-eslint'
1538-
}, {
1542+
}), ...withAndWithoutFlowVersion('0.52', {
15391543
code: [
15401544
'type Person = {',
15411545
' firstname: string',
@@ -1547,7 +1551,7 @@ ruleTester.run('prop-types', rule, {
15471551
'}'
15481552
].join('\n'),
15491553
parser: 'babel-eslint'
1550-
}, {
1554+
}), ...withAndWithoutFlowVersion('0.52', {
15511555
code: [
15521556
'type Props = {result?: {ok?: ?string | boolean;}|{ok?: ?number | Array}};',
15531557
'class Hello extends React.Component<void, Props, void> {',
@@ -1557,8 +1561,7 @@ ruleTester.run('prop-types', rule, {
15571561
'}'
15581562
].join('\n'),
15591563
parser: 'babel-eslint'
1560-
},
1561-
{
1564+
}), ...withAndWithoutFlowVersion('0.53', {
15621565
code: `
15631566
type Props = {
15641567
foo: string,
@@ -1571,7 +1574,7 @@ ruleTester.run('prop-types', rule, {
15711574
}
15721575
`,
15731576
parser: 'babel-eslint'
1574-
}, {
1577+
}), ...withAndWithoutFlowVersion('0.53', {
15751578
code: `
15761579
type FancyProps = {
15771580
foo: string,
@@ -1584,7 +1587,7 @@ ruleTester.run('prop-types', rule, {
15841587
}
15851588
`,
15861589
parser: 'babel-eslint'
1587-
},
1590+
}),
15881591
// issue #1288
15891592
`function Foo() {
15901593
const props = {}
@@ -2847,7 +2850,7 @@ ruleTester.run('prop-types', rule, {
28472850
errors: [
28482851
{message: '\'name\' is missing in props validation'}
28492852
]
2850-
}, {
2853+
}, ...withAndWithoutFlowVersion('0.52', {
28512854
code: [
28522855
'type Person = {',
28532856
' firstname: string',
@@ -2865,7 +2868,7 @@ ruleTester.run('prop-types', rule, {
28652868
type: 'Identifier'
28662869
}],
28672870
parser: 'babel-eslint'
2868-
}, {
2871+
}), ...withAndWithoutFlowVersion('0.52', {
28692872
code: [
28702873
'type Person = {',
28712874
' firstname: string',
@@ -2884,7 +2887,7 @@ ruleTester.run('prop-types', rule, {
28842887
type: 'Property'
28852888
}],
28862889
parser: 'babel-eslint'
2887-
}, {
2890+
}), ...withAndWithoutFlowVersion('0.52', {
28882891
code: [
28892892
'type Person = {',
28902893
' firstname: string',
@@ -2905,7 +2908,7 @@ ruleTester.run('prop-types', rule, {
29052908
type: 'Property'
29062909
}],
29072910
parser: 'babel-eslint'
2908-
}, {
2911+
}), ...withAndWithoutFlowVersion('0.52', {
29092912
code: [
29102913
'type Props = {name: {firstname: string;};};',
29112914
'class Hello extends React.Component<void, Props, void> {',
@@ -2921,7 +2924,7 @@ ruleTester.run('prop-types', rule, {
29212924
type: 'Identifier'
29222925
}],
29232926
parser: 'babel-eslint'
2924-
}, {
2927+
}), ...withAndWithoutFlowVersion('0.52', {
29252928
code: [
29262929
'type Props = {result?: {ok: string | boolean;}|{ok: number | Array}};',
29272930
'class Hello extends React.Component<void, Props, void> {',
@@ -2937,7 +2940,7 @@ ruleTester.run('prop-types', rule, {
29372940
type: 'Identifier'
29382941
}],
29392942
parser: 'babel-eslint'
2940-
}, {
2943+
}), ...withAndWithoutFlowVersion('0.52', {
29412944
code: [
29422945
'type Person = {',
29432946
' firstname: string',
@@ -2955,7 +2958,7 @@ ruleTester.run('prop-types', rule, {
29552958
type: 'Identifier'
29562959
}],
29572960
parser: 'babel-eslint'
2958-
}, {
2961+
}), ...withAndWithoutFlowVersion('0.53', {
29592962
code: `
29602963
type Props = {
29612964
foo: string,
@@ -2974,7 +2977,7 @@ ruleTester.run('prop-types', rule, {
29742977
type: 'Identifier'
29752978
}],
29762979
parser: 'babel-eslint'
2977-
}, {
2980+
}), ...withAndWithoutFlowVersion('0.53', {
29782981
code: `
29792982
type FancyProps = {
29802983
foo: string,
@@ -2993,6 +2996,6 @@ ruleTester.run('prop-types', rule, {
29932996
type: 'Identifier'
29942997
}],
29952998
parser: 'babel-eslint'
2996-
}
2999+
})
29973000
]
29983001
});

0 commit comments

Comments
 (0)