Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc29d3d

Browse files
armano2michalsnik
authored andcommitted
Fix #560 Allow null in require-prop-type-constructor (#578)
* Fix #560 Allow null in require-prop-type-constructor * Add missing check for `{ type: null }`
1 parent ce7cb10 commit bc29d3d

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

‎lib/rules/require-prop-type-constructor.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const forbiddenTypes = [
1919
'UpdateExpression'
2020
]
2121

22-
const isForbiddenType = nodeType => forbiddenTypes.indexOf(nodeType) > -1
22+
const isForbiddenType = node => forbiddenTypes.indexOf(node.type) > -1&&node.raw!=='null'
2323

2424
module.exports = {
2525
meta: {
@@ -46,7 +46,7 @@ module.exports = {
4646
}
4747

4848
const checkPropertyNode = (p) => {
49-
if (isForbiddenType(p.value.type)) {
49+
if (isForbiddenType(p.value)) {
5050
context.report({
5151
node: p.value,
5252
message,
@@ -57,7 +57,7 @@ module.exports = {
5757
})
5858
} else if (p.value.type === 'ArrayExpression') {
5959
p.value.elements
60-
.filter(prop => isForbiddenType(prop.type))
60+
.filter(prop => isForbiddenType(prop))
6161
.forEach(prop => context.report({
6262
node: prop,
6363
message,
@@ -79,20 +79,21 @@ module.exports = {
7979

8080
if (!node) return
8181

82-
node.value.properties.forEach(p => {
83-
if (isForbiddenType(p.value.type) || p.value.type === 'ArrayExpression') {
84-
checkPropertyNode(p)
85-
} else if (p.value.type === 'ObjectExpression') {
86-
const typeProperty = p.value.properties.find(prop =>
87-
prop.type === 'Property' &&
88-
prop.key.name === 'type'
89-
)
82+
node.value.properties
83+
.forEach(p => {
84+
if (isForbiddenType(p.value) || p.value.type === 'ArrayExpression') {
85+
checkPropertyNode(p)
86+
} else if (p.value.type === 'ObjectExpression') {
87+
const typeProperty = p.value.properties.find(prop =>
88+
prop.type === 'Property' &&
89+
prop.key.name === 'type'
90+
)
9091

91-
if (!typeProperty) return
92+
if (!typeProperty) return
9293

93-
checkPropertyNode(typeProperty)
94-
}
95-
})
94+
checkPropertyNode(typeProperty)
95+
}
96+
})
9697
})
9798
}
9899
}

‎tests/lib/rules/require-prop-type-constructor.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ ruleTester.run('require-prop-type-constructor', rule, {
3737
},
3838
lastProp: {
3939
type: [Number, Boolean]
40-
}
40+
},
41+
nullProp: null,
42+
nullTypeProp: { type: null }
4143
}
4244
}
4345
`
@@ -58,7 +60,8 @@ ruleTester.run('require-prop-type-constructor', rule, {
5860
},
5961
lastProp: {
6062
type: ['Boolean']
61-
}
63+
},
64+
nullProp: 'null'
6265
}
6366
}
6467
`,
@@ -73,7 +76,8 @@ ruleTester.run('require-prop-type-constructor', rule, {
7376
},
7477
lastProp: {
7578
type: [Boolean]
76-
}
79+
},
80+
nullProp: null
7781
}
7882
}
7983
`,
@@ -92,6 +96,9 @@ ruleTester.run('require-prop-type-constructor', rule, {
9296
}, {
9397
message: 'The "type" property should be a constructor.',
9498
line: 11
99+
}, {
100+
message: 'The "nullProp" property should be a constructor.',
101+
line: 13
95102
}]
96103
},
97104
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /