diff --git a/lib/rules/require-prop-type-constructor.js b/lib/rules/require-prop-type-constructor.js index 61d825039..c000e4530 100644 --- a/lib/rules/require-prop-type-constructor.js +++ b/lib/rules/require-prop-type-constructor.js @@ -45,24 +45,24 @@ module.exports = { } } - const checkPropertyNode = (p) => { - if (isForbiddenType(p.value)) { + const checkPropertyNode = (key, node) => { + if (isForbiddenType(node)) { context.report({ - node: p.value, + node: node, message, data: { - name: utils.getStaticPropertyName(p.key) + name: utils.getStaticPropertyName(key) }, - fix: fix(p.value) + fix: fix(node) }) - } else if (p.value.type === 'ArrayExpression') { - p.value.elements + } else if (node.type === 'ArrayExpression') { + node.elements .filter(prop => isForbiddenType(prop)) .forEach(prop => context.report({ node: prop, message, data: { - name: utils.getStaticPropertyName(p.key) + name: utils.getStaticPropertyName(key) }, fix: fix(prop) })) @@ -82,7 +82,7 @@ module.exports = { node.value.properties .forEach(p => { if (isForbiddenType(p.value) || p.value.type === 'ArrayExpression') { - checkPropertyNode(p) + checkPropertyNode(p.key, p.value) } else if (p.value.type === 'ObjectExpression') { const typeProperty = p.value.properties.find(prop => prop.type === 'Property' && @@ -91,7 +91,7 @@ module.exports = { if (!typeProperty) return - checkPropertyNode(typeProperty) + checkPropertyNode(p.key, typeProperty.value) } }) }) diff --git a/tests/lib/rules/require-prop-type-constructor.js b/tests/lib/rules/require-prop-type-constructor.js index fc6e79fc3..92dc9877f 100644 --- a/tests/lib/rules/require-prop-type-constructor.js +++ b/tests/lib/rules/require-prop-type-constructor.js @@ -91,10 +91,10 @@ ruleTester.run('require-prop-type-constructor', rule, { message: 'The "anotherType" property should be a constructor.', line: 5 }, { - message: 'The "type" property should be a constructor.', + message: 'The "extraProp" property should be a constructor.', line: 7 }, { - message: 'The "type" property should be a constructor.', + message: 'The "lastProp" property should be a constructor.', line: 11 }, { message: 'The "nullProp" property should be a constructor.',