eslint-plugin-crisp 1.0.14 → 1.0.15

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/index.js CHANGED
@@ -28,6 +28,7 @@ module.exports = {
28
28
  "two-lines-between-class-members": require("./rules/two-lines-between-class-members"),
29
29
  "variable-names": require("./rules/variable-names"),
30
30
  "align-consecutive-class-assignements": require("./rules/align-consecutive-class-assignements"),
31
+ "vue-html-quotes": require("./rules/vue-html-quotes"),
31
32
  "vue-props-declaration-order": require("./rules/vue-props-declaration-order")
32
33
  }
33
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Custom EsLint Rules for Crisp",
5
5
  "main": "index.js",
6
6
  "author": "Crisp IM SAS",
@@ -12,6 +12,7 @@
12
12
  "peerDependencies": {
13
13
  "eslint": "8.45.0",
14
14
  "eslint-plugin-vue": "8.5.0",
15
- "eslint-plugin-vue-pug": "0.6.0"
15
+ "eslint-plugin-vue-pug": "0.6.0",
16
+ "vue-eslint-parser": "9.3.1"
16
17
  }
17
18
  }
@@ -105,29 +105,43 @@ module.exports = {
105
105
  "crisp/jsdocs-align-params": "error",
106
106
 
107
107
  // General Vue rules
108
- "vue/multi-word-component-names": "error",
109
108
  "vue/no-v-html": "off",
109
+ "vue/html-quotes": "off",
110
+ "vue/component-tags-order": [
111
+ "error",
112
+
113
+ {
114
+ "order": [ "template", "script", "style" ]
115
+ }
116
+ ],
110
117
  "vue/attributes-order": [
111
118
  "error",
119
+
112
120
  {
113
121
  order: [
114
- "OTHER_DIRECTIVES",
122
+ "RENDER_MODIFIERS",
115
123
  "CONDITIONALS",
124
+ "OTHER_DIRECTIVES",
116
125
  "LIST_RENDERING",
117
- "RENDER_MODIFIERS",
118
126
  "SLOT",
119
127
  "TWO_WAY_BINDING",
120
128
  "CONTENT",
121
129
  "EVENTS",
122
- "GLOBAL",
123
130
  "DEFINITION",
124
- "UNIQUE",
125
- "OTHER_ATTR"
126
- ["ATTR_DYNAMIC", "ATTR_STATIC", "ATTR_SHORTHAND_BOOL"]
131
+ ["GLOBAL", "UNIQUE", "OTHER_ATTR"]
127
132
  ],
128
133
  "alphabetical": false
129
134
  }
130
135
  ],
136
+ "vue/v-slot-style": [
137
+ "error",
138
+
139
+ {
140
+ "atComponent": "v-slot",
141
+ "default": "v-slot",
142
+ "named": "longform"
143
+ }
144
+ ],
131
145
 
132
146
  // Crisp JS rules
133
147
  "crisp/header-check": "error",
@@ -149,6 +163,7 @@ module.exports = {
149
163
  ],
150
164
 
151
165
  // Crisp Vue rules
166
+ "crisp/vue-html-quotes": "error",
152
167
  "crisp/vue-props-declaration-order": "error"
153
168
  },
154
169
 
@@ -0,0 +1,76 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "layout",
4
+ docs: {
5
+ description: "enforce quotes style of HTML attributes"
6
+ },
7
+
8
+ schema: [
9
+ { enum: ["double", "single"] },
10
+ {
11
+ type: "object",
12
+ properties: {
13
+ avoidEscape: {
14
+ type: "boolean"
15
+ }
16
+ },
17
+ additionalProperties: false
18
+ }
19
+ ],
20
+
21
+ messages: {
22
+ expected: "Expected to be enclosed by {{kind}}."
23
+ }
24
+ },
25
+
26
+ create(context) {
27
+ const sourceCode = context.getSourceCode()
28
+ const double = context.options[0] !== "single"
29
+ const avoidEscape =
30
+ context.options[1] && context.options[1].avoidEscape === true
31
+ const quoteChar = double ? '"' : "'"
32
+ const quoteName = double ? "double quotes" : "single quotes"
33
+
34
+ return context.parserServices.defineTemplateBodyVisitor(
35
+ {
36
+ "VAttribute[value!=null]"(node) {
37
+ const text = sourceCode.getText(node.value)
38
+ const firstChar = text[0]
39
+
40
+ if (firstChar !== quoteChar) {
41
+ const contentText = text.slice(1, -1);
42
+
43
+ const quoted = firstChar === "'" || firstChar === '"';
44
+
45
+ if (avoidEscape && quoted) {
46
+ if (contentText.includes(quoteChar)) {
47
+
48
+ return
49
+ }
50
+ }
51
+
52
+ // Attribute value is an object or an array
53
+ if (firstChar === "[" || firstChar === "{") {
54
+ // Matching quote in the object
55
+ if (contentText.includes(quoteChar)) {
56
+ return
57
+ }
58
+
59
+ // No quotes in the object or array
60
+ if (!contentText.includes("'") && !contentText.includes('"')) {
61
+ return
62
+ }
63
+ }
64
+
65
+ context.report({
66
+ node: node.value,
67
+ loc: node.value.loc,
68
+ messageId: "expected",
69
+ data: { kind: quoteName }
70
+ })
71
+ }
72
+ }
73
+ }
74
+ )
75
+ }
76
+ }