Skip to content

Commit ace4def

Browse files
connorsheaCopilot
andauthored
docs(linter): Add configuration option docs for unicorn/no-array-reverse rule. (#15143)
Part of #14743. Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### allowExpressionStatement type: `boolean` default: `true` This rule allow `array.reverse()` as an expression statement by default. Set to `false` to forbid `Array#reverse()` even if it's an expression statement. Examples of **incorrect** code for this rule with this option set to `false`: \```js array.reverse(); \``` ``` --------- Signed-off-by: Connor Shea <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent f707fc9 commit ace4def

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

crates/oxc_linter/src/rules/unicorn/no_array_reverse.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use oxc_ast::{
55
use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
77
use oxc_span::Span;
8+
use schemars::JsonSchema;
89
use serde_json::Value;
910

1011
use crate::{AstNode, context::LintContext, rule::Rule};
@@ -15,8 +16,16 @@ fn no_array_reverse_diagnostic(span: Span) -> OxcDiagnostic {
1516
.with_label(span)
1617
}
1718

18-
#[derive(Debug, Clone)]
19+
#[derive(Debug, Clone, JsonSchema)]
20+
#[serde(rename_all = "camelCase", default)]
1921
pub struct NoArrayReverse {
22+
/// This rule allows `array.reverse()` as an expression statement by default.
23+
/// Set to `false` to forbid `Array#reverse()` even if it's an expression statement.
24+
///
25+
/// Examples of **incorrect** code for this rule with this option set to `false`:
26+
/// ```js
27+
/// array.reverse();
28+
/// ```
2029
allow_expression_statement: bool,
2130
}
2231

@@ -47,24 +56,11 @@ declare_oxc_lint!(
4756
/// ```js
4857
/// const reversed = [...array].toReversed();
4958
/// ```
50-
///
51-
/// ### Options
52-
///
53-
/// #### allowExpressionStatement
54-
///
55-
/// `{ type: boolean, default: true }`
56-
///
57-
/// This rule allow `array.reverse()` as an expression statement by default,
58-
/// Pass allowExpressionStatement: false to forbid `Array#reverse()` even it's an expression statement.
59-
///
60-
/// Examples of **incorrect** code for this rule with the `{ "allowExpressionStatement": false }` option:
61-
/// ```js
62-
/// array.reverse();
63-
/// ```
6459
NoArrayReverse,
6560
unicorn,
6661
suspicious,
6762
fix,
63+
config = NoArrayReverse,
6864
);
6965

7066
impl Rule for NoArrayReverse {

0 commit comments

Comments
 (0)