{"record":{"id":"4d0448c18815e23d","repo":"oxc-project/oxc","slug":"do-not-call-description-multiple-times","errorCode":null,"errorMessage":"Do not call `{description}` multiple times.","messagePattern":"Do not call `(.+?)` multiple times\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_single_call.rs","lineNumber":22,"sourceCode":"    AstKind,\n    ast::{CallExpression, Expression, Statement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::identifier::is_identifier_part;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::Fix,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn prefer_single_call_diagnostic(span: Span, description: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Do not call `{description}` multiple times.\"))\n        .with_help(\"Merge with the previous call.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(default, deny_unknown_fields)]\npub struct PreferSingleCallConfig {\n    /// Methods to ignore.\n    #[serde(default)]\n    ignore: Vec<String>,\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferSingleCall(Box<PreferSingleCallConfig>);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/oxc-project/oxc/blob/1f902a69625cd14e6d8dc58feca94da099d2d251/crates/oxc_linter/src/rules/unicorn/prefer_single_call.rs#L4-L40","documentation":"This is the oxlint rule `unicorn/prefer-single-call` (category `pedantic`, supersedes `unicorn/no-array-push-push`). It reports consecutive expression statements calling the same variadic method on the same receiver — `Array#push`/`unshift`, `Element#classList.add`/`remove`, and `importScripts()` — and asks you to merge them into one call, which is more concise and marginally faster.","triggerScenarios":"Two or more adjacent expression statements in the same statement list (block, program, function body, static block, or switch case) calling e.g. `foo.push(1); foo.push(2);`, `el.classList.add('a'); el.classList.add('b');`, or `importScripts('a.js'); importScripts('b.js');` with no intervening statements on that receiver. The `ignore` config option suppresses specific method names.","commonSituations":"Build scripts pushing into arrays line-by-line, DOM code adding classes one per line, worker bootstraps loading several scripts with repeated `importScripts`; teams enabling the whole `unicorn` preset during an ESLint-to-oxlint migration and hitting newly strict formatting of consecutive calls.","solutions":["Merge the calls: `foo.push(1, 2);`, `el.classList.add('a', 'b');`, `importScripts('a.js', 'b.js');` (for `unshift`, reverse the argument order to preserve semantics: `foo.unshift(2, 1);`).","Run `oxlint --fix` — the rule is auto-fixable and will merge the spans for you.","Add method names to the rule's `ignore` config if merging hurts readability or a receiver is a proxy with call-count side effects: `{ \"rules\": { \"unicorn/prefer-single-call\": [\"error\", { \"ignore\": [\"importScripts\"] }] } }`.","Disable the rule in `.oxlintrc.json` if your style guide prefers one call per line."],"exampleFix":"// before\nfoo.push(1);\nfoo.push(2);\nel.classList.add('a');\nel.classList.add('b');\n\n// after\nfoo.push(1, 2);\nel.classList.add('a', 'b');","handlingStrategy":"validation","validationCode":"// Write variadic calls merged from the start\nfoo.push(1, 2, 3);\nel.classList.add('a', 'b');\n// CI: npx oxlint --deny-warn unicorn/prefer-single-call src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Batch arguments into one variadic call when pushing/adding in sequence.","Use the `ignore` config for receivers with call-count side effects (proxies, analytics-instrumented objects).","Note `unshift` argument order reverses when merging — review autofixes on unshift chains."],"tags":["oxlint","unicorn","pedantic","code-style","variadic-methods"],"backgroundTag":"merge-consecutive-push-calls","analyzedSha":"1f902a69625cd14e6d8dc58feca94da099d2d251","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}