{"record":{"id":"61e9f5aba8237000","repo":"oxc-project/oxc","slug":"use-array-toreversed-instead-of-array-reverse","errorCode":null,"errorMessage":"Use `Array#toReversed()` instead of `Array#reverse()`.","messagePattern":"Use `Array#toReversed\\(\\)` instead of `Array#reverse\\(\\)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_array_reverse.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{ArrayExpressionElement, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_array_reverse_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `Array#toReversed()` instead of `Array#reverse()`.\")\n        .with_help(\"`Array#reverse()` mutates the original array. Use `Array#toReversed()` to return a new reversed array without modifying the original.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoArrayReverse {\n    /// This rule allows `array.reverse()` as an expression statement by default.\n    /// Set to `false` to forbid `Array#reverse()` even if it's an expression statement.\n    ///\n    /// Examples of **incorrect** code for this rule with this option set to `false`:\n    /// ```js\n    /// array.reverse();\n    /// ```\n    allow_expression_statement: bool,\n}\n\nimpl Default for NoArrayReverse {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_array_reverse.rs#L1-L37","documentation":"Raised by unicorn/no-array-reverse when `Array#reverse()` is called on an array (with ES2023 available). Because `reverse()` mutates in place, the rule suggests the copying variant; the faulting input is the `.reverse()` call at the labeled span.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_array_reverse.rs:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use `array.toReversed()` which returns a new reversed array without mutating the original","Spread-then-reverse (`[...array].reverse()`) when targeting older runtimes"],"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"}