diff --git a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs index 14e830c2382d6..19d8e0990917d 100644 --- a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs @@ -59,6 +59,7 @@ struct RestrictedPattern { group: Vec, import_names: Option>, allow_import_names: Option>, + case_sensitive: Option, message: Option, } @@ -153,6 +154,7 @@ fn add_configuration_patterns_from_string(paths: &mut Vec, mo group: vec![CompactStr::new(module_name)], import_names: None, allow_import_names: None, + case_sensitive: None, message: None, }); } @@ -341,6 +343,7 @@ impl NoRestrictedImports { } let mut builder = GitignoreBuilder::new("/"); + let _ = builder.case_insensitive(!pattern.case_sensitive.unwrap_or(false)); for group in &pattern.group { let _ = builder.add_line(None, group.as_str()); @@ -857,10 +860,10 @@ fn test() { r#"import withPatterns from "foo/bar";"#, Some(serde_json::json!([{ "patterns": [{ "group": ["foo/bar"] }] }])), ), - // ( - // "import withPatternsCaseInsensitive from 'foo';", - // Some(serde_json::json!([{ "patterns": [{ "group": ["FOO"] }] }])), - // ), + ( + "import withPatternsCaseInsensitive from 'foo';", + Some(serde_json::json!([{ "patterns": [{ "group": ["FOO"] }] }])), + ), ( r#"import withGitignores from "foo/bar";"#, Some(serde_json::json!([{ "patterns": ["foo/*", "!foo/baz"] }])), @@ -1734,16 +1737,16 @@ fn test() { // }] // }])), // ), - // ( - // "import withPatternsCaseSensitive from 'foo';", - // Some(serde_json::json!([{ - // "patterns": [{ - // "group": ["FOO"], - // "message": "foo is forbidden, use bar instead", - // "caseSensitive": false - // }] - // }])), - // ), + ( + "import withPatternsCaseSensitive from 'foo';", + Some(serde_json::json!([{ + "patterns": [{ + "group": ["FOO"], + "message": "foo is forbidden, use bar instead", + "caseSensitive": false + }] + }])), + ), // ( // " // // error diff --git a/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap b/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap index 972b0993fbdef..9d213f568e089 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap @@ -51,6 +51,13 @@ snapshot_kind: text ╰──── help: Remove the import statement. + ⚠ eslint(no-restricted-imports): 'foo' import is restricted from being used. + ╭─[no_restricted_imports.tsx:1:41] + 1 │ import withPatternsCaseInsensitive from 'foo'; + · ───── + ╰──── + help: Remove the import statement. + ⚠ eslint(no-restricted-imports): 'foo/bar' import is restricted from being used. ╭─[no_restricted_imports.tsx:1:28] 1 │ import withGitignores from "foo/bar"; @@ -638,3 +645,10 @@ snapshot_kind: text · ───────── ╰──── help: Remove the import statement. + + ⚠ eslint(no-restricted-imports): foo is forbidden, use bar instead + ╭─[no_restricted_imports.tsx:1:39] + 1 │ import withPatternsCaseSensitive from 'foo'; + · ───── + ╰──── + help: Remove the import statement.