Skip to content

Commit

Permalink
v1.0.91
Browse files Browse the repository at this point in the history
Add comma rule
  • Loading branch information
eliottvincent committed Jul 6, 2024
1 parent bd27f49 commit 58195a7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | 🟢 |
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions recommended-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 33 additions & 0 deletions rules/vue-attribute-comma.js
Original file line number Diff line number Diff line change
@@ -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]);
},
});
}
},
});
},
};

0 comments on commit 58195a7

Please sign in to comment.