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 2a7516811376c..ee29802f5cbb2 100644 --- a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs @@ -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); } @@ -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); @@ -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, )); } } @@ -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";"#, @@ -2150,7 +2159,6 @@ fn test() { }] }])), ), - // ToDo: wrong span ( r#"export * as ns from "fs";"#, Some(serde_json::json!([{ 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 a8c41016e5b0e..d1001cd6ffcb8 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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.