eslint-plugin-crisp 1.0.84 → 1.0.86

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
@@ -191,9 +191,11 @@ Each item has emojis denoting:
191
191
 
192
192
  | Name | Description | 🟠 | 🟢 |
193
193
  | :- | :- | :- | :- |
194
+ | [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 | | 🟢 |
194
195
  | [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 | | 🟢 |
195
196
  | [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 | | 🟢 |
196
197
  | [crisp/vue-header-check](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-header-check.js) | Ensures `script`, `template` and `style` tags start with corresponding comment block | | 🟢 |
198
+ | [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) | | 🟢 |
197
199
  | [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 | | 🟢 |
198
200
  | [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 | | 🟢 |
199
201
  | [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 | | 🟢 |
package/index.js CHANGED
@@ -34,9 +34,11 @@ module.exports = {
34
34
  "ternary-parenthesis": require("./rules/ternary-parenthesis"),
35
35
  "two-lines-between-class-members": require("./rules/two-lines-between-class-members"),
36
36
  "variable-names": require("./rules/variable-names"),
37
+ "vue-attribute-linebreak": require("./rules/vue-attribute-linebreak"),
37
38
  "vue-computed-order": require("./rules/vue-computed-order"),
38
39
  "vue-emits-order": require("./rules/vue-emits-order"),
39
40
  "vue-header-check": require("./rules/vue-header-check"),
41
+ "vue-html-indent": require("./rules/vue-html-indent"),
40
42
  "vue-html-quotes": require("./rules/vue-html-quotes"),
41
43
  "vue-no-regex-data": require("./rules/vue-no-regex-data"),
42
44
  "vue-props-declaration-order": require("./rules/vue-props-declaration-order"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -334,9 +334,11 @@ module.exports = {
334
334
  ],
335
335
 
336
336
  // Crisp Vue rules
337
+ "crisp/vue-attribute-linebreak": "error",
337
338
  "crisp/vue-computed-order": "error",
338
339
  "crisp/vue-emits-order": "error",
339
340
  "crisp/vue-header-check": "error",
341
+ "crisp/vue-html-indent": "error",
340
342
  "crisp/vue-html-quotes": "error",
341
343
  "crisp/vue-no-regex-data": "error",
342
344
  "crisp/vue-props-declaration-multiline": "error",
@@ -0,0 +1,47 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "layout",
4
+ docs: {
5
+ description: "enforce the location of first and last attributes",
6
+ category: "Stylistic Issues",
7
+ recommended: false,
8
+ },
9
+ fixable: null
10
+ },
11
+
12
+ create(context) {
13
+ function report(attribute, location) {
14
+ context.report({
15
+ node: attribute,
16
+ message: `Expected a linebreak ${location} this attribute.`
17
+ })
18
+ }
19
+
20
+ return context.parserServices.defineTemplateBodyVisitor({
21
+ VStartTag(node) {
22
+ // Skip 'template' tags
23
+ if (node.parent.name === "template") {
24
+ return;
25
+ }
26
+
27
+ // No attributes
28
+ if (node.attributes.length === 0) {
29
+ return;
30
+ }
31
+
32
+ const firstAttribute = node.attributes[0];
33
+ const lastAttribute = node.attributes[node.attributes.length - 1];
34
+
35
+ // Enforce line-break before first attribute
36
+ if (node.loc.start.line === firstAttribute.loc.start.line) {
37
+ report(firstAttribute, "above");
38
+ }
39
+
40
+ // Enforce line-break after last attribute
41
+ if (node.loc.end.line === lastAttribute.loc.start.line) {
42
+ report(lastAttribute, "below");
43
+ }
44
+ }
45
+ })
46
+ }
47
+ };
@@ -0,0 +1,86 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "layout",
4
+ docs: {
5
+ description: "enforce consistent indentation in `<template>`",
6
+ category: "Stylistic Issues",
7
+ recommended: false,
8
+ },
9
+ fixable: "whitespace"
10
+ },
11
+
12
+ create(context) {
13
+ const sourceCode = context.getSourceCode()
14
+ const template = (
15
+ sourceCode.parserServices.getTemplateBodyTokenStore &&
16
+ sourceCode.parserServices.getTemplateBodyTokenStore()
17
+ );
18
+
19
+ function report(element, type, expected, actual) {
20
+ const reportObj = {
21
+ node: element,
22
+ message: `Expected ${type} indentation of ${expected} spaces but found ${actual}`
23
+ };
24
+
25
+ if (type === "attribute") {
26
+ reportObj.fix = function(fixer) {
27
+ const startToken = template.getTokenBefore(element);
28
+ const endToken = template.getTokenAfter(element);
29
+ const indent = " ".repeat(expected);
30
+
31
+ return fixer.replaceTextRange(
32
+ [startToken.range[1], element.range[0]],
33
+ `\n${indent}`
34
+ );
35
+ };
36
+ }
37
+
38
+ context.report(reportObj);
39
+ }
40
+
41
+ return context.parserServices.defineTemplateBodyVisitor({
42
+ VStartTag(node) {
43
+ // Skip "template" tags
44
+ if (node.parent.name === "template") {
45
+ return;
46
+ }
47
+
48
+ // Skip singleline element (no indentation to check)
49
+ if (node.loc.start.line === node.loc.end.line) {
50
+ return;
51
+ }
52
+
53
+ // There is a shift of 1 space on the closing tag (likely caused by Pug)
54
+ const actual = node.loc.end.column - 1;
55
+ const expected = node.loc.start.column;
56
+
57
+ // Check closing tag indentation
58
+ if (actual !== expected) {
59
+ report(
60
+ node,
61
+ "closing tag",
62
+
63
+ expected,
64
+ actual
65
+ );
66
+ }
67
+
68
+ node.attributes.forEach((attribute) => {
69
+ const actual = attribute.loc.start.column;
70
+ const expected = node.loc.start.column + 2;
71
+
72
+ // Check attribute indentation
73
+ if (actual !== expected) {
74
+ report(
75
+ attribute,
76
+ "attribute",
77
+
78
+ expected,
79
+ actual
80
+ );
81
+ }
82
+ });
83
+ }
84
+ })
85
+ }
86
+ };