Skip to content

Commit

Permalink
v1.0.94
Browse files Browse the repository at this point in the history
New rule
  • Loading branch information
eliottvincent committed Aug 20, 2024
1 parent ec2e582 commit 220a0a4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Each item has emojis denoting:
| [crisp/vue-html-indent](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-html-indent.js) | Enforces consistent indentation in `template` (supports for Pug) | | 🟢 |
| [crisp/vue-html-quotes](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-html-quotes.js) | Enforces HTML attributes to be enclosed with double quotes | | 🟢 |
| [crisp/vue-no-regex-data](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-regex-data.js) | Disallows regular expressions to be declared in Vue data object | | 🟢 |
| [crisp/vue-props-declaration-line-break](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-line-break.js) | Enforces line break between type and default function in prop definition | | 🟢 |
| [crisp/vue-props-declaration-multiline](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-multiline.js) | Enforces props declarations to be multiline | | 🟢 |
| [crisp/vue-props-declaration-order](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-order.js) | Ensures props declarations are alphabetically ordered | | 🟢 |
| [crisp/vue-ref-case](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-ref-case.js) | Enforces `ref` attributes to snake case | | 🟢 |
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
"vue-html-indent": require("./rules/vue-html-indent"),
"vue-html-quotes": require("./rules/vue-html-quotes"),
"vue-no-regex-data": require("./rules/vue-no-regex-data"),
"vue-props-declaration-line-break": require("./rules/vue-props-declaration-line-break"),
"vue-props-declaration-multiline": require("./rules/vue-props-declaration-multiline"),
"vue-props-declaration-order": require("./rules/vue-props-declaration-order"),
"vue-ref-case": require("./rules/vue-ref-case")
Expand Down
2 changes: 1 addition & 1 deletion 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.93",
"version": "1.0.94",
"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 @@ -352,6 +352,7 @@ module.exports = {
"crisp/vue-html-indent": "error",
"crisp/vue-html-quotes": "error",
"crisp/vue-no-regex-data": "error",
"crisp/vue-props-declaration-line-break": "error",
"crisp/vue-props-declaration-multiline": "error",
"crisp/vue-props-declaration-order": "error",
"crisp/vue-ref-case": "error"
Expand Down
50 changes: 50 additions & 0 deletions rules/vue-props-declaration-line-break.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
meta: {
type: "layout",
docs: {
description: "Enforce line break between type and default function in Vue props",
category: "Stylistic Issues",
recommended: false,
},
fixable: "whitespace",
schema: [], // no options
},

create(context) {
const sourceCode = context.getSourceCode();

function checkPropDefinition(propNode) {
const typeProperty = propNode.properties.find(p => p.key.name === "type");
const defaultProperty = propNode.properties.find(p => p.key.name === "default");

if (typeProperty && defaultProperty && defaultProperty.value.type === "FunctionExpression") {
const typeLine = sourceCode.getLastToken(typeProperty).loc.end.line;
const defaultLine = sourceCode.getFirstToken(defaultProperty).loc.start.line;

if (defaultLine - typeLine < 2) {
context.report({
node: defaultProperty,
message: "There should be a line break between 'type' and 'default' function in prop definition.",
fix(fixer) {
const typeToken = sourceCode.getLastToken(typeProperty);
const defaultToken = sourceCode.getFirstToken(defaultProperty);
const textBetween = sourceCode.text.slice(typeToken.range[1], defaultToken.range[0]);
const newTextBetween = textBetween.replace(/,?\s*/, ",\n\n");
return fixer.replaceTextRange([typeToken.range[1], defaultToken.range[0]], newTextBetween);
}
});
}
}
}

return {
'ExportDefaultDeclaration Property[key.name="props"] ObjectExpression'(node) {
node.properties.forEach(prop => {
if (prop.value.type === "ObjectExpression") {
checkPropDefinition(prop.value);
}
});
}
};
}
};

0 comments on commit 220a0a4

Please sign in to comment.