You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.8 KiB
60 lines
1.8 KiB
3 years ago
|
/**
|
||
|
* @author tyankatsu <https://github.com/tyankatsu0105>
|
||
|
* See LICENSE file in root directory for full license.
|
||
|
*/
|
||
|
'use strict'
|
||
|
|
||
|
// ------------------------------------------------------------------------------
|
||
|
// Requirements
|
||
|
// ------------------------------------------------------------------------------
|
||
|
|
||
|
const { defineTemplateBodyVisitor } = require('../utils')
|
||
|
|
||
|
// ------------------------------------------------------------------------------
|
||
|
// Rule Definition
|
||
|
// ------------------------------------------------------------------------------
|
||
|
|
||
|
/**
|
||
|
* count ObjectExpression element
|
||
|
* @param {VDirective & {value: VExpressionContainer & {expression: ArrayExpression}}} node
|
||
|
* @return {number}
|
||
|
*/
|
||
|
function countObjectExpression(node) {
|
||
|
return node.value.expression.elements.filter(
|
||
|
(element) => element && element.type === 'ObjectExpression'
|
||
|
).length
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
type: 'suggestion',
|
||
|
docs: {
|
||
|
description: 'disallow to pass multiple objects into array to class',
|
||
|
categories: undefined,
|
||
|
url: 'https://eslint.vuejs.org/rules/no-multiple-objects-in-class.html'
|
||
|
},
|
||
|
fixable: null,
|
||
|
schema: [],
|
||
|
messages: {
|
||
|
unexpected: 'Unexpected multiple objects. Merge objects.'
|
||
|
}
|
||
|
},
|
||
|
/** @param {RuleContext} context */
|
||
|
create(context) {
|
||
|
return defineTemplateBodyVisitor(context, {
|
||
|
/** @param {VDirective & {value: VExpressionContainer & {expression: ArrayExpression}}} node */
|
||
|
'VAttribute[directive=true][key.argument.name="class"][key.name.name="bind"][value.expression.type="ArrayExpression"]'(
|
||
|
node
|
||
|
) {
|
||
|
if (countObjectExpression(node) > 1) {
|
||
|
context.report({
|
||
|
node,
|
||
|
loc: node.loc,
|
||
|
messageId: 'unexpected'
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|