Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7c9c1f5
bugfix(linter): add option "allowTypeImports" for rule "no-restricted…
Sysix Dec 14, 2024
acbff7b
fix(linter): rule `no-restricted-imports` support `regex` option insi…
Sysix Dec 23, 2024
a955782
fix(linter): rule no-restricted-imports support regex option inside p…
Sysix Dec 23, 2024
0a19f9a
fix(linter): rule no-restricted-imports support `import_name_pattern`…
Sysix Dec 23, 2024
5296bb4
fix(linter): rule no-restricted-imports support missing options
Sysix Dec 23, 2024
f088c10
fix(linter): rule `no-restricted-imports` support missing options
Sysix Dec 23, 2024
9d1caab
fix(linter): rule `no-restricted-imports`: improve diagnostics
Sysix Dec 25, 2024
531c132
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 25, 2024
0da9b9d
fix(linter): rule no-restricted-imports support missing options - rem…
Sysix Dec 25, 2024
63f3113
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
0152d10
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
b6b185a
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
e069fcb
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
6567e39
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
a029467
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
33e4842
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 26, 2024
87d8da7
fix(linter): rule no-restricted-imports support missing options - bui…
Sysix Dec 26, 2024
12911f4
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 30, 2024
304c2d8
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 30, 2024
b833ef8
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 30, 2024
3ba7bd4
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 30, 2024
ece4df6
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 30, 2024
2cb4ef0
Merge branch 'main' into fix-linter-no-restricted-imports-regex-option
Sysix Dec 31, 2024
5bd8d88
Merge branch 'fix-linter-no-restricted-imports-regex-option' into fix…
Sysix Dec 31, 2024
4109692
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 31, 2024
f8caf13
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 31, 2024
16adf00
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 31, 2024
b694eef
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 31, 2024
f485633
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 31, 2024
6d8c597
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 31, 2024
071c062
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Dec 31, 2024
5f8d1b4
fix(linter): rule no-restricted-imports: improve diagnostics
Sysix Jan 3, 2025
373e5f9
Merge branch 'fix-linter-no-restricted-imports-improve-diagnostics' i…
Sysix Jan 3, 2025
61f30b3
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Jan 3, 2025
49f9186
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Jan 3, 2025
bb73b60
Merge branch 'main' into bugfix-linter-add-option-allow-type-imports-…
Sysix Feb 10, 2025
8a02b84
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Feb 10, 2025
a2aea8c
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Feb 22, 2025
375a326
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Feb 22, 2025
e5ef7e1
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 22, 2025
db3cdea
Merge branch 'bugfix-linter-add-option-allow-type-imports-for-no-rest…
Sysix Feb 22, 2025
305b3ce
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Feb 22, 2025
a21da15
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 22, 2025
b420291
Merge branch 'main' into bugfix-linter-add-option-allow-type-imports-…
Sysix Feb 22, 2025
be27b34
fix(linter): add option "allowTypeImports" for rule "no-restricted-im…
Sysix Feb 23, 2025
4f9e1d5
Merge branch 'bugfix-linter-add-option-allow-type-imports-for-no-rest…
Sysix Feb 23, 2025
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
Prev Previous commit
Next Next commit
fix(linter): rule no-restricted-imports support missing options - rem…
…ove regress
  • Loading branch information
Sysix committed Dec 25, 2024
commit 0da9b9d8030f0bdd87e3e3a5ad588638cdaea8c3
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ prettyplease = "0.2.25"
project-root = "0.2.2"
rayon = "1.10.0"
regex = "1.11.1"
regress = "0.10.1"
ropey = "1.6.1"
rust-lapper = "1.1.0"
ryu-js = "1.0.1"
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ nonmax = { workspace = true }
phf = { workspace = true, features = ["macros"] }
rayon = { workspace = true }
regex = { workspace = true }
regress = { workspace = true }
rust-lapper = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, features = ["indexmap2"] }
Expand Down
73 changes: 34 additions & 39 deletions crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ignore::gitignore::GitignoreBuilder;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{CompactStr, Span};
use regress::Regex;
use regex::Regex;
use rustc_hash::FxHashMap;
use serde::Deserialize;
use serde_json::Value;
Expand Down Expand Up @@ -323,12 +323,7 @@ impl RestrictedPattern {
return false;
};

let flags = match self.case_sensitive {
Some(case_sensitive) if case_sensitive => "u",
_ => "iu",
};

