eslint-plugin-crisp 1.0.93 → 1.0.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -200,6 +200,7 @@ Each item has emojis denoting:
200
200
  | [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) | | 🟢 |
201
201
  | [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 | | 🟢 |
202
202
  | [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 | | 🟢 |
203
+ | [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 | | 🟢 |
203
204
  | [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 | | 🟢 |
204
205
  | [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 | | 🟢 |
205
206
  | [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 | | 🟢 |
package/index.js CHANGED
@@ -43,6 +43,7 @@ module.exports = {
43
43
  "vue-html-indent": require("./rules/vue-html-indent"),
44
44
  "vue-html-quotes": require("./rules/vue-html-quotes"),
45
45
  "vue-no-regex-data": require("./rules/vue-no-regex-data"),
46
+ "vue-props-declaration-line-break": require("./rules/vue-props-declaration-line-break"),
46
47
  "vue-props-declaration-multiline": require("./rules/vue-props-declaration-multiline"),
47
48
  "vue-props-declaration-order": require("./rules/vue-props-declaration-order"),
48
49
  "vue-ref-case": require("./rules/vue-ref-case")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.93",
3
+ "version": "1.0.94",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -352,6 +352,7 @@ module.exports = {
352
352
  "crisp/vue-html-indent": "error",
353
353
  "crisp/vue-html-quotes": "error",
354
354
  "crisp/vue-no-regex-data": "error",
355
+ "crisp/vue-props-declaration-line-break": "error",
355
356
  "crisp/vue-props-declaration-multiline": "error",
356
357
  "crisp/vue-props-declaration-order": "error",
357
358
  "crisp/vue-ref-case": "error"
@@ -0,0 +1,50 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "layout",
4
+ docs: {
5
+ description: "Enforce line break between type and default function in Vue props",
6
+ category: "Stylistic Issues",
7
+ recommended: false,
8
+ },
9
+ fixable: "whitespace",
10
+ schema: [], // no options
11
+ },
12
+
13
+ create(context) {
14
+ const sourceCode = context.getSourceCode();
15
+
16
+ function checkPropDefinition(propNode) {
17
+ const typeProperty = propNode.properties.find(p => p.key.name === "type");
18
+ const defaultProperty = propNode.properties.find(p => p.key.name === "default");
19
+
20
+ if (typeProperty && defaultProperty && defaultProperty.value.type === "FunctionExpression") {
21
+ const typeLine = sourceCode.getLastToken(typeProperty).loc.end.line;
22
+ const defaultLine = sourceCode.getFirstToken(defaultProperty).loc.start.line;
23
+
24
+ if (defaultLine - typeLine < 2) {
25
+ context.report({
26
+ node: defaultProperty,
27
+ message: "There should be a line break between 'type' and 'default' function in prop definition.",
28
+ fix(fixer) {
29
+ const typeToken = sourceCode.getLastToken(typeProperty);
30
+ const defaultToken = sourceCode.getFirstToken(defaultProperty);
31
+ const textBetween = sourceCode.text.slice(typeToken.range[1], defaultToken.range[0]);
32
+ const newTextBetween = textBetween.replace(/,?\s*/, ",\n\n");
33
+ return fixer.replaceTextRange([typeToken.range[1], defaultToken.range[0]], newTextBetween);
34
+ }
35
+ });
36
+ }
37
+ }
38
+ }
39
+
40
+ return {
41
+ 'ExportDefaultDeclaration Property[key.name="props"] ObjectExpression'(node) {
42
+ node.properties.forEach(prop => {
43
+ if (prop.value.type === "ObjectExpression") {
44
+ checkPropDefinition(prop.value);
45
+ }
46
+ });
47
+ }
48
+ };
49
+ }
50
+ };