Files
renovate[bot]GitHubrenovate[bot] <29139614+renovate[bot]@users.noreply.github.com>fisker Cheungautofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
d8741b8eb9 Update ESLint related dependencies (major) (#18870)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: fisker Cheung <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-02-12 18:38:54 +08:00

52 lines
1.2 KiB
JavaScript

const selector = [
"CallExpression",
"[optional=false]",
'[callee.type="MemberExpression"]',
"[callee.computed=false]",
"[callee.optional=false]",
'[callee.property.type="Identifier"]',
'[callee.property.name="call"]',
"[arguments.length=1]",
'[arguments.0.type!="SpreadElement"]',
].join("");
const messageId = "no-unnecessary-ast-path-call";
export default {
meta: {
type: "suggestion",
messages: {
[messageId]: "Do not use `AstPath.call()` with one argument.",
},
fixable: "code",
},
create(context) {
const { sourceCode } = context;
return {
[selector](node) {
const problem = {
node,
messageId,
};
const [callback] = node.arguments;
// Don't fix to IIFE
if (
callback.type !== "ArrowFunctionExpression" &&
callback.type !== "FunctionExpression"
) {
problem.fix = function (fixer) {
const callbackText = sourceCode.getText(callback);
const astPathText = sourceCode.getText(node.callee.object);
return fixer.replaceText(node, `${callbackText}(${astPathText})`);
};
}
context.report(problem);
},
};
},
};