mirror of
https://github.com/hanzoai/prettier.git
synced 2026-09-24 17:02:04 +00:00
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>
52 lines
1.2 KiB
JavaScript
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);
|
|
},
|
|
};
|
|
},
|
|
};
|