Skip to content

Commit 096949b

Browse files
armano2mysticatea
authored andcommitted
Fix: reporting correct name in require-prop-type-constructor (#615)
1 parent 3ccf3ef commit 096949b

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ module.exports = {
4545
}
4646
}
4747

48-
const checkPropertyNode = (p) => {
49-
if (isForbiddenType(p.value)) {
48+
const checkPropertyNode = (key, node) => {
49+
if (isForbiddenType(node)) {
5050
context.report({
51-
node: p.value,
51+
node: node,
5252
message,
5353
data: {
54-
name: utils.getStaticPropertyName(p.key)
54+
name: utils.getStaticPropertyName(key)
5555
},
56-
fix: fix(p.value)
56+
fix: fix(node)
5757
})
58-
} else if (p.value.type === 'ArrayExpression') {
59-
p.value.elements
58+
} else if (node.type === 'ArrayExpression') {
59+
node.elements
6060
.filter(prop => isForbiddenType(prop))
6161
.forEach(prop => context.report({
6262
node: prop,
6363
message,
6464
data: {
65-
name: utils.getStaticPropertyName(p.key)
65+
name: utils.getStaticPropertyName(key)
6666
},
6767
fix: fix(prop)
6868
}))
@@ -82,7 +82,7 @@ module.exports = {
8282
node.value.properties
8383
.forEach(p => {
8484
if (isForbiddenType(p.value) || p.value.type === 'ArrayExpression') {
85-
checkPropertyNode(p)
85+
checkPropertyNode(p.key, p.value)
8686
} else if (p.value.type === 'ObjectExpression') {
8787
const typeProperty = p.value.properties.find(prop =>
8888
prop.type === 'Property' &&
@@ -91,7 +91,7 @@ module.exports = {
9191

9292
if (!typeProperty) return
9393

94-
checkPropertyNode(typeProperty)
94+
checkPropertyNode(p.key, typeProperty.value)
9595
}
9696
})
9797
})

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ ruleTester.run('require-prop-type-constructor', rule, {
9191
message: 'The "anotherType" property should be a constructor.',
9292
line: 5
9393
}, {
94-
message: 'The "type" property should be a constructor.',
94+
message: 'The "extraProp" property should be a constructor.',
9595
line: 7
9696
}, {
97-
message: 'The "type" property should be a constructor.',
97+
message: 'The "lastProp" property should be a constructor.',
9898
line: 11
9999
}, {
100100
message: 'The "nullProp" property should be a constructor.',

0 commit comments

Comments
 (0)