diff --git a/lib/rules/no-invalid-attribute-name.js b/lib/rules/no-invalid-attribute-name.js index 75f802c26..55a2b9b72 100644 --- a/lib/rules/no-invalid-attribute-name.js +++ b/lib/rules/no-invalid-attribute-name.js @@ -5,6 +5,7 @@ 'use strict' const utils = require('../utils') +const xnv = require('xml-name-validator') module.exports = { meta: { @@ -18,7 +19,7 @@ module.exports = { fixable: null, schema: [], messages: { - unexpected: '{{name}} is not a valid attribute name' + unexpected: 'Attribute name {{name}} is not valid.' } }, /** @param {RuleContext} context */ @@ -39,7 +40,7 @@ module.exports = { VAttribute(node) { const name = getName(node.key.name) - if (!/^[_:a-zA-Z][_:.\-a-zA-Z0-9]+/.test(name)) { + if (!xnv.name(name)) { context.report({ node, messageId: 'unexpected', diff --git a/package.json b/package.json index 9ddbb72a4..7e9c1217b 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,8 @@ "nth-check": "^2.0.1", "postcss-selector-parser": "^6.0.9", "semver": "^7.3.5", - "vue-eslint-parser": "^8.0.1" + "vue-eslint-parser": "^8.0.1", + "xml-name-validator": "^4.0.0" }, "devDependencies": { "@types/eslint": "^7.28.1", diff --git a/tests/lib/rules/no-invalid-attribute-name.js b/tests/lib/rules/no-invalid-attribute-name.js index 9d6d584cb..37d50099b 100644 --- a/tests/lib/rules/no-invalid-attribute-name.js +++ b/tests/lib/rules/no-invalid-attribute-name.js @@ -116,7 +116,7 @@ tester.run('no-invalid-attribute-name', rule, { `, errors: [ { - message: '0abc is not a valid attribute name' + message: 'Attribute name 0abc is not valid.' } ] }, @@ -133,7 +133,7 @@ tester.run('no-invalid-attribute-name', rule, { `, errors: [ { - message: '-def is not a valid attribute name' + message: 'Attribute name -def is not valid.' } ] }, @@ -150,7 +150,7 @@ tester.run('no-invalid-attribute-name', rule, { `, errors: [ { - message: '!ghi is not a valid attribute name' + message: 'Attribute name !ghi is not valid.' } ] }