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 crashes of no-reserved-component-names, match-component-file-name and component-definition-name-casing rules. #1019

Merged
merged 1 commit into from Dec 27, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 6 additions & 12 deletions lib/rules/component-definition-name-casing.js
Expand Up @@ -73,21 +73,15 @@ module.exports = {
}

return Object.assign({},
{
"CallExpression > MemberExpression > Identifier[name='component']" (node) {
const parent = node.parent.parent
const calleeObject = utils.unwrapTypes(parent.callee.object)
utils.executeOnCallVueComponent(context, (node) => {
if (node.arguments.length === 2) {
const argument = node.arguments[0]

if (calleeObject.type === 'Identifier' && calleeObject.name === 'Vue') {
if (parent.arguments && parent.arguments.length === 2) {
const argument = parent.arguments[0]
if (canConvert(argument)) {
convertName(argument)
}
}
if (canConvert(argument)) {
convertName(argument)
}
}
},
}),
utils.executeOnVue(context, (obj) => {
const node = obj.properties
.find(item => (
Expand Down
20 changes: 7 additions & 13 deletions lib/rules/match-component-file-name.js
Expand Up @@ -101,21 +101,15 @@ module.exports = {
}

return Object.assign({},
{
"CallExpression > MemberExpression > Identifier[name='component']" (node) {
const parent = node.parent.parent
const calleeObject = utils.unwrapTypes(parent.callee.object)

if (calleeObject.type === 'Identifier' && calleeObject.name === 'Vue') {
if (parent.arguments && parent.arguments.length === 2) {
const argument = parent.arguments[0]
if (canVerify(argument)) {
verifyName(argument)
}
}
utils.executeOnCallVueComponent(context, (node) => {
if (node.arguments.length === 2) {
const argument = node.arguments[0]

if (canVerify(argument)) {
verifyName(argument)
}
}
},
}),
utils.executeOnVue(context, (object) => {
const node = object.properties
.find(item => (
Expand Down
21 changes: 6 additions & 15 deletions lib/rules/no-reserved-component-names.js
Expand Up @@ -86,24 +86,15 @@ module.exports = {
}

return Object.assign({},
{
"CallExpression > MemberExpression > Identifier[name='component']" (node) {
const parent = node.parent.parent
const calleeObject = utils.unwrapTypes(parent.callee.object)
utils.executeOnCallVueComponent(context, (node) => {
if (node.arguments.length === 2) {
const argument = node.arguments[0]

if (calleeObject.type === 'Identifier' &&
calleeObject.name === 'Vue' &&
parent.arguments &&
parent.arguments.length === 2
) {
const argument = parent.arguments[0]

if (canVerify(argument)) {
reportIfInvalid(argument)
}
if (canVerify(argument)) {
reportIfInvalid(argument)
}
}
},
}),
utils.executeOnVue(context, (obj) => {
// Report if a component has been registered locally with a reserved name.
utils.getRegisteredComponents(obj)
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/index.js
Expand Up @@ -635,6 +635,30 @@ module.exports = {
}
},

/**
* Check call `Vue.component` and call callback.
* @param {RuleContext} _context The ESLint rule context object.
* @param {Function} cb Callback function
*/
executeOnCallVueComponent (_context, cb) {
return {
"CallExpression > MemberExpression > Identifier[name='component']": (node) => {
const callExpr = node.parent.parent
const callee = callExpr.callee

if (callee.type === 'MemberExpression') {
const calleeObject = this.unwrapTypes(callee.object)

if (calleeObject.type === 'Identifier' &&
calleeObject.name === 'Vue' &&
callee.property === node &&
callExpr.arguments.length >= 1) {
cb(callExpr)
}
}
}
}
},
/**
* Return generator with all properties
* @param {ASTNode} node Node to check
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/component-definition-name-casing.js
Expand Up @@ -136,6 +136,12 @@ ruleTester.run('component-definition-name-casing', rule, {
code: `Vue.component(\`fooBar\${foo}\`, component)`,
options: ['kebab-case'],
parserOptions
},
// https://github.com/vuejs/eslint-plugin-vue/issues/1018
{
filename: 'test.js',
code: `fn1(component.data)`,
parserOptions
}
],

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/match-component-file-name.js
Expand Up @@ -531,6 +531,12 @@ ruleTester.run('match-component-file-name', rule, {
`,
options: [{ shouldMatchCase: true }],
parserOptions: jsxParserOptions
},
// https://github.com/vuejs/eslint-plugin-vue/issues/1018
{
filename: 'test.jsx',
code: `fn1(component.data)`,
parserOptions
}
],

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-reserved-component-names.js
Expand Up @@ -311,6 +311,12 @@ ruleTester.run('no-reserved-component-names', rule, {
`,
parser: require.resolve('vue-eslint-parser'),
parserOptions
},
// https://github.com/vuejs/eslint-plugin-vue/issues/1018
{
filename: 'test.js',
code: `fn1(component.data)`,
parserOptions
}
],

Expand Down