mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(linter): ignore unsupported extensions in import/no_unresolved (#2481)
This commit is contained in:
parent
3d008abacb
commit
135e56a401
2 changed files with 12 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ use oxc_diagnostics::{
|
|||
};
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_resolver::NODEJS_BUILTINS;
|
||||
use oxc_span::SourceType;
|
||||
use oxc_span::Span;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule};
|
||||
|
|
@ -35,9 +36,16 @@ impl Rule for NoUnresolved {
|
|||
if module_record.loaded_modules.contains_key(specifier) {
|
||||
continue;
|
||||
}
|
||||
let specifier_path = Path::new(specifier.as_str());
|
||||
// skip if the extension is not supported
|
||||
if specifier_path.extension().is_some()
|
||||
&& SourceType::from_path(specifier_path).is_err()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// skip node.js builtin modules
|
||||
if specifier.starts_with("node:")
|
||||
|| (Path::new(specifier.as_str())
|
||||
|| (specifier_path
|
||||
.components()
|
||||
.next()
|
||||
.is_some_and(|c| matches!(c, Component::Normal(_)))
|
||||
|
|
@ -90,6 +98,8 @@ fn test() {
|
|||
r"define([0, foo], function (bar) {})",
|
||||
r"require(0)",
|
||||
r"require(foo)",
|
||||
// Unsupported extensions
|
||||
r#"import "./test.png""#,
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ impl Runtime {
|
|||
fn resolver() -> Resolver {
|
||||
Resolver::new(ResolveOptions {
|
||||
extensions: VALID_EXTENSIONS.iter().map(|ext| format!(".{ext}")).collect(),
|
||||
condition_names: vec!["require".into(), "module".into()],
|
||||
..ResolveOptions::default()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue