Skip to content

Commit 9c01dbf

Browse files
committed
fix(linter): default options for eslint/new-cap (#12760)
https://eslint.org/docs/latest/rules/new-cap#options
1 parent 8854c1a commit 9c01dbf

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn new_cap_diagnostic(span: Span, cap: &GetCapResult) -> OxcDiagnostic {
2121
#[derive(Debug, Default, Clone)]
2222
pub struct NewCap(Box<NewCapConfig>);
2323

24-
#[derive(Debug, Default, Clone)]
24+
#[derive(Debug, Clone)]
2525
pub struct NewCapConfig {
2626
new_is_cap: bool,
2727
cap_is_new: bool,
@@ -32,6 +32,20 @@ pub struct NewCapConfig {
3232
properties: bool,
3333
}
3434

35+
impl Default for NewCapConfig {
36+
fn default() -> Self {
37+
Self {
38+
new_is_cap: true,
39+
cap_is_new: true,
40+
new_is_cap_exceptions: caps_allowed_vec(),
41+
new_is_cap_exception_pattern: None,
42+
cap_is_new_exceptions: vec![],
43+
cap_is_new_exception_pattern: None,
44+
properties: true,
45+
}
46+
}
47+
}
48+
3549
impl std::ops::Deref for NewCap {
3650
type Target = NewCapConfig;
3751

@@ -81,15 +95,7 @@ fn regex_serde_value(map: &serde_json::Map<String, serde_json::Value>, key: &str
8195
impl From<&serde_json::Value> for NewCap {
8296
fn from(raw: &serde_json::Value) -> Self {
8397
let Some(config_entry) = raw.get(0) else {
84-
return Self(Box::new(NewCapConfig {
85-
new_is_cap: true,
86-
cap_is_new: true,
87-
new_is_cap_exceptions: caps_allowed_vec(),
88-
new_is_cap_exception_pattern: None,
89-
cap_is_new_exceptions: vec![],
90-
cap_is_new_exception_pattern: None,
91-
properties: true,
92-
}));
98+
return Self(Box::default());
9399
};
94100

95101
let config = config_entry

crates/oxc_linter/tests/rule_configuration_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fn test_rule_default_matches_from_configuration_null() {
2525
// 1. The Default implementation returns the same values as from_configuration(null), or
2626
// 2. The from_configuration method is updated to return Default::default() when given null
2727
let exceptions = [
28-
"eslint/new-cap",
2928
"eslint/no-unneeded-ternary",
3029
"eslint/no-else-return",
3130
"import/extensions",

0 commit comments

Comments
 (0)