diff --git a/README.md b/README.md index bf94433..ba04f30 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ Each item has emojis denoting: | Name | Description | 🟠 | 🟢 | | :- | :- | :- | :- | +| [crisp/vue-attribute-comma](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-attribute-comma.js) | Disallows trailing comma after attribute | | 🟢 | | [crisp/vue-attribute-linebreak](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-attribute-linebreak.js) | Enforces linebreak before first attribute and after last attribute | | 🟢 | | [crisp/vue-computed-order](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-computed-order.js) | Ensures computed properties are alphabetically ordered | | 🟢 | | [crisp/vue-emits-order](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-emits-order.js) | Ensures emits properties are alphabetically ordered | | 🟢 | diff --git a/index.js b/index.js index 1b87030..6ea79e0 100644 --- a/index.js +++ b/index.js @@ -34,6 +34,7 @@ module.exports = { "ternary-parenthesis": require("./rules/ternary-parenthesis"), "two-lines-between-class-members": require("./rules/two-lines-between-class-members"), "variable-names": require("./rules/variable-names"), + "vue-attribute-comma": require("./rules/vue-attribute-comma"), "vue-attribute-linebreak": require("./rules/vue-attribute-linebreak"), "vue-computed-order": require("./rules/vue-computed-order"), "vue-emits-order": require("./rules/vue-emits-order"), diff --git a/package-lock.json b/package-lock.json index f4d3289..03656d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "eslint-plugin-crisp", - "version": "1.0.90", + "version": "1.0.91", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "eslint-plugin-crisp", - "version": "1.0.90", + "version": "1.0.91", "license": "MIT", "dependencies": { "doctrine": "3.0.0", diff --git a/package.json b/package.json index 4645004..44caa84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-crisp", - "version": "1.0.90", + "version": "1.0.91", "description": "Custom ESLint Rules for Crisp", "author": "Crisp IM SAS", "main": "index.js", diff --git a/recommended-vue.js b/recommended-vue.js index 9f41628..e924497 100644 --- a/recommended-vue.js +++ b/recommended-vue.js @@ -334,6 +334,7 @@ module.exports = { ], // Crisp Vue rules + "crisp/vue-attribute-comma": "error", "crisp/vue-attribute-linebreak": "error", "crisp/vue-computed-order": "error", "crisp/vue-emits-order": "error", diff --git a/rules/vue-attribute-comma.js b/rules/vue-attribute-comma.js new file mode 100644 index 0000000..a08721a --- /dev/null +++ b/rules/vue-attribute-comma.js @@ -0,0 +1,33 @@ +module.exports = { + meta: { + type: "problem", + docs: { + description: "disallow commas after attribute values in Vue templates", + category: "Possible Errors", + recommended: false, + }, + fixable: "code", + schema: [], // no options + }, + + create(context) { + return context.parserServices.defineTemplateBodyVisitor({ + 'VAttribute'(node) { + const sourceCode = context.getSourceCode(); + const attributeText = sourceCode.getText(node); + const attributeEndIndex = node.range[1]; + const nextChar = sourceCode.getText().slice(attributeEndIndex, attributeEndIndex + 1); + + if (nextChar === ',') { + context.report({ + node, + message: 'Comma after attribute value is not allowed.', + fix(fixer) { + return fixer.removeRange([attributeEndIndex, attributeEndIndex + 1]); + }, + }); + } + }, + }); + }, +};