diff --git a/lib/rules/require-prop-type-constructor.js b/lib/rules/require-prop-type-constructor.js index d6c00e257..edde36f49 100644 --- a/lib/rules/require-prop-type-constructor.js +++ b/lib/rules/require-prop-type-constructor.js @@ -58,7 +58,7 @@ module.exports = { }) } else if (node.type === 'ArrayExpression') { node.elements - .filter(prop => isForbiddenType(prop)) + .filter(prop => prop && isForbiddenType(prop)) .forEach(prop => context.report({ node: prop, message, diff --git a/lib/utils/index.js b/lib/utils/index.js index d6c9221a1..5e32fa9bf 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -453,6 +453,7 @@ module.exports = { }) } else { props = propsNode.value.elements + .filter(prop => prop) .map(prop => { const key = prop.type === 'Literal' && typeof prop.value === 'string' ? prop : null return { key, value: null, node: prop, propName: key != null ? prop.value : null } diff --git a/tests/lib/rules/require-prop-type-constructor.js b/tests/lib/rules/require-prop-type-constructor.js index 1e3ca6d94..70fc35e8e 100644 --- a/tests/lib/rules/require-prop-type-constructor.js +++ b/tests/lib/rules/require-prop-type-constructor.js @@ -44,6 +44,56 @@ ruleTester.run('require-prop-type-constructor', rule, { } } ` + }, + { + filename: 'ExtraCommas.vue', + code: ` + export default { + props: { + name: [String,,] + } + } + ` + }, + { + filename: 'ExtraCommas.vue', + code: ` + export default { + props: { + name: { + type: [String,,] + } + } + } + ` + }, + { + filename: 'ExtraCommas.vue', + code: ` + export default { + props: { + name: [String,,Number] + } + } + ` + }, + { + filename: 'ExtraCommas.vue', + code: ` + export default { + props: { + name: [,,Number] + } + } + ` + }, + { + filename: 'ExtraCommas.vue', + code: ` + export default { + props: ['name',,,] + } + ` } ], @@ -165,6 +215,28 @@ ruleTester.run('require-prop-type-constructor', rule, { line: 5 }], parser: require.resolve('@typescript-eslint/parser') + }, + { + filename: 'ExtraCommas.vue', + code: ` + export default { + props: { + name: ['String',,] + } + } + `, + output: ` + export default { + props: { + name: [String,,] + } + } + `, + errors: [{ + message: 'The "name" property should be a constructor.', + line: 4 + }], + parser: require.resolve('@typescript-eslint/parser') } ] })