Skip to content

Commit 9fc6374

Browse files
authored
docs(linter): Add configuration option docs for eslint/no-misleading-character-class rule. (#15058)
These docs already existed, but weren't using the standard format. Part of #14743. Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### allowEscape type: `boolean` default: `false` When set to `true`, the rule allows any grouping of code points inside a character class as long as they are written using escape sequences. Examples of **incorrect** code for this rule with `{ "allowEscape": true }`: ```javascript /[\uD83D]/; // backslash can be omitted new RegExp("[\ud83d" + "\udc4d]"); ``` Examples of **correct** code for this rule with `{ "allowEscape": true }`: ```javascript /[\ud83d\udc4d]/; /[\u00B7\u0300-\u036F]/u; /[👨\u200d👩]/u; new RegExp("[\x41\u0301]"); new RegExp(`[\u{1F1EF}\u{1F1F5}]`, "u"); new RegExp("[\\u{1F1EF}\\u{1F1F5}]", "u"); ``` ```
1 parent be87ace commit 9fc6374

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use oxc_regular_expression::{
66
visit::{RegExpAstKind, Visit},
77
};
88
use oxc_span::Span;
9+
use schemars::JsonSchema;
910

1011
use crate::{AstNode, context::LintContext, rule::Rule, utils::run_on_regex_node};
1112

@@ -29,8 +30,27 @@ fn zwj_diagnostic(span: Span) -> OxcDiagnostic {
2930
OxcDiagnostic::warn("Unexpected joined character sequence in character class.").with_label(span)
3031
}
3132

32-
#[derive(Debug, Default, Clone)]
33+
#[derive(Debug, Default, Clone, JsonSchema)]
34+
#[serde(rename_all = "camelCase", default)]
3335
pub struct NoMisleadingCharacterClass {
36+
/// When set to `true`, the rule allows any grouping of code points
37+
/// inside a character class as long as they are written using escape sequences.
38+
///
39+
/// Examples of **incorrect** code for this rule with `{ "allowEscape": true }`:
40+
/// ```javascript
41+
/// /[\uD83D]/; // backslash can be omitted
42+
/// new RegExp("[\ud83d" + "\udc4d]");
43+
/// ```
44+
///
45+
/// Examples of **correct** code for this rule with `{ "allowEscape": true }`:
46+
/// ```javascript
47+
/// /[\ud83d\udc4d]/;
48+
/// /[\u00B7\u0300-\u036F]/u;
49+
/// /[👨\u200d👩]/u;
50+
/// new RegExp("[\x41\u0301]");
51+
/// new RegExp(`[\u{1F1EF}\u{1F1F5}]`, "u");
52+
/// new RegExp("[\\u{1F1EF}\\u{1F1F5}]", "u");
53+
/// ```
3454
allow_escape: bool,
3555
}
3656

@@ -77,32 +97,10 @@ declare_oxc_lint!(
7797
/// /[\u00B7\u0300-\u036F]/u;
7898
/// new RegExp("^[\u{1F1EF}\u{1F1F5}]", "u");
7999
/// ```
80-
///
81-
/// #### Options
82-
///
83-
/// This rule has an object option:
84-
///
85-
/// - `allowEscape`: When set to `true`, the rule allows any grouping of code points
86-
/// inside a character class as long as they are written using escape sequences.
87-
///
88-
/// Examples of **incorrect** code for this rule with `{ "allowEscape": true }`:
89-
/// ```javascript
90-
/// /[\uD83D]/; // backslash can be omitted
91-
/// new RegExp("[\ud83d" + "\udc4d]");
92-
/// ```
93-
///
94-
/// Examples of **correct** code for this rule with `{ "allowEscape": true }`:
95-
/// ```javascript
96-
/// /[\ud83d\udc4d]/;
97-
/// /[\u00B7\u0300-\u036F]/u;
98-
/// /[👨\u200d👩]/u;
99-
/// new RegExp("[\x41\u0301]");
100-
/// new RegExp(`[\u{1F1EF}\u{1F1F5}]`, "u");
101-
/// new RegExp("[\\u{1F1EF}\\u{1F1F5}]", "u");
102-
/// ```
103100
NoMisleadingCharacterClass,
104101
eslint,
105102
nursery, // TODO: change category to `correctness`, after oxc-project/oxc#13660 and oxc-project/oxc#13436
103+
config = NoMisleadingCharacterClass,
106104
);
107105

108106
#[derive(Debug)]

0 commit comments

Comments
 (0)