{"record":{"id":"5e2bef9f97b40572","repo":"oxc-project/oxc","slug":"function-parameter-s-use-the-done-argument","errorCode":null,"errorMessage":"Function parameter(s) use the `done` argument","messagePattern":"Function parameter\\(s\\) use the `done` argument","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/no_done_callback.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, CallExpression, Expression, FormalParameters},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    rule::Rule,\n    utils::{\n        JestFnKind, JestGeneralFnKind, PossibleJestNode, get_node_name, parse_general_jest_fn_call,\n    },\n};\n\nfn no_done_callback(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Function parameter(s) use the `done` argument\")\n        .with_help(\"Return a Promise instead of relying on callback parameter\")\n        .with_label(span)\n}\n\nfn use_await_instead_of_callback(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Function parameter(s) use the `done` argument\")\n        .with_help(\"Use await instead of callback in async functions\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDoneCallback;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule checks the function parameter of hooks & tests for use of the done argument, suggesting you return a promise instead.\n    ///","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/no_done_callback.rs#L1-L36","documentation":"This is the sync variant of oxlint's 'jest/no-done-callback' diagnostic. It fires when the function passed to a Jest test, hook (beforeEach/afterAll/...), or custom test-block function declares a parameter named 'done'. Jest's callback style is error-prone (forgotten done() calls hang tests, assertions after done() are skipped), so the rule tells you to return a Promise instead; the help text for this variant is 'Return a Promise instead of relying on callback parameter'.","triggerScenarios":"Enable the rule and lint a file where parse_general_jest_fn_call recognizes it(...)/test(...)/xdescribe hooks etc. and the callback function's parameter list contains an identifier named 'done'. The diagnostic is raised on the function parameters.","commonSituations":"Legacy test suites written before async/await used done for async assertions; enabling stricter Jest presets (eslint-plugin-jest parity) during a migration flags them in bulk. Also triggered by parameter names that merely shadow 'done' in helper-wrapped test functions.","solutions":["Rewrite the test to return a Promise: it('loads', () => fetch(url).then(res => expect(res.ok).toBe(true))).","Or convert to async/await: it('loads', async () => { const res = await fetch(url); expect(res.ok).toBe(true); }).","If the callback genuinely signals completion from an event, wrap the event in a Promise and return it.","Suppress one legacy test with // oxlint-disable-next-line jest/no-done-callback while migrating."],"exampleFix":"// before\nit('loads user', (done) => {\n  loadUser(1, (err, user) => {\n    expect(user.name).toBe('a');\n    done();\n  });\n});\n\n// after\nit('loads user', () => {\n  return new Promise((resolve, reject) => {\n    loadUser(1, (err, user) => {\n      if (err) reject(err);\n      else expect(user.name).toBe('a');\n      resolve();\n    });\n  });\n});","handlingStrategy":"validation","validationCode":"// list test/hook callbacks declaring a done parameter\nconst { execSync } = require('node:child_process');\nconsole.log(execSync(\"rg -n '\\\\((\\\\w+,\\\\s*)?done(,\\\\s*\\\\w+)?\\\\)\\\\s*=>' tests/ ; rg -n 'function\\\\s*\\\\((\\\\w+,\\\\s*)?done' tests/\", { encoding: 'utf8' }));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write new tests async-first: no done parameter, only async/await or returned Promises.","When migrating legacy suites, convert done-style tests in small batches and delete the parameter.","Enable jest/no-done-callback early in a project so callback style never accumulates."],"tags":["lint","jest","testing","async","callback","oxlint"],"backgroundTag":"jest-done-callback","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"}