Skip to content

Commit

Permalink
fix(linter): rule no-restricted-imports: improve diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Dec 31, 2024
1 parent 5bd8d88 commit 4109692
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 116 deletions.
18 changes: 6 additions & 12 deletions crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ impl NoRestrictedImports {
for (source, requests) in &module_record.requested_modules {
for request in requests {
if request.is_import && module_record.import_entries.is_empty() {
side_effect_import_map.entry(source).or_default().push(request.span);
side_effect_import_map.entry(source).or_default().push(request.statement_span);
}
}
}
Expand Down Expand Up @@ -679,7 +679,7 @@ impl NoRestrictedImports {
}

let diagnostic = get_diagnostic_from_is_skip_able_result_path(
entry.module_request.span(),
entry.statement_span,
source,
result,
path,
Expand All @@ -705,7 +705,7 @@ impl NoRestrictedImports {
}
GlobResult::Found => {
let diagnostic = get_diagnostic_from_is_skip_able_result_pattern(
entry.module_request.span(),
entry.statement_span,
source,
result,
pattern,
Expand All @@ -717,9 +717,7 @@ impl NoRestrictedImports {
};

if pattern.get_regex_result(&entry.module_request) {
let span = entry.module_request.span();

ctx.diagnostic(diagnostic_pattern(span, pattern.message.clone(), source));
ctx.diagnostic(diagnostic_pattern(entry.statement_span, pattern.message.clone(), source));
}
}

Expand Down Expand Up @@ -773,10 +771,8 @@ impl NoRestrictedImports {
break;
}
GlobResult::Found => {
let span = module_request.span();

let diagnostic = get_diagnostic_from_is_skip_able_result_pattern(
span, source, result, pattern,
entry.span, source, result, pattern,
);

found_errors.push(diagnostic);
Expand All @@ -785,9 +781,7 @@ impl NoRestrictedImports {
};

if pattern.get_regex_result(module_request) {
let span = module_request.span();

ctx.diagnostic(diagnostic_pattern(span, pattern.message.clone(), source));
ctx.diagnostic(diagnostic_pattern(entry.span, pattern.message.clone(), source));
}
}

Expand Down
Loading

0 comments on commit 4109692

Please sign in to comment.