@vue-jsx-vapor/eslint 2.3.0
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/LICENSE +21 -0
- package/dist/index.cjs +634 -0
- package/dist/index.d.cts +82 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +634 -0
- package/package.json +63 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
// src/rules/define-style/index.ts
|
|
2
|
+
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
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var define_style_default = rule;
|
|
76
|
+
|
|
77
|
+
// src/rules/jsx-sort-props/index.ts
|
|
78
|
+
var COMPAT_TAG_REGEX = /^[a-z]/;
|
|
79
|
+
function isDOMComponent(node) {
|
|
80
|
+
const name = getElementType(node);
|
|
81
|
+
return COMPAT_TAG_REGEX.test(name);
|
|
82
|
+
}
|
|
83
|
+
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;
|
|
91
|
+
}
|
|
92
|
+
function resolveMemberExpressions(object, property) {
|
|
93
|
+
if (object.type === "JSXMemberExpression")
|
|
94
|
+
return `${resolveMemberExpressions(object.object, object.property)}.${property.name}`;
|
|
95
|
+
return `${object.name}.${property.name}`;
|
|
96
|
+
}
|
|
97
|
+
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;
|
|
108
|
+
}
|
|
109
|
+
function isCallbackPropName(name) {
|
|
110
|
+
return /^on[A-Z]/.test(name);
|
|
111
|
+
}
|
|
112
|
+
function isMultilineProp(node) {
|
|
113
|
+
return node.loc.start.line !== node.loc.end.line;
|
|
114
|
+
}
|
|
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"
|
|
125
|
+
};
|
|
126
|
+
var RESERVED_PROPS_LIST = [
|
|
127
|
+
"children",
|
|
128
|
+
"dangerouslySetInnerHTML",
|
|
129
|
+
"key",
|
|
130
|
+
"ref"
|
|
131
|
+
];
|
|
132
|
+
function getReservedPropIndex(name, list) {
|
|
133
|
+
return list.indexOf(name.split(":")[0]);
|
|
134
|
+
}
|
|
135
|
+
var attributeMap;
|
|
136
|
+
function shouldSortToEnd(node) {
|
|
137
|
+
const attr = attributeMap.get(node);
|
|
138
|
+
return !!attr && !!attr.hasComment;
|
|
139
|
+
}
|
|
140
|
+
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);
|
|
193
|
+
}
|
|
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;
|
|
273
|
+
}
|
|
274
|
+
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
|
+
};
|
|
333
|
+
}
|
|
334
|
+
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
|
+
}
|
|
343
|
+
}
|
|
344
|
+
var reportedNodeAttributes = /* @__PURE__ */ new WeakMap();
|
|
345
|
+
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
|
+
});
|
|
355
|
+
}
|
|
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
|
+
}
|
|
587
|
+
};
|
|
588
|
+
var jsx_sort_props_default = rule2;
|
|
589
|
+
|
|
590
|
+
// src/rules/index.ts
|
|
591
|
+
var ruleOptions = {
|
|
592
|
+
"jsx-sort-props": jsx_sort_props_default,
|
|
593
|
+
"define-style": define_style_default
|
|
594
|
+
};
|
|
595
|
+
var rules_default = ruleOptions;
|
|
596
|
+
|
|
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
|
|
629
|
+
});
|
|
630
|
+
export {
|
|
631
|
+
index_default as default,
|
|
632
|
+
plugins,
|
|
633
|
+
rules_default as rules
|
|
634
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vue-jsx-vapor/eslint",
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Vue JSX Vapor ESLint Plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vue",
|
|
8
|
+
"jsx",
|
|
9
|
+
"vapor",
|
|
10
|
+
"eslint"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"homepage": "https://github.com/vuejs/vue-jsx-vapor#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/vuejs/vue-jsx-vapor/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/vuejs/vue-jsx-vapor.git"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"main": "dist/index.cjs",
|
|
25
|
+
"module": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"dev": "./src/index.ts",
|
|
30
|
+
"require": "./dist/index.cjs",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./*": "./*"
|
|
34
|
+
},
|
|
35
|
+
"typesVersions": {
|
|
36
|
+
"*": {
|
|
37
|
+
"*": [
|
|
38
|
+
"./dist/*",
|
|
39
|
+
"./*"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
".": {
|
|
45
|
+
"require": "./dist/index.cjs",
|
|
46
|
+
"import": "./dist/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./*": "./*"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@prettier/sync": "^0.5.5"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@typescript-eslint/utils": "^8.29.1",
|
|
55
|
+
"eslint-vitest-rule-tester": "^2.2.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"dev": "DEV=true tsup",
|
|
60
|
+
"release": "bumpp && npm publish",
|
|
61
|
+
"test": "vitest"
|
|
62
|
+
}
|
|
63
|
+
}
|