{"record":{"id":"cbf98f826cb88ae4","repo":"oxc-project/oxc","slug":"don-t-use-array-reduce-and-array-reduceright","errorCode":null,"errorMessage":"Don't use `Array#reduce()` and `Array#reduceRight()`, use `for` loops instead.","messagePattern":"Don't use `Array#reduce\\(\\)` and `Array#reduceRight\\(\\)`, use `for` loops instead\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs","lineNumber":20,"sourceCode":"    AstKind,\n    ast::{Argument, CallExpression, Expression, Statement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    ast_util::is_method_call,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_prototype_property,\n};\n\nfn no_array_reduce_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Don't use `Array#reduce()` and `Array#reduceRight()`, use `for` loops instead.\",\n    )\n    .with_help(\"Refactor your code to use `for` loops instead.\")\n    .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoArrayReduce {\n    /// When set to `true`, allows simple operations (like summing numbers) in `reduce` and `reduceRight` calls.\n    pub allow_simple_operations: bool,\n}\n\nimpl Default for NoArrayReduce {\n    fn default() -> Self {\n        Self { allow_simple_operations: true }\n    }\n}","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs#L2-L38","documentation":"Raised by unicorn/no-array-reduce when `Array#reduce()` or `Array#reduceRight()` is used (prototype or instance call detected via is_method_call/is_prototype_property). The faulting input is the reduce call at the labeled span; the report is stylistic/complexity-driven, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs:20 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite the reduction as a `for…of` loop accumulating into a named variable","Use more specific combinators (map/filter/flatMap/some/every) when they express the intent","Disable the rule for the rare genuinely reduce-shaped case"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}