Skip to content

Commit

Permalink
Fixed an issue that caused an error when extra commas were included i…
Browse files Browse the repository at this point in the history
…n `require-prop-type-constructor` (#963)
  • Loading branch information
ota-meshi committed Dec 26, 2019
1 parent b412783 commit 2418da7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/require-prop-type-constructor.js
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/index.js
Expand Up @@ -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 }
Expand Down
72 changes: 72 additions & 0 deletions tests/lib/rules/require-prop-type-constructor.js
Expand Up @@ -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',,,]
}
`
}
],

Expand Down Expand Up @@ -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')
}
]
})

0 comments on commit 2418da7

Please sign in to comment.