{"record":{"id":"01c8baaf06d06e1f","repo":"oxc-project/oxc","slug":"avoid-unnecessary-use-of-name","errorCode":null,"errorMessage":"Avoid unnecessary use of .{name}()","messagePattern":"Avoid unnecessary use of \\.(.+?)\\(\\)","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_call.rs","lineNumber":14,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{CallExpression, ChainElement, Expression, MemberExpression},\n    match_member_expression,\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::ContentEq;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_useless_call_diagnostic(name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Avoid unnecessary use of .{name}()\"))\n        .with_help(\"Replace with a normal function invocation\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessCall;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow unnecessary calls to `.call()` and `.apply()`\n    ///\n    /// ### Why is this bad?\n    ///\n    /// `Function.prototype.call()` and `Function.prototype.apply()` are slower than the normal function invocation.\n    ///\n    /// This rule compares code statically to check whether or not thisArg is changed.\n    /// So if the code about thisArg is a dynamic expression, this rule cannot judge correctly.","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_call.rs#L1-L32","documentation":"Diagnostic from the `no-useless-call` rule. It fires when `.call()` or `.apply()` adds nothing: the thisArg is null/undefined (or identical to the callee receiver) and apply's argument array is a plain spread of the same arguments a direct call would take. In strict-mode ES modules `this` is already undefined, so the indirection is pure overhead. Oxc detects it via `match_member_expression` on CallExpression whose callee property is `call`/`apply` on a plain function.","triggerScenarios":"Calls like `foo.call(null)`, `foo.call(undefined, 1)`, `foo.apply(this, arguments)` in non-method contexts, or `obj.fn.call(obj, ...)` where the receiver equals the object itself. The rule matches MemberExpression callees named call/apply whose arguments provide no binding effect.","commonSituations":"Code ported from ES5 libraries that needed apply for variadic args before spread syntax; defensive `this` binding habits; bundled output from old transpilers that was hand-edited.","solutions":["Replace `foo.call(null, 1, 2)` with a direct call `foo(1, 2)`.","Replace `foo.apply(null, args)` with `foo(...args)`.","If you rely on `this` binding, pass a meaningful thisArg or use `fn.bind(receiver)` once.","Fix is often automatic: run `oxlint --fix` to rewrite the call."],"exampleFix":"// before\nfoo.call(null, 1, 2);\nfoo.apply(undefined, [1, 2]);\n\n// after\nfoo(1, 2);\nfoo(1, 2);","handlingStrategy":"validation","validationCode":"function isUselessCall(node) {\n  // before refactoring, detect .call(null/undefined, ...) patterns in review\n  return /^\\.call\\((null|undefined)/.test(snippet) || /^\\.apply\\((null|undefined),\\s*\\[/.test(snippet);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call functions directly; use spread `f(...args)` instead of apply.","Reserve .call/.apply for actual this-binding with a real receiver.","Run `oxlint --fix` in pre-commit to strip useless calls mechanically."],"tags":["lint","eslint","oxlint","javascript","function-calls"],"backgroundTag":"no-useless-call-apply","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}