Skip to content

Commit

Permalink
vuejs#1373 Use xml-name-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade committed Apr 21, 2022
1 parent 05c60a0 commit 01ed0d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/rules/no-invalid-attribute-name.js
Expand Up @@ -5,6 +5,7 @@
'use strict'

const utils = require('../utils')
const xnv = require('xml-name-validator')

module.exports = {
meta: {
Expand All @@ -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 */
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/no-invalid-attribute-name.js
Expand Up @@ -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.'
}
]
},
Expand All @@ -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.'
}
]
},
Expand All @@ -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.'
}
]
}
Expand Down

0 comments on commit 01ed0d7

Please sign in to comment.