@vue-jsx-vapor/eslint 2.3.0 → 2.3.1

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/dist/index.js CHANGED
@@ -1,634 +1,533 @@
1
- // src/rules/define-style/index.ts
2
1
  import prettier from "@prettier/sync";
3
- var rule = {
4
- defaultOptions: [
5
- {
6
- tabWidth: 2
7
- }
8
- ],
9
- meta: {
10
- type: "layout",
11
- docs: {
12
- description: "Enforce consistent formatting in defineStyle CSS"
13
- },
14
- fixable: "code",
15
- messages: {
16
- "define-style": "Style in defineStyle should be properly formatted",
17
- "define-style-syntax-error": "Syntax error in defineStyle"
18
- },
19
- schema: [
20
- {
21
- type: "object",
22
- properties: {
23
- tabWidth: {
24
- type: "number",
25
- default: 2
26
- }
27
- }
28
- }
29
- ]
30
- },
31
- create(context) {
32
- const configuration = context.options[0] || {};
33
- const tabWidth = configuration.tabWidth || 2;
34
- return {
35
- CallExpression(node) {
36
- const callee = node.callee.type === "MemberExpression" ? node.callee.object : node.callee;
37
- const offset = callee.loc.start.column;
38
- const parser = node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" ? node.callee.property.name : "css";
39
- if (callee.type === "Identifier" && callee.name === "defineStyle") {
40
- const arg = node.arguments[0];
41
- if (arg?.type === "TemplateLiteral") {
42
- const cssRaw = arg.quasis[0].value.raw;
43
- let formattedCss = "";
44
- try {
45
- formattedCss = prettier.format(cssRaw, { parser, tabWidth });
46
- } catch {
47
- return context.report({
48
- node: arg,
49
- messageId: "define-style-syntax-error"
50
- });
51
- }
52
- const placeholder = " ".repeat(offset + tabWidth);
53
- const result = `
54
- ${placeholder}${formattedCss.slice(0, -1).replaceAll("\n", `
55
- ${placeholder}`)}
56
- ${" ".repeat(offset)}`;
57
- if (result !== cssRaw) {
58
- context.report({
59
- node: arg,
60
- messageId: "define-style",
61
- fix(fixer) {
62
- return fixer.replaceTextRange(
63
- [arg.range[0] + 1, arg.range[1] - 1],
64
- result
65
- );
66
- }
67
- });
68
- }
69
- }
70
- }
71
- }
72
- };
73
- }
2
+
3
+ //#region src/rules/define-style/index.ts
4
+ const rule$1 = {
5
+ defaultOptions: [{ tabWidth: 2 }],
6
+ meta: {
7
+ type: "layout",
8
+ docs: { description: "Enforce consistent formatting in defineStyle CSS" },
9
+ fixable: "code",
10
+ messages: {
11
+ "define-style": "Style in defineStyle should be properly formatted",
12
+ "define-style-syntax-error": "Syntax error in defineStyle"
13
+ },
14
+ schema: [{
15
+ type: "object",
16
+ properties: { tabWidth: {
17
+ type: "number",
18
+ default: 2
19
+ } }
20
+ }]
21
+ },
22
+ create(context) {
23
+ const configuration = context.options[0] || {};
24
+ const tabWidth = configuration.tabWidth || 2;
25
+ return { CallExpression(node) {
26
+ const callee = node.callee.type === "MemberExpression" ? node.callee.object : node.callee;
27
+ const offset = callee.loc.start.column;
28
+ const parser = node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" ? node.callee.property.name : "css";
29
+ if (callee.type === "Identifier" && callee.name === "defineStyle") {
30
+ const arg = node.arguments[0];
31
+ if (arg?.type === "TemplateLiteral") {
32
+ const cssRaw = arg.quasis[0].value.raw;
33
+ let formattedCss = "";
34
+ try {
35
+ formattedCss = prettier.format(cssRaw, {
36
+ parser,
37
+ tabWidth
38
+ });
39
+ } catch {
40
+ return context.report({
41
+ node: arg,
42
+ messageId: "define-style-syntax-error"
43
+ });
44
+ }
45
+ const placeholder = " ".repeat(offset + tabWidth);
46
+ const result = `\n${placeholder}${formattedCss.slice(0, -1).replaceAll("\n", `\n${placeholder}`)}\n${" ".repeat(offset)}`;
47
+ if (result !== cssRaw) context.report({
48
+ node: arg,
49
+ messageId: "define-style",
50
+ fix(fixer) {
51
+ return fixer.replaceTextRange([arg.range[0] + 1, arg.range[1] - 1], result);
52
+ }
53
+ });
54
+ }
55
+ }
56
+ } };
57
+ }
74
58
  };
75
- var define_style_default = rule;
59
+ var define_style_default = rule$1;
76
60
 
77
- // src/rules/jsx-sort-props/index.ts
78
- var COMPAT_TAG_REGEX = /^[a-z]/;
61
+ //#endregion
62
+ //#region src/rules/jsx-sort-props/index.ts
63
+ const COMPAT_TAG_REGEX = /^[a-z]/;
64
+ /**
65
+ * Checks if a node represents a DOM element according to React.
66
+ * @param node - JSXOpeningElement to check.
67
+ * @returns Whether or not the node corresponds to a DOM element.
68
+ */
79
69
  function isDOMComponent(node) {
80
- const name = getElementType(node);
81
- return COMPAT_TAG_REGEX.test(name);
70
+ const name = getElementType(node);
71
+ return COMPAT_TAG_REGEX.test(name);
82
72
  }
73
+ /**
74
+ * Returns the name of the prop given the JSXAttribute object.
75
+ *
76
+ * Ported from `jsx-ast-utils/propName` to reduce bundle size
77
+ * @see https://github.com/jsx-eslint/jsx-ast-utils/blob/main/src/propName.js
78
+ */
83
79
  function getPropName(prop) {
84
- if (!prop.type || prop.type !== "JSXAttribute")
85
- throw new Error(
86
- "The prop must be a JSXAttribute collected by the AST parser."
87
- );
88
- if (prop.name.type === "JSXNamespacedName")
89
- return `${prop.name.namespace.name}:${prop.name.name.name}`;
90
- return prop.name.name;
80
+ if (!prop.type || prop.type !== "JSXAttribute") throw new Error("The prop must be a JSXAttribute collected by the AST parser.");
81
+ if (prop.name.type === "JSXNamespacedName") return `${prop.name.namespace.name}:${prop.name.name.name}`;
82
+ return prop.name.name;
91
83
  }
92
84
  function resolveMemberExpressions(object, property) {
93
- if (object.type === "JSXMemberExpression")
94
- return `${resolveMemberExpressions(object.object, object.property)}.${property.name}`;
95
- return `${object.name}.${property.name}`;
85
+ if (object.type === "JSXMemberExpression") return `${resolveMemberExpressions(object.object, object.property)}.${property.name}`;
86
+ return `${object.name}.${property.name}`;
96
87
  }
88
+ /**
89
+ * Returns the tagName associated with a JSXElement.
90
+ *
91
+ * Ported from `jsx-ast-utils/elementType` to reduce bundle size
92
+ * @see https://github.com/jsx-eslint/jsx-ast-utils/blob/main/src/elementType.js
93
+ */
97
94
  function getElementType(node) {
98
- if (node.type === "JSXOpeningFragment") return "<>";
99
- const { name } = node;
100
- if (!name) throw new Error("The argument provided is not a JSXElement node.");
101
- if (name.type === "JSXMemberExpression") {
102
- const { object, property } = name;
103
- return resolveMemberExpressions(object, property);
104
- }
105
- if (name.type === "JSXNamespacedName")
106
- return `${name.namespace.name}:${name.name.name}`;
107
- return node.name.name;
95
+ if (node.type === "JSXOpeningFragment") return "<>";
96
+ const { name } = node;
97
+ if (!name) throw new Error("The argument provided is not a JSXElement node.");
98
+ if (name.type === "JSXMemberExpression") {
99
+ const { object, property } = name;
100
+ return resolveMemberExpressions(object, property);
101
+ }
102
+ if (name.type === "JSXNamespacedName") return `${name.namespace.name}:${name.name.name}`;
103
+ return node.name.name;
108
104
  }
109
105
  function isCallbackPropName(name) {
110
- return /^on[A-Z]/.test(name);
106
+ return /^on[A-Z]/.test(name);
111
107
  }
112
108
  function isMultilineProp(node) {
113
- return node.loc.start.line !== node.loc.end.line;
109
+ return node.loc.start.line !== node.loc.end.line;
114
110
  }
115
- var messages = {
116
- listIsEmpty: "A customized reserved first list must not be empty",
117
- listReservedPropsFirst: "Reserved props must be listed before all other props",
118
- listReservedPropsLast: "Reserved props must be listed after all other props",
119
- listCallbacksLast: "Callbacks must be listed after all other props",
120
- listShorthandFirst: "Shorthand props must be listed before all other props",
121
- listShorthandLast: "Shorthand props must be listed after all other props",
122
- listMultilineFirst: "Multiline props must be listed before all other props",
123
- listMultilineLast: "Multiline props must be listed after all other props",
124
- sortPropsByAlpha: "Props should be sorted alphabetically"
111
+ const messages = {
112
+ listIsEmpty: "A customized reserved first list must not be empty",
113
+ listReservedPropsFirst: "Reserved props must be listed before all other props",
114
+ listReservedPropsLast: "Reserved props must be listed after all other props",
115
+ listCallbacksLast: "Callbacks must be listed after all other props",
116
+ listShorthandFirst: "Shorthand props must be listed before all other props",
117
+ listShorthandLast: "Shorthand props must be listed after all other props",
118
+ listMultilineFirst: "Multiline props must be listed before all other props",
119
+ listMultilineLast: "Multiline props must be listed after all other props",
120
+ sortPropsByAlpha: "Props should be sorted alphabetically"
125
121
  };
126
- var RESERVED_PROPS_LIST = [
127
- "children",
128
- "dangerouslySetInnerHTML",
129
- "key",
130
- "ref"
122
+ const RESERVED_PROPS_LIST = [
123
+ "children",
124
+ "dangerouslySetInnerHTML",
125
+ "key",
126
+ "ref"
131
127
  ];
132
128
  function getReservedPropIndex(name, list) {
133
- return list.indexOf(name.split(":")[0]);
129
+ return list.indexOf(name.split(":")[0]);
134
130
  }
135
- var attributeMap;
131
+ let attributeMap;
136
132
  function shouldSortToEnd(node) {
137
- const attr = attributeMap.get(node);
138
- return !!attr && !!attr.hasComment;
133
+ const attr = attributeMap.get(node);
134
+ return !!attr && !!attr.hasComment;
139
135
  }
140
136
  function contextCompare(a, b, options) {
141
- let aProp = getPropName(a);
142
- let bProp = getPropName(b);
143
- const aPropWithoutNamespace = aProp.split(":")[0];
144
- const bPropWithoutNamespace = bProp.split(":")[0];
145
- const aSortToEnd = shouldSortToEnd(a);
146
- const bSortToEnd = shouldSortToEnd(b);
147
- if (aSortToEnd && !bSortToEnd) return 1;
148
- if (!aSortToEnd && bSortToEnd) return -1;
149
- if (options.reservedFirst) {
150
- const aIndex = getReservedPropIndex(aProp, options.reservedList);
151
- const bIndex = getReservedPropIndex(bProp, options.reservedList);
152
- if (aIndex > -1 && bIndex === -1) return -1;
153
- if (aIndex === -1 && bIndex > -1) return 1;
154
- if (aIndex > -1 && bIndex > -1 && aPropWithoutNamespace !== bPropWithoutNamespace)
155
- return aIndex > bIndex ? 1 : -1;
156
- }
157
- if (options.reservedLast.length > 0) {
158
- const aLastIndex = getReservedPropIndex(aProp, options.reservedLast);
159
- const bLastIndex = getReservedPropIndex(bProp, options.reservedLast);
160
- if (aLastIndex > -1 && bLastIndex === -1) return 1;
161
- if (aLastIndex === -1 && bLastIndex > -1) return -1;
162
- if (aLastIndex > -1 && bLastIndex > -1 && aPropWithoutNamespace !== bPropWithoutNamespace)
163
- return aLastIndex > bLastIndex ? 1 : -1;
164
- }
165
- if (options.callbacksLast) {
166
- const aIsCallback = isCallbackPropName(aProp);
167
- const bIsCallback = isCallbackPropName(bProp);
168
- if (aIsCallback && !bIsCallback) return 1;
169
- if (!aIsCallback && bIsCallback) return -1;
170
- }
171
- if (options.shorthandFirst || options.shorthandLast) {
172
- const shorthandSign = options.shorthandFirst ? -1 : 1;
173
- if (!a.value && b.value) return shorthandSign;
174
- if (a.value && !b.value) return -shorthandSign;
175
- }
176
- if (options.multiline !== "ignore") {
177
- const multilineSign = options.multiline === "first" ? -1 : 1;
178
- const aIsMultiline = isMultilineProp(a);
179
- const bIsMultiline = isMultilineProp(b);
180
- if (aIsMultiline && !bIsMultiline) return multilineSign;
181
- if (!aIsMultiline && bIsMultiline) return -multilineSign;
182
- }
183
- if (options.noSortAlphabetically) return 0;
184
- const actualLocale = options.locale === "auto" ? void 0 : options.locale;
185
- if (options.ignoreCase) {
186
- aProp = aProp.toLowerCase();
187
- bProp = bProp.toLowerCase();
188
- return aProp.localeCompare(bProp, actualLocale);
189
- }
190
- if (aProp === bProp) return 0;
191
- if (options.locale === "auto") return aProp < bProp ? -1 : 1;
192
- return aProp.localeCompare(bProp, actualLocale);
137
+ let aProp = getPropName(a);
138
+ let bProp = getPropName(b);
139
+ const aPropWithoutNamespace = aProp.split(":")[0];
140
+ const bPropWithoutNamespace = bProp.split(":")[0];
141
+ const aSortToEnd = shouldSortToEnd(a);
142
+ const bSortToEnd = shouldSortToEnd(b);
143
+ if (aSortToEnd && !bSortToEnd) return 1;
144
+ if (!aSortToEnd && bSortToEnd) return -1;
145
+ if (options.reservedFirst) {
146
+ const aIndex = getReservedPropIndex(aProp, options.reservedList);
147
+ const bIndex = getReservedPropIndex(bProp, options.reservedList);
148
+ if (aIndex > -1 && bIndex === -1) return -1;
149
+ if (aIndex === -1 && bIndex > -1) return 1;
150
+ if (aIndex > -1 && bIndex > -1 && aPropWithoutNamespace !== bPropWithoutNamespace) return aIndex > bIndex ? 1 : -1;
151
+ }
152
+ if (options.reservedLast.length > 0) {
153
+ const aLastIndex = getReservedPropIndex(aProp, options.reservedLast);
154
+ const bLastIndex = getReservedPropIndex(bProp, options.reservedLast);
155
+ if (aLastIndex > -1 && bLastIndex === -1) return 1;
156
+ if (aLastIndex === -1 && bLastIndex > -1) return -1;
157
+ if (aLastIndex > -1 && bLastIndex > -1 && aPropWithoutNamespace !== bPropWithoutNamespace) return aLastIndex > bLastIndex ? 1 : -1;
158
+ }
159
+ if (options.callbacksLast) {
160
+ const aIsCallback = isCallbackPropName(aProp);
161
+ const bIsCallback = isCallbackPropName(bProp);
162
+ if (aIsCallback && !bIsCallback) return 1;
163
+ if (!aIsCallback && bIsCallback) return -1;
164
+ }
165
+ if (options.shorthandFirst || options.shorthandLast) {
166
+ const shorthandSign = options.shorthandFirst ? -1 : 1;
167
+ if (!a.value && b.value) return shorthandSign;
168
+ if (a.value && !b.value) return -shorthandSign;
169
+ }
170
+ if (options.multiline !== "ignore") {
171
+ const multilineSign = options.multiline === "first" ? -1 : 1;
172
+ const aIsMultiline = isMultilineProp(a);
173
+ const bIsMultiline = isMultilineProp(b);
174
+ if (aIsMultiline && !bIsMultiline) return multilineSign;
175
+ if (!aIsMultiline && bIsMultiline) return -multilineSign;
176
+ }
177
+ if (options.noSortAlphabetically) return 0;
178
+ const actualLocale = options.locale === "auto" ? void 0 : options.locale;
179
+ if (options.ignoreCase) {
180
+ aProp = aProp.toLowerCase();
181
+ bProp = bProp.toLowerCase();
182
+ return aProp.localeCompare(bProp, actualLocale);
183
+ }
184
+ if (aProp === bProp) return 0;
185
+ if (options.locale === "auto") return aProp < bProp ? -1 : 1;
186
+ return aProp.localeCompare(bProp, actualLocale);
193
187
  }
188
+ /**
189
+ * Create an array of arrays where each subarray is composed of attributes
190
+ * that are considered sortable.
191
+ * @param attributes
192
+ * @param context The context of the rule
193
+ */
194
194
  function getGroupsOfSortableAttributes(attributes, context) {
195
- const sourceCode = context.sourceCode;
196
- const sortableAttributeGroups = [];
197
- let groupCount = 0;
198
- function addtoSortableAttributeGroups(attribute) {
199
- sortableAttributeGroups[groupCount - 1].push(attribute);
200
- }
201
- for (let i = 0; i < attributes.length; i++) {
202
- const attribute = attributes[i];
203
- const nextAttribute = attributes[i + 1];
204
- const attributeline = attribute.loc.start.line;
205
- let comment = [];
206
- try {
207
- comment = sourceCode.getCommentsAfter(attribute);
208
- } catch {
209
- }
210
- const lastAttr = attributes[i - 1];
211
- const attrIsSpread = attribute.type === "JSXSpreadAttribute";
212
- if (!lastAttr || lastAttr.type === "JSXSpreadAttribute" && !attrIsSpread) {
213
- groupCount += 1;
214
- sortableAttributeGroups[groupCount - 1] = [];
215
- }
216
- if (!attrIsSpread) {
217
- if (comment.length === 0) {
218
- attributeMap.set(attribute, {
219
- end: attribute.range[1],
220
- hasComment: false
221
- });
222
- addtoSortableAttributeGroups(attribute);
223
- } else {
224
- const firstComment = comment[0];
225
- const commentline = firstComment.loc.start.line;
226
- if (comment.length === 1) {
227
- if (attributeline + 1 === commentline && nextAttribute) {
228
- attributeMap.set(attribute, {
229
- end: nextAttribute.range[1],
230
- hasComment: true
231
- });
232
- addtoSortableAttributeGroups(attribute);
233
- i += 1;
234
- } else if (attributeline === commentline) {
235
- if (firstComment.type === "Block" && nextAttribute) {
236
- attributeMap.set(attribute, {
237
- end: nextAttribute.range[1],
238
- hasComment: true
239
- });
240
- i += 1;
241
- } else if (firstComment.type === "Block") {
242
- attributeMap.set(attribute, {
243
- end: firstComment.range[1],
244
- hasComment: true
245
- });
246
- } else {
247
- attributeMap.set(attribute, {
248
- end: firstComment.range[1],
249
- hasComment: false
250
- });
251
- }
252
- addtoSortableAttributeGroups(attribute);
253
- }
254
- } else if (comment.length > 1 && attributeline + 1 === comment[1].loc.start.line && nextAttribute) {
255
- const commentNextAttribute = sourceCode.getCommentsAfter(nextAttribute);
256
- attributeMap.set(attribute, {
257
- end: nextAttribute.range[1],
258
- hasComment: true
259
- });
260
- if (commentNextAttribute.length === 1 && nextAttribute.loc.start.line === commentNextAttribute[0].loc.start.line) {
261
- attributeMap.set(attribute, {
262
- end: commentNextAttribute[0].range[1],
263
- hasComment: true
264
- });
265
- }
266
- addtoSortableAttributeGroups(attribute);
267
- i += 1;
268
- }
269
- }
270
- }
271
- }
272
- return sortableAttributeGroups;
195
+ const sourceCode = context.sourceCode;
196
+ const sortableAttributeGroups = [];
197
+ let groupCount = 0;
198
+ function addtoSortableAttributeGroups(attribute) {
199
+ sortableAttributeGroups[groupCount - 1].push(attribute);
200
+ }
201
+ for (let i = 0; i < attributes.length; i++) {
202
+ const attribute = attributes[i];
203
+ const nextAttribute = attributes[i + 1];
204
+ const attributeline = attribute.loc.start.line;
205
+ let comment = [];
206
+ try {
207
+ comment = sourceCode.getCommentsAfter(attribute);
208
+ } catch {}
209
+ const lastAttr = attributes[i - 1];
210
+ const attrIsSpread = attribute.type === "JSXSpreadAttribute";
211
+ if (!lastAttr || lastAttr.type === "JSXSpreadAttribute" && !attrIsSpread) {
212
+ groupCount += 1;
213
+ sortableAttributeGroups[groupCount - 1] = [];
214
+ }
215
+ if (!attrIsSpread) if (comment.length === 0) {
216
+ attributeMap.set(attribute, {
217
+ end: attribute.range[1],
218
+ hasComment: false
219
+ });
220
+ addtoSortableAttributeGroups(attribute);
221
+ } else {
222
+ const firstComment = comment[0];
223
+ const commentline = firstComment.loc.start.line;
224
+ if (comment.length === 1) {
225
+ if (attributeline + 1 === commentline && nextAttribute) {
226
+ attributeMap.set(attribute, {
227
+ end: nextAttribute.range[1],
228
+ hasComment: true
229
+ });
230
+ addtoSortableAttributeGroups(attribute);
231
+ i += 1;
232
+ } else if (attributeline === commentline) {
233
+ if (firstComment.type === "Block" && nextAttribute) {
234
+ attributeMap.set(attribute, {
235
+ end: nextAttribute.range[1],
236
+ hasComment: true
237
+ });
238
+ i += 1;
239
+ } else if (firstComment.type === "Block") attributeMap.set(attribute, {
240
+ end: firstComment.range[1],
241
+ hasComment: true
242
+ });
243
+ else attributeMap.set(attribute, {
244
+ end: firstComment.range[1],
245
+ hasComment: false
246
+ });
247
+ addtoSortableAttributeGroups(attribute);
248
+ }
249
+ } else if (comment.length > 1 && attributeline + 1 === comment[1].loc.start.line && nextAttribute) {
250
+ const commentNextAttribute = sourceCode.getCommentsAfter(nextAttribute);
251
+ attributeMap.set(attribute, {
252
+ end: nextAttribute.range[1],
253
+ hasComment: true
254
+ });
255
+ if (commentNextAttribute.length === 1 && nextAttribute.loc.start.line === commentNextAttribute[0].loc.start.line) attributeMap.set(attribute, {
256
+ end: commentNextAttribute[0].range[1],
257
+ hasComment: true
258
+ });
259
+ addtoSortableAttributeGroups(attribute);
260
+ i += 1;
261
+ }
262
+ }
263
+ }
264
+ return sortableAttributeGroups;
273
265
  }
274
266
  function generateFixerFunction(node, context, reservedList) {
275
- const sourceCode = context.sourceCode;
276
- const attributes = node.attributes.slice(0);
277
- const configuration = context.options[0] || {};
278
- const ignoreCase = configuration.ignoreCase || false;
279
- const callbacksLast = configuration.callbacksLast || false;
280
- const shorthandFirst = configuration.shorthandFirst || false;
281
- const shorthandLast = configuration.shorthandLast || false;
282
- const multiline = configuration.multiline || "ignore";
283
- const noSortAlphabetically = configuration.noSortAlphabetically || false;
284
- const reservedFirst = configuration.reservedFirst || false;
285
- const reservedLast = configuration.reservedLast || [];
286
- const locale = configuration.locale || "auto";
287
- const options = {
288
- ignoreCase,
289
- callbacksLast,
290
- shorthandFirst,
291
- shorthandLast,
292
- multiline,
293
- noSortAlphabetically,
294
- reservedFirst,
295
- reservedList,
296
- reservedLast,
297
- locale
298
- };
299
- const sortableAttributeGroups = getGroupsOfSortableAttributes(
300
- attributes,
301
- context
302
- );
303
- const sortedAttributeGroups = sortableAttributeGroups.slice(0).map((group) => [...group].sort((a, b) => contextCompare(a, b, options)));
304
- return function fixFunction(fixer) {
305
- const fixers = [];
306
- let source = sourceCode.getText();
307
- sortableAttributeGroups.forEach((sortableGroup, ii) => {
308
- sortableGroup.forEach((attr, jj) => {
309
- const sortedAttr = sortedAttributeGroups[ii][jj];
310
- const sortedAttrText = source.slice(
311
- sortedAttr.range[0],
312
- attributeMap.get(sortedAttr).end
313
- );
314
- fixers.push({
315
- range: [attr.range[0], attributeMap.get(attr).end],
316
- text: sortedAttrText
317
- });
318
- });
319
- });
320
- fixers.sort((a, b) => b.range[0] - a.range[0]);
321
- const firstFixer = fixers[0];
322
- const lastFixer = fixers.at(-1);
323
- const rangeStart = lastFixer ? lastFixer.range[0] : 0;
324
- const rangeEnd = firstFixer ? firstFixer.range[1] : -0;
325
- fixers.forEach((fix) => {
326
- source = `${source.slice(0, fix.range[0])}${fix.text}${source.slice(fix.range[1])}`;
327
- });
328
- return fixer.replaceTextRange(
329
- [rangeStart, rangeEnd],
330
- source.slice(rangeStart, rangeEnd)
331
- );
332
- };
267
+ const sourceCode = context.sourceCode;
268
+ const attributes = node.attributes.slice(0);
269
+ const configuration = context.options[0] || {};
270
+ const ignoreCase = configuration.ignoreCase || false;
271
+ const callbacksLast = configuration.callbacksLast || false;
272
+ const shorthandFirst = configuration.shorthandFirst || false;
273
+ const shorthandLast = configuration.shorthandLast || false;
274
+ const multiline = configuration.multiline || "ignore";
275
+ const noSortAlphabetically = configuration.noSortAlphabetically || false;
276
+ const reservedFirst = configuration.reservedFirst || false;
277
+ const reservedLast = configuration.reservedLast || [];
278
+ const locale = configuration.locale || "auto";
279
+ const options = {
280
+ ignoreCase,
281
+ callbacksLast,
282
+ shorthandFirst,
283
+ shorthandLast,
284
+ multiline,
285
+ noSortAlphabetically,
286
+ reservedFirst,
287
+ reservedList,
288
+ reservedLast,
289
+ locale
290
+ };
291
+ const sortableAttributeGroups = getGroupsOfSortableAttributes(attributes, context);
292
+ const sortedAttributeGroups = sortableAttributeGroups.slice(0).map((group) => [...group].sort((a, b) => contextCompare(a, b, options)));
293
+ return function fixFunction(fixer) {
294
+ const fixers = [];
295
+ let source = sourceCode.getText();
296
+ sortableAttributeGroups.forEach((sortableGroup, ii) => {
297
+ sortableGroup.forEach((attr, jj) => {
298
+ const sortedAttr = sortedAttributeGroups[ii][jj];
299
+ const sortedAttrText = source.slice(sortedAttr.range[0], attributeMap.get(sortedAttr).end);
300
+ fixers.push({
301
+ range: [attr.range[0], attributeMap.get(attr).end],
302
+ text: sortedAttrText
303
+ });
304
+ });
305
+ });
306
+ fixers.sort((a, b) => b.range[0] - a.range[0]);
307
+ const firstFixer = fixers[0];
308
+ const lastFixer = fixers.at(-1);
309
+ const rangeStart = lastFixer ? lastFixer.range[0] : 0;
310
+ const rangeEnd = firstFixer ? firstFixer.range[1] : -0;
311
+ fixers.forEach((fix) => {
312
+ source = `${source.slice(0, fix.range[0])}${fix.text}${source.slice(fix.range[1])}`;
313
+ });
314
+ return fixer.replaceTextRange([rangeStart, rangeEnd], source.slice(rangeStart, rangeEnd));
315
+ };
333
316
  }
317
+ /**
318
+ * Checks if the `reservedFirst` option is valid
319
+ * @param context The context of the rule
320
+ * @param reservedFirst The `reservedFirst` option
321
+ * @return {Function|undefined} If an error is detected, a function to generate the error message, otherwise, `undefined`
322
+ */
334
323
  function validateReservedFirstConfig(context, reservedFirst) {
335
- if (reservedFirst && Array.isArray(reservedFirst) && reservedFirst.length === 0) {
336
- return function Report(decl) {
337
- context.report({
338
- node: decl,
339
- messageId: "listIsEmpty"
340
- });
341
- };
342
- }
324
+ if (reservedFirst && Array.isArray(reservedFirst) && reservedFirst.length === 0) return function Report(decl) {
325
+ context.report({
326
+ node: decl,
327
+ messageId: "listIsEmpty"
328
+ });
329
+ };
343
330
  }
344
- var reportedNodeAttributes = /* @__PURE__ */ new WeakMap();
331
+ const reportedNodeAttributes = new WeakMap();
332
+ /**
333
+ * Check if the current node attribute has already been reported with the same error type
334
+ * if that's the case then we don't report a new error
335
+ * otherwise we report the error
336
+ * @param nodeAttribute The node attribute to be reported
337
+ * @param errorType The error type to be reported
338
+ * @param node The parent node for the node attribute
339
+ * @param context The context of the rule
340
+ * @param reservedList The list of reserved props
341
+ */
345
342
  function reportNodeAttribute(nodeAttribute, errorType, node, context, reservedList) {
346
- const errors = reportedNodeAttributes.get(nodeAttribute) || [];
347
- if (errors.includes(errorType)) return;
348
- errors.push(errorType);
349
- reportedNodeAttributes.set(nodeAttribute, errors);
350
- context.report({
351
- node: nodeAttribute.name ?? "",
352
- messageId: errorType,
353
- fix: generateFixerFunction(node, context, reservedList)
354
- });
343
+ const errors = reportedNodeAttributes.get(nodeAttribute) || [];
344
+ if (errors.includes(errorType)) return;
345
+ errors.push(errorType);
346
+ reportedNodeAttributes.set(nodeAttribute, errors);
347
+ context.report({
348
+ node: nodeAttribute.name ?? "",
349
+ messageId: errorType,
350
+ fix: generateFixerFunction(node, context, reservedList)
351
+ });
355
352
  }
356
- var rule2 = {
357
- defaultOptions: [
358
- {
359
- multiline: "ignore",
360
- locale: "auto"
361
- }
362
- ],
363
- meta: {
364
- type: "layout",
365
- docs: {
366
- description: "Enforce props alphabetical sorting"
367
- },
368
- fixable: "code",
369
- messages,
370
- schema: [
371
- {
372
- type: "object",
373
- properties: {
374
- // Whether callbacks (prefixed with "on") should be listed at the very end,
375
- // after all other props. Supersedes shorthandLast.
376
- callbacksLast: {
377
- type: "boolean"
378
- },
379
- // Whether shorthand properties (without a value) should be listed first
380
- shorthandFirst: {
381
- type: "boolean"
382
- },
383
- // Whether shorthand properties (without a value) should be listed last
384
- shorthandLast: {
385
- type: "boolean"
386
- },
387
- // Whether multiline properties should be listed first or last
388
- multiline: {
389
- type: "string",
390
- enum: ["ignore", "first", "last"],
391
- default: "ignore"
392
- },
393
- ignoreCase: {
394
- type: "boolean"
395
- },
396
- // Whether alphabetical sorting should be enforced
397
- noSortAlphabetically: {
398
- type: "boolean"
399
- },
400
- reservedFirst: {
401
- type: ["array", "boolean"]
402
- },
403
- reservedLast: {
404
- type: "array"
405
- },
406
- locale: {
407
- type: "string",
408
- default: "auto"
409
- }
410
- },
411
- additionalProperties: false
412
- }
413
- ]
414
- },
415
- create(context) {
416
- const configuration = context.options[0] || {};
417
- const ignoreCase = configuration.ignoreCase || false;
418
- const callbacksLast = configuration.callbacksLast || false;
419
- const shorthandFirst = configuration.shorthandFirst || false;
420
- const shorthandLast = configuration.shorthandLast || false;
421
- const multiline = configuration.multiline || "ignore";
422
- const noSortAlphabetically = configuration.noSortAlphabetically || false;
423
- const reservedFirst = configuration.reservedFirst || false;
424
- const reservedFirstError = validateReservedFirstConfig(
425
- context,
426
- reservedFirst
427
- );
428
- const reservedList = Array.isArray(reservedFirst) ? reservedFirst : RESERVED_PROPS_LIST;
429
- const reservedLastList = configuration.reservedLast || [];
430
- const locale = configuration.locale || "auto";
431
- return {
432
- Program() {
433
- attributeMap = /* @__PURE__ */ new WeakMap();
434
- },
435
- JSXOpeningElement(node) {
436
- const nodeReservedList = reservedFirst && !isDOMComponent(node) ? reservedList.filter((prop) => prop !== "dangerouslySetInnerHTML") : reservedList;
437
- node.attributes.reduce((memo, decl, idx, attrs) => {
438
- if (decl.type === "JSXSpreadAttribute") return attrs[idx + 1];
439
- let previousPropName = getPropName(memo);
440
- let currentPropName = getPropName(decl);
441
- const previousValue = memo.value;
442
- const currentValue = decl.value;
443
- const previousIsCallback = isCallbackPropName(previousPropName);
444
- const currentIsCallback = isCallbackPropName(currentPropName);
445
- if (ignoreCase) {
446
- previousPropName = previousPropName.toLowerCase();
447
- currentPropName = currentPropName.toLowerCase();
448
- }
449
- if (reservedFirst) {
450
- if (reservedFirstError) {
451
- reservedFirstError(decl);
452
- return memo;
453
- }
454
- const previousReservedIndex = getReservedPropIndex(
455
- previousPropName,
456
- nodeReservedList
457
- );
458
- const currentReservedIndex = getReservedPropIndex(
459
- currentPropName,
460
- nodeReservedList
461
- );
462
- if (previousReservedIndex > -1 && currentReservedIndex === -1)
463
- return decl;
464
- if (reservedFirst !== true && previousReservedIndex > currentReservedIndex || previousReservedIndex === -1 && currentReservedIndex > -1) {
465
- reportNodeAttribute(
466
- decl,
467
- "listReservedPropsFirst",
468
- node,
469
- context,
470
- nodeReservedList
471
- );
472
- return memo;
473
- }
474
- }
475
- if (reservedLastList.length > 0) {
476
- const previousReservedIndex = getReservedPropIndex(
477
- previousPropName,
478
- reservedLastList
479
- );
480
- const currentReservedIndex = getReservedPropIndex(
481
- currentPropName,
482
- reservedLastList
483
- );
484
- if (previousReservedIndex === -1 && currentReservedIndex > -1)
485
- return decl;
486
- if (previousReservedIndex < currentReservedIndex || previousReservedIndex > -1 && currentReservedIndex === -1) {
487
- reportNodeAttribute(
488
- decl,
489
- "listReservedPropsLast",
490
- node,
491
- context,
492
- nodeReservedList
493
- );
494
- return memo;
495
- }
496
- }
497
- if (callbacksLast) {
498
- if (!previousIsCallback && currentIsCallback) {
499
- return decl;
500
- }
501
- if (previousIsCallback && !currentIsCallback) {
502
- reportNodeAttribute(
503
- memo,
504
- "listCallbacksLast",
505
- node,
506
- context,
507
- nodeReservedList
508
- );
509
- return memo;
510
- }
511
- }
512
- if (shorthandFirst) {
513
- if (currentValue && !previousValue) return decl;
514
- if (!currentValue && previousValue) {
515
- reportNodeAttribute(
516
- decl,
517
- "listShorthandFirst",
518
- node,
519
- context,
520
- nodeReservedList
521
- );
522
- return memo;
523
- }
524
- }
525
- if (shorthandLast) {
526
- if (!currentValue && previousValue) return decl;
527
- if (currentValue && !previousValue) {
528
- reportNodeAttribute(
529
- memo,
530
- "listShorthandLast",
531
- node,
532
- context,
533
- nodeReservedList
534
- );
535
- return memo;
536
- }
537
- }
538
- const previousIsMultiline = isMultilineProp(memo);
539
- const currentIsMultiline = isMultilineProp(decl);
540
- if (multiline === "first") {
541
- if (previousIsMultiline && !currentIsMultiline) {
542
- return decl;
543
- }
544
- if (!previousIsMultiline && currentIsMultiline) {
545
- reportNodeAttribute(
546
- decl,
547
- "listMultilineFirst",
548
- node,
549
- context,
550
- nodeReservedList
551
- );
552
- return memo;
553
- }
554
- } else if (multiline === "last") {
555
- if (!previousIsMultiline && currentIsMultiline) {
556
- return decl;
557
- }
558
- if (previousIsMultiline && !currentIsMultiline) {
559
- reportNodeAttribute(
560
- memo,
561
- "listMultilineLast",
562
- node,
563
- context,
564
- nodeReservedList
565
- );
566
- return memo;
567
- }
568
- }
569
- if (!noSortAlphabetically && (ignoreCase || locale !== "auto" ? previousPropName.localeCompare(
570
- currentPropName,
571
- locale === "auto" ? void 0 : locale
572
- ) > 0 : previousPropName > currentPropName)) {
573
- reportNodeAttribute(
574
- decl,
575
- "sortPropsByAlpha",
576
- node,
577
- context,
578
- nodeReservedList
579
- );
580
- return memo;
581
- }
582
- return decl;
583
- }, node.attributes[0]);
584
- }
585
- };
586
- }
353
+ const rule = {
354
+ defaultOptions: [{
355
+ multiline: "ignore",
356
+ locale: "auto"
357
+ }],
358
+ meta: {
359
+ type: "layout",
360
+ docs: { description: "Enforce props alphabetical sorting" },
361
+ fixable: "code",
362
+ messages,
363
+ schema: [{
364
+ type: "object",
365
+ properties: {
366
+ callbacksLast: { type: "boolean" },
367
+ shorthandFirst: { type: "boolean" },
368
+ shorthandLast: { type: "boolean" },
369
+ multiline: {
370
+ type: "string",
371
+ enum: [
372
+ "ignore",
373
+ "first",
374
+ "last"
375
+ ],
376
+ default: "ignore"
377
+ },
378
+ ignoreCase: { type: "boolean" },
379
+ noSortAlphabetically: { type: "boolean" },
380
+ reservedFirst: { type: ["array", "boolean"] },
381
+ reservedLast: { type: "array" },
382
+ locale: {
383
+ type: "string",
384
+ default: "auto"
385
+ }
386
+ },
387
+ additionalProperties: false
388
+ }]
389
+ },
390
+ create(context) {
391
+ const configuration = context.options[0] || {};
392
+ const ignoreCase = configuration.ignoreCase || false;
393
+ const callbacksLast = configuration.callbacksLast || false;
394
+ const shorthandFirst = configuration.shorthandFirst || false;
395
+ const shorthandLast = configuration.shorthandLast || false;
396
+ const multiline = configuration.multiline || "ignore";
397
+ const noSortAlphabetically = configuration.noSortAlphabetically || false;
398
+ const reservedFirst = configuration.reservedFirst || false;
399
+ const reservedFirstError = validateReservedFirstConfig(context, reservedFirst);
400
+ const reservedList = Array.isArray(reservedFirst) ? reservedFirst : RESERVED_PROPS_LIST;
401
+ const reservedLastList = configuration.reservedLast || [];
402
+ const locale = configuration.locale || "auto";
403
+ return {
404
+ Program() {
405
+ attributeMap = new WeakMap();
406
+ },
407
+ JSXOpeningElement(node) {
408
+ const nodeReservedList = reservedFirst && !isDOMComponent(node) ? reservedList.filter((prop) => prop !== "dangerouslySetInnerHTML") : reservedList;
409
+ node.attributes.reduce((memo, decl, idx, attrs) => {
410
+ if (decl.type === "JSXSpreadAttribute") return attrs[idx + 1];
411
+ let previousPropName = getPropName(memo);
412
+ let currentPropName = getPropName(decl);
413
+ const previousValue = memo.value;
414
+ const currentValue = decl.value;
415
+ const previousIsCallback = isCallbackPropName(previousPropName);
416
+ const currentIsCallback = isCallbackPropName(currentPropName);
417
+ if (ignoreCase) {
418
+ previousPropName = previousPropName.toLowerCase();
419
+ currentPropName = currentPropName.toLowerCase();
420
+ }
421
+ if (reservedFirst) {
422
+ if (reservedFirstError) {
423
+ reservedFirstError(decl);
424
+ return memo;
425
+ }
426
+ const previousReservedIndex = getReservedPropIndex(previousPropName, nodeReservedList);
427
+ const currentReservedIndex = getReservedPropIndex(currentPropName, nodeReservedList);
428
+ if (previousReservedIndex > -1 && currentReservedIndex === -1) return decl;
429
+ if (reservedFirst !== true && previousReservedIndex > currentReservedIndex || previousReservedIndex === -1 && currentReservedIndex > -1) {
430
+ reportNodeAttribute(decl, "listReservedPropsFirst", node, context, nodeReservedList);
431
+ return memo;
432
+ }
433
+ }
434
+ if (reservedLastList.length > 0) {
435
+ const previousReservedIndex = getReservedPropIndex(previousPropName, reservedLastList);
436
+ const currentReservedIndex = getReservedPropIndex(currentPropName, reservedLastList);
437
+ if (previousReservedIndex === -1 && currentReservedIndex > -1) return decl;
438
+ if (previousReservedIndex < currentReservedIndex || previousReservedIndex > -1 && currentReservedIndex === -1) {
439
+ reportNodeAttribute(decl, "listReservedPropsLast", node, context, nodeReservedList);
440
+ return memo;
441
+ }
442
+ }
443
+ if (callbacksLast) {
444
+ if (!previousIsCallback && currentIsCallback) return decl;
445
+ if (previousIsCallback && !currentIsCallback) {
446
+ reportNodeAttribute(memo, "listCallbacksLast", node, context, nodeReservedList);
447
+ return memo;
448
+ }
449
+ }
450
+ if (shorthandFirst) {
451
+ if (currentValue && !previousValue) return decl;
452
+ if (!currentValue && previousValue) {
453
+ reportNodeAttribute(decl, "listShorthandFirst", node, context, nodeReservedList);
454
+ return memo;
455
+ }
456
+ }
457
+ if (shorthandLast) {
458
+ if (!currentValue && previousValue) return decl;
459
+ if (currentValue && !previousValue) {
460
+ reportNodeAttribute(memo, "listShorthandLast", node, context, nodeReservedList);
461
+ return memo;
462
+ }
463
+ }
464
+ const previousIsMultiline = isMultilineProp(memo);
465
+ const currentIsMultiline = isMultilineProp(decl);
466
+ if (multiline === "first") {
467
+ if (previousIsMultiline && !currentIsMultiline) return decl;
468
+ if (!previousIsMultiline && currentIsMultiline) {
469
+ reportNodeAttribute(decl, "listMultilineFirst", node, context, nodeReservedList);
470
+ return memo;
471
+ }
472
+ } else if (multiline === "last") {
473
+ if (!previousIsMultiline && currentIsMultiline) return decl;
474
+ if (previousIsMultiline && !currentIsMultiline) {
475
+ reportNodeAttribute(memo, "listMultilineLast", node, context, nodeReservedList);
476
+ return memo;
477
+ }
478
+ }
479
+ if (!noSortAlphabetically && (ignoreCase || locale !== "auto" ? previousPropName.localeCompare(currentPropName, locale === "auto" ? void 0 : locale) > 0 : previousPropName > currentPropName)) {
480
+ reportNodeAttribute(decl, "sortPropsByAlpha", node, context, nodeReservedList);
481
+ return memo;
482
+ }
483
+ return decl;
484
+ }, node.attributes[0]);
485
+ }
486
+ };
487
+ }
587
488
  };
588
- var jsx_sort_props_default = rule2;
489
+ var jsx_sort_props_default = rule;
589
490
 
590
- // src/rules/index.ts
591
- var ruleOptions = {
592
- "jsx-sort-props": jsx_sort_props_default,
593
- "define-style": define_style_default
491
+ //#endregion
492
+ //#region src/rules/index.ts
493
+ const ruleOptions = {
494
+ "jsx-sort-props": jsx_sort_props_default,
495
+ "define-style": define_style_default
594
496
  };
595
497
  var rules_default = ruleOptions;
596
498
 
597
- // src/index.ts
598
- var plugins = {
599
- "vue-jsx-vapor": {
600
- rules: rules_default
601
- }
602
- };
603
- var index_default = ({ rules = {}, ...options } = {}) => ({
604
- name: "vue-jsx-vapor",
605
- plugins,
606
- rules: {
607
- "style/jsx-sort-props": "off",
608
- "react/jsx-sort-props": "off",
609
- "vue-jsx-vapor/jsx-sort-props": rules["vue-jsx-vapor/jsx-sort-props"] || [
610
- "warn",
611
- {
612
- callbacksLast: true,
613
- shorthandFirst: true,
614
- reservedFirst: [
615
- "v-if",
616
- "v-else-if",
617
- "v-else",
618
- "v-for",
619
- "key",
620
- "ref",
621
- "v-model"
622
- ],
623
- reservedLast: ["v-text", "v-html", "v-slots", "v-slot"]
624
- }
625
- ],
626
- "vue-jsx-vapor/define-style": rules["vue-jsx-vapor/define-style"] || "warn"
627
- },
628
- ...options
499
+ //#endregion
500
+ //#region src/index.ts
501
+ const plugins = { "vue-jsx-vapor": { rules: rules_default } };
502
+ var src_default = ({ rules = {},...options } = {}) => ({
503
+ name: "vue-jsx-vapor",
504
+ plugins,
505
+ rules: {
506
+ "style/jsx-sort-props": "off",
507
+ "react/jsx-sort-props": "off",
508
+ "vue-jsx-vapor/jsx-sort-props": rules["vue-jsx-vapor/jsx-sort-props"] || ["warn", {
509
+ callbacksLast: true,
510
+ shorthandFirst: true,
511
+ reservedFirst: [
512
+ "v-if",
513
+ "v-else-if",
514
+ "v-else",
515
+ "v-for",
516
+ "key",
517
+ "ref",
518
+ "v-model"
519
+ ],
520
+ reservedLast: [
521
+ "v-text",
522
+ "v-html",
523
+ "v-slots",
524
+ "v-slot"
525
+ ]
526
+ }],
527
+ "vue-jsx-vapor/define-style": rules["vue-jsx-vapor/define-style"] || "warn"
528
+ },
529
+ ...options
629
530
  });
630
- export {
631
- index_default as default,
632
- plugins,
633
- rules_default as rules
634
- };
531
+
532
+ //#endregion
533
+ export { src_default as default, plugins, rules_default as rules };