Skip to content

Commit c893316

Browse files
author
Moroine Bentefrit
committed
Add test for issue #2138
1 parent 1725ee2 commit c893316

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/lib/rules/no-unused-prop-types.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,6 +4619,29 @@ ruleTester.run('no-unused-prop-types', rule, {
46194619
errors: [{
46204620
message: '\'aProp\' PropType is defined but prop is never used'
46214621
}]
4622+
}, {
4623+
// issue #2138
4624+
code: `
4625+
type UsedProps = {|
4626+
usedProp: number,
4627+
|};
4628+
4629+
type UnusedProps = {|
4630+
unusedProp: number,
4631+
|};
4632+
4633+
type Props = {| ...UsedProps, ...UnusedProps |};
4634+
4635+
function MyComponent({ usedProp, notOne }: Props) {
4636+
return <div>{usedProp}</div>;
4637+
}
4638+
`,
4639+
parser: parsers.BABEL_ESLINT,
4640+
errors: [{
4641+
message: "'unusedProp' PropType is defined but prop is never used",
4642+
line: 7,
4643+
column: 19
4644+
}]
46224645
}, {
46234646
code: `
46244647
type Props = {

tests/lib/rules/prop-types.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,30 @@ ruleTester.run('prop-types', rule, {
23542354
`,
23552355
parser: parsers.BABEL_ESLINT
23562356
},
2357+
{
2358+
// issue #2138
2359+
code: `
2360+
type UsedProps = {|
2361+
usedProp: number,
2362+
|};
2363+
2364+
type UnusedProps = {|
2365+
unusedProp: number,
2366+
|};
2367+
2368+
type Props = {| ...UsedProps, ...UnusedProps |};
2369+
2370+
function MyComponent({ usedProp }: Props) {
2371+
return <div>{usedProp}</div>;
2372+
}
2373+
`,
2374+
parser: parsers.BABEL_ESLINT,
2375+
errors: [{
2376+
message: "'notOne' is missing in props validation",
2377+
line: 8,
2378+
column: 34
2379+
}]
2380+
},
23572381
{
23582382
// issue #1259
23592383
code: `
@@ -4747,6 +4771,30 @@ ruleTester.run('prop-types', rule, {
47474771
message: '\'initialValues\' is missing in props validation'
47484772
}]
47494773
},
4774+
{
4775+
// issue #2138
4776+
code: `
4777+
type UsedProps = {|
4778+
usedProp: number,
4779+
|};
4780+
4781+
type UnusedProps = {|
4782+
unusedProp: number,
4783+
|};
4784+
4785+
type Props = {| ...UsedProps, ...UnusedProps |};
4786+
4787+
function MyComponent({ usedProp, notOne }: Props) {
4788+
return <div>{usedProp}</div>;
4789+
}
4790+
`,
4791+
parser: parsers.BABEL_ESLINT,
4792+
errors: [{
4793+
message: "'notOne' is missing in props validation",
4794+
line: 8,
4795+
column: 34
4796+
}]
4797+
},
47504798
{
47514799
// issue #2298
47524800
code: `

0 commit comments

Comments
 (0)