Skip to content

Commit 13f985c

Browse files
committed
fix(linter): Fix casing for unicorn/explicit-length-check config option. (#16269)
[The original rule](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/explicit-length-check.md) has it cased as `non-zero` but we were using camelCase `nonZero`. This change fixes the config option docs and also ensures that rules are deserialized more simply.
1 parent 99281bc commit 13f985c

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
1212
use crate::{
1313
AstNode,
1414
context::LintContext,
15-
rule::Rule,
15+
rule::{DefaultRuleConfig, Rule},
1616
utils::{get_boolean_ancestor, is_boolean_call, is_boolean_node},
1717
};
1818

@@ -45,16 +45,8 @@ enum NonZero {
4545
NotEqual,
4646
}
4747

48-
impl NonZero {
49-
pub fn from(raw: &str) -> Self {
50-
match raw {
51-
"not-equal" => Self::NotEqual,
52-
_ => Self::GreaterThan,
53-
}
54-
}
55-
}
56-
#[derive(Debug, Default, Clone, JsonSchema)]
57-
#[serde(rename_all = "camelCase", default)]
48+
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
49+
#[serde(rename_all = "kebab-case", default)]
5850
pub struct ExplicitLengthCheck {
5951
/// Configuration option to specify how non-zero length checks should be enforced.
6052
///
@@ -271,7 +263,14 @@ impl ExplicitLengthCheck {
271263
}
272264
}
273265
}
266+
274267
impl Rule for ExplicitLengthCheck {
268+
fn from_configuration(value: serde_json::Value) -> Self {
269+
serde_json::from_value::<DefaultRuleConfig<ExplicitLengthCheck>>(value)
270+
.unwrap_or_default()
271+
.into_inner()
272+
}
273+
275274
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
276275
if let AstKind::StaticMemberExpression(static_member_expr) = node.kind() {
277276
let StaticMemberExpression { object, property, .. } = static_member_expr;
@@ -309,17 +308,6 @@ impl Rule for ExplicitLengthCheck {
309308
}
310309
}
311310
}
312-
313-
fn from_configuration(value: serde_json::Value) -> Self {
314-
Self {
315-
non_zero: value
316-
.get(0)
317-
.and_then(|v| v.get("non-zero"))
318-
.and_then(serde_json::Value::as_str)
319-
.map(NonZero::from)
320-
.unwrap_or_default(),
321-
}
322-
}
323311
}
324312

325313
#[test]

0 commit comments

Comments
 (0)