Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions crates/oxc_linter/src/rules/unicorn/no_array_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use oxc_ast::{
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::Value;

use crate::{AstNode, context::LintContext, rule::Rule};
Expand All @@ -15,8 +17,16 @@ fn no_array_sort_diagnostic(span: Span) -> OxcDiagnostic {
.with_label(span)
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default)]
pub struct NoArraySort {
/// When set to `true` (default), allows `array.sort()` as an expression statement.
/// Set to `false` to forbid `Array#sort()` even if it's an expression statement.
///
/// Example of **incorrect** code for this rule with `allowExpressionStatement` set to `false`:
/// ```js
/// array.sort();
/// ```
allow_expression_statement: bool,
}

Expand Down Expand Up @@ -47,24 +57,11 @@ declare_oxc_lint!(
/// ```js
/// const sorted = [...array].toSorted();
/// ```
///
/// ### Options
///
/// #### allowExpressionStatement
///
/// `{ type: boolean, default: true }`
///
/// This rule allows `array.sort()` as an expression statement by default,
/// Pass allowExpressionStatement: false to forbid `Array#sort()` even if it's an expression statement.
///
/// Examples of **incorrect** code for this rule with the `{ "allowExpressionStatement": false }` option:
/// ```js
/// array.sort();
/// ```
NoArraySort,
unicorn,
suspicious,
fix,
config = NoArraySort,
);

impl Rule for NoArraySort {
Expand Down
Loading