Files
SnowLuma/.pnpm-store/v11/files/59/2cf1a1bbc492c56da1eb208ecafb385675f90ded01aa0db70bde72e7c14106e792a81677c6ccdd38b9394daa74f1f43b935a719248936574d5755737a44b25
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

42 lines
1.3 KiB
Plaintext

import { U as isParenthesised, f as createRule } from "../utils.js";
function isConditional(node) {
return node.type === "ConditionalExpression";
}
var no_confusing_arrow_default = createRule({
name: "no-confusing-arrow",
meta: {
type: "layout",
docs: { description: "Disallow arrow functions where they could be confused with comparisons" },
fixable: "code",
schema: [{
type: "object",
properties: {
allowParens: { type: "boolean" },
onlyOneSimpleParam: { type: "boolean" }
},
additionalProperties: false
}],
defaultOptions: [{
allowParens: true,
onlyOneSimpleParam: false
}],
messages: { confusing: "Arrow function used ambiguously with a conditional expression." }
},
create(context, [options]) {
const { allowParens, onlyOneSimpleParam } = options;
const sourceCode = context.sourceCode;
function checkArrowFunc(node) {
const body = node.body;
if (isConditional(body) && !(allowParens && isParenthesised(sourceCode, body)) && !(onlyOneSimpleParam && !(node.params.length === 1 && node.params[0].type === "Identifier"))) context.report({
node,
messageId: "confusing",
fix(fixer) {
return allowParens ? fixer.replaceText(node.body, `(${sourceCode.getText(node.body)})`) : null;
}
});
}
return { ArrowFunctionExpression: checkArrowFunc };
}
});
export { no_confusing_arrow_default as t };