{"record":{"id":"69bc2fb8c74c7ce1","repo":"oxc-project/oxc","slug":"do-not-mix-core-module-file-and-computed-require","errorCode":null,"errorMessage":"Do not mix core, module, file and computed requires.","messagePattern":"Do not mix core, module, file and computed requires\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/node/no_mixed_requires.rs","lineNumber":23,"sourceCode":"    AstKind,\n    ast::{Expression, VariableDeclarator},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_mix_require_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not mix 'require' and other declarations.\").with_label(span)\n}\n\nfn no_mix_core_module_file_computed_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not mix core, module, file and computed requires.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Copy, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", deny_unknown_fields, default)]\nstruct NoMixedRequiresOptions {\n    grouping: bool,\n    allow_call: bool,\n}\n\n#[derive(Debug, Clone, Deserialize, JsonSchema)]\n#[serde(untagged)]\nenum NoMixedRequiresConfig {\n    Grouping(bool),\n    Options(NoMixedRequiresOptions),\n}\n\n#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]\npub struct NoMixedRequires(NoMixedRequiresOptions);","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/node/no_mixed_requires.rs#L5-L41","documentation":"Diagnostic from oxlint rule node/no-mixed-requires, emitted only when the grouping option is true. It requires each declaration to contain requires of a single kind: core modules (the BUILTIN_MODULES list frozen at Node v13.8.0 — fs, path, events...), file modules (specifiers starting with './', '../' or '/'), package modules (other string literals), or computed requires (non-literal or absent argument, e.g. require(getName())). Mixing kinds in one statement is the reported offense.","triggerScenarios":"Config \"node/no-mixed-requires\": [\"error\", { \"grouping\": true }] or the boolean shorthand [\"error\", true], plus a single declaration containing requires classified into two or more module types — e.g. var fs = require('fs'), foo = require('./foo'); (core + file) or var foo = require('foo'), bar = require(getName()); (module + computed). The base mixing check must NOT have fired first (it returns early), so the statement is all-requires but heterogeneous.","commonSituations":"Strict style configs inherited from eslint-plugin-n; legacy files where requires were appended in whatever order over years; caveat: the builtin list is dated, so modern specifiers like 'node:fs' or 'fs/promises' classify as 'module', not core.","solutions":["Group declarations by require kind: builtins together, relative files together, packages together, computed last","Prefer one require per line so grouping is explicit and diff-friendly","If the convention isn't worth the churn, set \"grouping\": false (the default) and only the mixing check remains"],"exampleFix":"// before (grouping: true)\nvar fs = require('fs'),\n    async = require('async'),\n    myUtils = require('./utils');\n\n// after: grouped by kind\nvar fs = require('fs');\nvar async = require('async');\nvar myUtils = require('./utils');","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n\"rules\": {\n  \"node/no-mixed-requires\": [\"error\", { \"grouping\": true, \"allowCall\": false }]\n}\n\nnpx oxlint -c .oxlintrc.json --deny-warning .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Order requires consistently (built-ins, then packages, then relative files) so grouping violations stand out in review","Remember the builtin list is frozen at Node v13.8.0 — modern specifiers like 'node:fs' count as package requires under this rule","Adopt one-require-per-line style; explicit grouping then comes free"],"tags":["node","commonjs","require","style","oxlint"],"backgroundTag":"ungrouped-require-imports","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"}