Skip to content

Commit c80da95

Browse files
connorsheaCopilot
andauthored
docs(linter): Add configuration docs to no-useless-escape lint rule. (#14791)
Also add missing text for "Why is this bad?" section. I've updated this to use the autogen docs rather than an explicit Options section, since that seems to be the preferred implementation path for this kind of addition. Part of #14743. Results in: ```md ## Configuration This rule accepts a configuration object with the following properties: ### allowRegexCharacters type: `string[]` default: `[]` An array of characters that are allowed to be escaped unnecessarily in regexes. ``` --------- Signed-off-by: Connor Shea <connor.james.shea@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7b64f27 commit c80da95

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use oxc_regular_expression::{
88
};
99
use oxc_semantic::NodeId;
1010
use oxc_span::Span;
11+
use schemars::JsonSchema;
1112

1213
use crate::{AstNode, context::LintContext, rule::Rule};
1314

@@ -26,18 +27,23 @@ impl std::ops::Deref for NoUselessEscape {
2627
}
2728
}
2829

29-
#[derive(Debug, Default, Clone)]
30+
#[derive(Debug, Default, Clone, JsonSchema)]
31+
#[serde(rename_all = "camelCase", default)]
3032
pub struct NoUselessEscapeConfig {
33+
/// An array of characters that are allowed to be escaped unnecessarily in regexes.
3134
allow_regex_characters: Vec<char>,
3235
}
3336

3437
declare_oxc_lint!(
3538
/// ### What it does
3639
///
37-
/// Disallow unnecessary escape characters
40+
/// Disallow unnecessary escape characters.
3841
///
3942
/// ### Why is this bad?
4043
///
44+
/// Escaping characters unnecessarily has no effect on the behavior of strings or regexes,
45+
/// and can make code harder to read and understand by adding unnecessary complexity.
46+
/// This applies to string literals, template literals, and regular expressions.
4147
///
4248
/// ### Examples
4349
///
@@ -81,7 +87,8 @@ declare_oxc_lint!(
8187
NoUselessEscape,
8288
eslint,
8389
correctness,
84-
fix
90+
fix,
91+
config = NoUselessEscapeConfig,
8592
);
8693

8794
impl Rule for NoUselessEscape {

0 commit comments

Comments
 (0)