Files
SnowLuma/.pnpm-store/v11/files/14/9b6f2d23493236255dc829fe4e31e8d1f868837b5a4759496d4a66389c678e4b36e1c457d5b95db6839e19a02ea944b9aa85ffd3ae25d26f6a307d4704e7df
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

50 lines
1.7 KiB
Plaintext

import { K as isSingleLine, f as createRule } from "../utils.js";
var jsx_first_prop_new_line_default = createRule({
name: "jsx-first-prop-new-line",
meta: {
type: "layout",
docs: { description: "Enforce proper position of the first property in JSX" },
fixable: "code",
schema: [{
type: "string",
enum: [
"always",
"never",
"multiline",
"multiline-multiprop",
"multiprop"
]
}],
defaultOptions: ["multiline-multiprop"],
messages: {
propOnNewLine: "Property should be placed on a new line",
propOnSameLine: "Property should be placed on the same line as the component declaration"
}
},
create(context, [configuration]) {
return { JSXOpeningElement(node) {
if (configuration === "multiline" && !isSingleLine(node) || configuration === "multiline-multiprop" && !isSingleLine(node) && node.attributes.length > 1 || configuration === "multiprop" && node.attributes.length > 1 || configuration === "always") node.attributes.some((decl) => {
if (decl.loc.start.line === node.loc.start.line) context.report({
node: decl,
messageId: "propOnNewLine",
fix(fixer) {
return fixer.replaceTextRange([(node.typeArguments || node.name).range[1], decl.range[0]], "\n");
}
});
return true;
});
else if (configuration === "never" && node.attributes.length > 0 || configuration === "multiprop" && !isSingleLine(node) && node.attributes.length <= 1) {
const firstNode = node.attributes[0];
if (node.loc.start.line < firstNode.loc.start.line) context.report({
node: firstNode,
messageId: "propOnSameLine",
fix(fixer) {
return fixer.replaceTextRange([node.name.range[1], firstNode.range[0]], " ");
}
});
}
} };
}
});
export { jsx_first_prop_new_line_default as t };