Skip to content

Commit

Permalink
v1.0.61
Browse files Browse the repository at this point in the history
Enforce multiline props
  • Loading branch information
eliottvincent committed Dec 21, 2023
1 parent c5f18a1 commit 1f0d121
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
"vue-header-check": require("./rules/vue-header-check"),
"vue-html-quotes": require("./rules/vue-html-quotes"),
"vue-no-regex-data": require("./rules/vue-no-regex-data"),
"vue-props-declaration-order": require("./rules/vue-props-declaration-order")
"vue-props-declaration-order": require("./rules/vue-props-declaration-order"),
"vue-props-declaration-multiline": require("./rules/vue-props-declaration-multiline")
}
};
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.60",
"version": "1.0.61",
"description": "Custom ESLint Rules for Crisp",
"author": "Crisp IM SAS",
"main": "index.js",
Expand Down
2 changes: 2 additions & 0 deletions recommended-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ module.exports = {
"vue/html-quotes": "off",
"vue/no-v-html": "off",
"vue/prefer-true-attribute-shorthand": "error",
"vue/require-name-property": "error",
"vue/comma-dangle": "error",
"vue/eqeqeq": "error",
"vue/key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
Expand Down Expand Up @@ -321,6 +322,7 @@ module.exports = {
"crisp/vue-header-check": "error",
"crisp/vue-html-quotes": "error",
"crisp/vue-no-regex-data": "error",
"crisp/vue-props-declaration-multiline": "error",
"crisp/vue-props-declaration-order": "error"
}
}
46 changes: 46 additions & 0 deletions rules/vue-props-declaration-multiline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "enforce multi-line declaration for Vue props",
category: "Stylistic Issues",
recommended: false,
},
fixable: "code",
schema: [], // no options
},

create(context) {
return {
'ExportDefaultDeclaration Property[key.name="props"] ObjectExpression'(node) {
node.properties.forEach(prop => {
// Ensuring we only target the top-level prop definitions
if (prop.value.type === "ObjectExpression") {
const propDefinition = prop.value;

// Check if the prop definition is on a single line
if (propDefinition.loc.start.line === propDefinition.loc.end.line) {
context.report({
node: prop,
message: "Props should be declared in multiple lines.",

fix(fixer) {
const sourceCode = context.getSourceCode();
const propText = sourceCode.getText(propDefinition);

// Construct the multi-line version of the prop
const expandedProp = propText
.replace("{", "{\n")
.replace("}", "\n}")
.replace(/, /g, ",\n");

return fixer.replaceText(propDefinition, expandedProp);
}
});
}
}
});
}
};
}
};

0 comments on commit 1f0d121

Please sign in to comment.