Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue that caused an error when extra commas were included in require-prop-type-constructor #963

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/require-prop-type-constructor.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')
}
]
})