/** * @author Mussin Benarbia * See LICENSE file in root directory for full license. */ 'use strict' const { isVElement } = require('../utils') /** * check whether a tag has the `scoped` attribute * @param {VElement} componentBlock */ function isScoped(componentBlock) { return componentBlock.startTag.attributes.some( (attribute) => !attribute.directive && attribute.key.name === 'scoped' ) } /** * check whether a tag has the `module` attribute * @param {VElement} componentBlock */ function isModule(componentBlock) { return componentBlock.startTag.attributes.some( (attribute) => !attribute.directive && attribute.key.name === 'module' ) } /** * check if a tag doesn't have either the `scoped` nor `module` attribute * @param {VElement} componentBlock */ function isPlain(componentBlock) { return !isScoped(componentBlock) && !isModule(componentBlock) } /** @param {RuleContext} context */ function getUserDefinedAllowedAttrs(context) { if (context.options[0] && context.options[0].allow) { return context.options[0].allow } return [] } const defaultAllowedAttrs = ['scoped'] module.exports = { meta: { type: 'suggestion', docs: { description: 'enforce or forbid the use of the `scoped` and `module` attributes in SFC top level style tags', categories: undefined, url: 'https://eslint.vuejs.org/rules/enforce-style-attribute.html' }, fixable: null, schema: [ { type: 'object', properties: { allow: { type: 'array', minItems: 1, uniqueItems: true, items: { type: 'string', enum: ['plain', 'scoped', 'module'] } } }, additionalProperties: false } ], messages: { notAllowedScoped: 'The scoped attribute is not allowed. Allowed: {{ allowedAttrsString }}.', notAllowedModule: 'The module attribute is not allowed. Allowed: {{ allowedAttrsString }}.', notAllowedPlain: 'Plain