Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/invalid_config_complex_enum/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": ["react"],
"categories": {
"correctness": "off"
},
"rules": {
// Invalid config, valid options are "syntax" or "element" (or an object).
"react/jsx-fragments": ["error", "somethingelse"]
}
}
7 changes: 7 additions & 0 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,4 +1517,11 @@ export { redundant };
fn test_valid_complex_config() {
Tester::new().with_cwd("fixtures/valid_complex_config".into()).test_and_snapshot(&[]);
}

#[test]
fn test_invalid_config_invalid_config_complex_enum() {
Tester::new()
.with_cwd("fixtures/invalid_config_complex_enum".into())
.test_and_snapshot(&[]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments:
working directory: fixtures/invalid_config_complex_enum
----------
Failed to parse oxlint configuration file.

x Invalid configuration for rule `react/jsx-fragments`: data did not match any variant of untagged enum JsxFragments, received `"somethingelse"`

----------
CLI result: InvalidOptionConfig
----------
8 changes: 3 additions & 5 deletions crates/oxc_linter/src/rules/react/jsx_fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ fn jsx_fragments_diagnostic(span: Span, mode: FragmentMode) -> OxcDiagnostic {
OxcDiagnostic::warn(msg).with_help(help).with_label(span)
}

// Generally we should prefer the string-only syntax for compatibility with the original ESLint rule,
// but we originally implemented the rule with only the object syntax, so we support both now.
#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(untagged)]
pub enum JsxFragments {
Expand Down Expand Up @@ -104,12 +106,8 @@ declare_oxc_lint!(
);

impl Rule for JsxFragments {
// Generally we should prefer the string-only syntax for compatibility with the original ESLint rule,
// but we originally implemented the rule with only the object syntax, so we support both now.
fn from_configuration(value: Value) -> Result<Self, serde_json::error::Error> {
Ok(serde_json::from_value::<DefaultRuleConfig<Self>>(value)
.unwrap_or_default()
.into_inner())
serde_json::from_value::<DefaultRuleConfig<Self>>(value).map(DefaultRuleConfig::into_inner)
}

fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
Expand Down
Loading