Files
SnowLuma/.pnpm-store/v11/files/6c/97fd6ba0f477c083dcf21f449aabd99a3287ad7a4988b677f5a2ed6baef75d78d596ed4a83ea374958856727890a7d38afe96c7c755cfda9575e01eb0bd6a1
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

40 lines
1.5 KiB
Plaintext

import { d as safeReplaceTextBetween, f as createRule, g as import_ast_utils } from "../utils.js";
var implicit_arrow_linebreak_default = createRule({
name: "implicit-arrow-linebreak",
meta: {
type: "layout",
docs: { description: "Enforce the location of arrow function bodies" },
fixable: "whitespace",
schema: [{
type: "string",
enum: ["beside", "below"]
}],
defaultOptions: ["beside"],
messages: {
expected: "Expected a linebreak before this expression.",
unexpected: "Expected no linebreak before this expression."
}
},
create(context, [option]) {
const sourceCode = context.sourceCode;
function validateExpression(node) {
if (node.body.type === "BlockStatement") return;
const arrowToken = sourceCode.getTokenBefore(node.body, import_ast_utils.isNotOpeningParenToken);
const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken);
const onSameLine = (0, import_ast_utils.isTokenOnSameLine)(arrowToken, firstTokenOfBody);
if (onSameLine && option === "below") context.report({
node: firstTokenOfBody,
messageId: "expected",
fix: (fixer) => fixer.insertTextBefore(firstTokenOfBody, "\n")
});
else if (!onSameLine && option === "beside") context.report({
node: firstTokenOfBody,
messageId: "unexpected",
fix: safeReplaceTextBetween(sourceCode, arrowToken, firstTokenOfBody, " ")
});
}
return { ArrowFunctionExpression: (node) => validateExpression(node) };
}
});
export { implicit_arrow_linebreak_default as t };