let Ok(reg_exp) = Regex::with_flags(regex.as_str(), flags) else {
let Ok(reg_exp) = Regex::new(regex.as_str()) else {
return false;
};

Expand All @@ -340,7 +335,7 @@ impl RestrictedPattern {
return false;
};

let Ok(reg_exp) = Regex::with_flags(import_name_pattern.as_str(), "u") else {
let Ok(reg_exp) = Regex::new(import_name_pattern.as_str()) else {
return false;
};

Expand All @@ -352,7 +347,7 @@ impl RestrictedPattern {
return false;
};

let Ok(reg_exp) = Regex::with_flags(allow_import_names.as_str(), "u") else {
let Ok(reg_exp) = Regex::new(allow_import_names.as_str()) else {
return false;
};

Expand Down Expand Up @@ -954,12 +949,12 @@ fn test() {
}]
}])),
),
(
r#"import withPatterns from "foo/bar";"#,
Some(
serde_json::json!([{ "patterns": [{ "regex": "foo/(?!bar)", "message": "foo is forbidden, use bar instead" }] }]),
),
),
// (
// r#"import withPatterns from "foo/bar";"#,
// Some(
// serde_json::json!([{ "patterns": [{ "regex": "foo/(?!bar)", "message": "foo is forbidden, use bar instead" }] }]),
// ),
// ),
(
"import withPatternsCaseSensitive from 'foo';",
Some(serde_json::json!([{
Expand Down Expand Up @@ -1874,12 +1869,12 @@ fn test() {
}]
}])),
),
(
r#"import withPatterns from "foo/baz";"#,
Some(
serde_json::json!([{ "patterns": [{ "regex": "foo/(?!bar)", "message": "foo is forbidden, use bar instead" }] }]),
),
),
// (
// r#"import withPatterns from "foo/baz";"#,
// Some(
// serde_json::json!([{ "patterns": [{ "regex": "foo/(?!bar)", "message": "foo is forbidden, use bar instead" }] }]),
// ),
// ),
(
"import withPatternsCaseSensitive from 'FOO';",
Some(serde_json::json!([{
Expand Down Expand Up @@ -1909,24 +1904,24 @@ fn test() {
}]
}])),
),
(
"
// error
import { Foo_Enum } from '@app/api';
import { Bar_Enum } from '@app/api/bar';
import { Baz_Enum } from '@app/api/baz';
import { B_Enum } from '@app/api/enums/foo';

// no error
import { C_Enum } from '@app/api/enums';
",
Some(serde_json::json!([{
"patterns": [{
"regex": "@app/(?!(api/enums$)).*",
"importNamePattern": "_Enum$"
}]
}])),
),
// (
// "
// // error
// import { Foo_Enum } from '@app/api';
// import { Bar_Enum } from '@app/api/bar';
// import { Baz_Enum } from '@app/api/baz';
// import { B_Enum } from '@app/api/enums/foo';
//
// // no error
// import { C_Enum } from '@app/api/enums';
// ",
// Some(serde_json::json!([{
// "patterns": [{
// "regex": "@app/(?!(api/enums$)).*",
// "importNamePattern": "_Enum$"
// }]
// }])),
// ),
];

Tester::new(NoRestrictedImports::NAME, NoRestrictedImports::CATEGORY, pass, fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,6 @@ snapshot_kind: text
╰────
help: Remove the import statement.

⚠ eslint(no-restricted-imports): foo is forbidden, use bar instead
╭─[no_restricted_imports.tsx:1:26]
1 │ import withPatterns from "foo/baz";
· ─────────
╰────
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';
Expand All @@ -862,39 +855,3 @@ snapshot_kind: text
· ─────
╰────
help: Remove the import statement.

⚠ eslint(no-restricted-imports): '@app/api' import is restricted from being used.
╭─[no_restricted_imports.tsx:3:43]
2 │ // error
3 │ import { Foo_Enum } from '@app/api';
· ──────────
4 │ import { Bar_Enum } from '@app/api/bar';
╰────
help: Remove the import statement.

⚠ eslint(no-restricted-imports): '@app/api/bar' import is restricted from being used.
╭─[no_restricted_imports.tsx:4:43]
3 │ import { Foo_Enum } from '@app/api';
4 │ import { Bar_Enum } from '@app/api/bar';
· ──────────────
5 │ import { Baz_Enum } from '@app/api/baz';
╰────
help: Remove the import statement.

⚠ eslint(no-restricted-imports): '@app/api/baz' import is restricted from being used.
╭─[no_restricted_imports.tsx:5:43]
4 │ import { Bar_Enum } from '@app/api/bar';
5 │ import { Baz_Enum } from '@app/api/baz';
· ──────────────
6 │ import { B_Enum } from '@app/api/enums/foo';
╰────
help: Remove the import statement.

⚠ eslint(no-restricted-imports): '@app/api/enums/foo' import is restricted from being used.
╭─[no_restricted_imports.tsx:6:41]
5 │ import { Baz_Enum } from '@app/api/baz';
6 │ import { B_Enum } from '@app/api/enums/foo';
· ────────────────────
7 │
╰────
help: Remove the import statement.
Loading