@vue-jsx-vapor/eslint 2.3.0 → 2.3.2

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