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
20 changes: 14 additions & 6 deletions crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,12 @@ impl NoRestrictedImports {
continue;
}

let diagnostic =
get_diagnostic_from_import_name_result_path(entry.span, source, result, path);
let diagnostic = get_diagnostic_from_import_name_result_path(
entry.statement_span,
source,
result,
path,
);

ctx.diagnostic(diagnostic);
}
Expand All @@ -1185,7 +1189,10 @@ impl NoRestrictedImports {
}
GlobResult::Found => {
let diagnostic = get_diagnostic_from_import_name_result_pattern(
entry.span, source, result, pattern,
entry.statement_span,
source,
result,
pattern,
);

found_errors.push(diagnostic);
Expand All @@ -1195,7 +1202,10 @@ impl NoRestrictedImports {

if pattern.get_regex_result(module_request.name()) {
ctx.diagnostic(get_diagnostic_from_import_name_result_pattern(
entry.span, source, result, pattern,
entry.statement_span,
source,
result,
pattern,
));
}
}
Expand Down Expand Up @@ -2098,7 +2108,6 @@ fn test() {
),
(r#"export * from "fs";"#, Some(serde_json::json!(["fs"]))),
(r#"export * as ns from "fs";"#, Some(serde_json::json!(["fs"]))),
// ToDo: wrong span
(r#"export {a} from "fs";"#, Some(serde_json::json!(["fs"]))),
(
r#"export {foo as b} from "fs";"#,
Expand Down Expand Up @@ -2150,7 +2159,6 @@ fn test() {
}]
}])),
),
// ToDo: wrong span
(
r#"export * as ns from "fs";"#,
Some(serde_json::json!([{
Expand Down
24 changes: 12 additions & 12 deletions crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ source: crates/oxc_linter/src/tester.rs
╰────

⚠ eslint(no-restricted-imports): 'fs' import is restricted from being used.
╭─[no_restricted_imports.tsx:1:9]
╭─[no_restricted_imports.tsx:1:1]
1 │ export {a} from "fs";
·
· ────────────────────
╰────

⚠ eslint(no-restricted-imports): 'foo' import from 'fs' is restricted.
Expand Down Expand Up @@ -800,9 +800,9 @@ source: crates/oxc_linter/src/tester.rs
╰────

⚠ eslint(no-restricted-imports): 'import1' import is restricted from being used.
╭─[no_restricted_imports.tsx:1:10]
╭─[no_restricted_imports.tsx:1:1]
1 │ export { foo } from 'import1';
· ───
· ──────────────────────────────
╰────

⚠ eslint(no-restricted-imports): 'import1' import is restricted from being used.
Expand All @@ -812,9 +812,9 @@ source: crates/oxc_linter/src/tester.rs
╰────

⚠ eslint(no-restricted-imports): 'import1' import is restricted from being used.
╭─[no_restricted_imports.tsx:1:10]
╭─[no_restricted_imports.tsx:1:1]
1 │ export { foo } from 'import1';
· ───
· ──────────────────────────────
╰────

⚠ eslint(no-restricted-imports): 'import-foo' import is restricted from being used.
Expand All @@ -825,9 +825,9 @@ source: crates/oxc_linter/src/tester.rs
help: Please use import-bar instead.

⚠ eslint(no-restricted-imports): 'import-foo' import is restricted from being used.
╭─[no_restricted_imports.tsx:1:10]
╭─[no_restricted_imports.tsx:1:1]
1 │ export { foo } from 'import-foo';
· ───
· ─────────────────────────────────
╰────
help: Please use import-bar instead.

Expand All @@ -853,9 +853,9 @@ source: crates/oxc_linter/src/tester.rs
help: usage of import1 private modules not allowed.

⚠ eslint(no-restricted-imports): 'import1/private/foo' import is restricted from being used by a pattern.
╭─[no_restricted_imports.tsx:1:10]
╭─[no_restricted_imports.tsx:1:1]
1 │ export { foo } from 'import1/private/foo';
· ───
· ──────────────────────────────────────────
╰────
help: usage of import1 private modules not allowed.

Expand Down Expand Up @@ -907,9 +907,9 @@ source: crates/oxc_linter/src/tester.rs
help: usage of import1 private modules not allowed.

⚠ eslint(no-restricted-imports): 'import1/private/bar' import is restricted from being used by a pattern.
╭─[no_restricted_imports.tsx:1:10]
╭─[no_restricted_imports.tsx:1:1]
1 │ export { foo } from 'import1/private/bar';
· ───
· ──────────────────────────────────────────
╰────
help: usage of import1 private modules not allowed.

Expand Down
Loading