Files
SnowLuma/.pnpm-store/v11/files/93/df0c884408f4ce870850ed846075021c6f7114d2e28251ed5aed0ae5b4b97c9894ed5c7921bf9b91993b1784008da525ef1ce126b4a55853a3e1299cd35da8
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Skipped
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

63 lines
2.0 KiB
Plaintext

import { K as isSingleLine, f as createRule, g as import_ast_utils, o as isJSX } from "../utils.js";
function endWithComma(context, node) {
const nextToken = context.sourceCode.getTokenAfter(node);
return !!nextToken && nextToken.value === "," && nextToken.range[0] >= node.range[1];
}
var jsx_function_call_newline_default = createRule({
name: "jsx-function-call-newline",
meta: {
type: "layout",
docs: { description: "Enforce line breaks before and after JSX elements when they are used as arguments to a function." },
fixable: "whitespace",
schema: [{
type: "string",
enum: ["always", "multiline"]
}],
defaultOptions: ["multiline"],
messages: { missingLineBreak: "Missing line break around JSX" }
},
create(context, [option]) {
function needsOpeningNewLine(node) {
if ((0, import_ast_utils.isTokenOnSameLine)(context.sourceCode.getTokenBefore(node), node)) return true;
return false;
}
function needsClosingNewLine(node) {
const nextToken = context.sourceCode.getTokenAfter(node);
if (endWithComma(context, node)) return false;
if (node.loc.end.line === nextToken.loc.end.line) return true;
return false;
}
function check(node) {
if (!node || !isJSX(node)) return;
const sourceCode = context.sourceCode;
if (option === "always" || !isSingleLine(node)) {
const needsOpening = needsOpeningNewLine(node);
const needsClosing = needsClosingNewLine(node);
if (needsOpening || needsClosing) context.report({
node,
messageId: "missingLineBreak",
fix: (fixer) => {
let fixed = sourceCode.getText(node);
if (needsOpening) fixed = `\n${fixed}`;
if (needsClosing) fixed = `${fixed}\n`;
return fixer.replaceText(node, fixed);
}
});
}
}
function handleCallExpression(node) {
if (node.arguments.length === 0) return;
node.arguments.forEach(check);
}
return {
CallExpression(node) {
handleCallExpression(node);
},
NewExpression(node) {
handleCallExpression(node);
}
};
}
});
export { jsx_function_call_newline_default as t };