mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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_macros::declare_oxc_lint;
|
||||||
use oxc_resolver::NODEJS_BUILTINS;
|
use oxc_resolver::NODEJS_BUILTINS;
|
||||||
|
use oxc_span::SourceType;
|
||||||
use oxc_span::Span;
|
use oxc_span::Span;
|
||||||
|
|
||||||
use crate::{context::LintContext, rule::Rule};
|
use crate::{context::LintContext, rule::Rule};
|
||||||
|
|
@ -35,9 +36,16 @@ impl Rule for NoUnresolved {
|
||||||
if module_record.loaded_modules.contains_key(specifier) {
|
if module_record.loaded_modules.contains_key(specifier) {
|
||||||
continue;
|
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
|
// skip node.js builtin modules
|
||||||
if specifier.starts_with("node:")
|
if specifier.starts_with("node:")
|
||||||
|| (Path::new(specifier.as_str())
|
|| (specifier_path
|
||||||
.components()
|
.components()
|
||||||
.next()
|
.next()
|
||||||
.is_some_and(|c| matches!(c, Component::Normal(_)))
|
.is_some_and(|c| matches!(c, Component::Normal(_)))
|
||||||
|
|
@ -90,6 +98,8 @@ fn test() {
|
||||||
r"define([0, foo], function (bar) {})",
|
r"define([0, foo], function (bar) {})",
|
||||||
r"require(0)",
|
r"require(0)",
|
||||||
r"require(foo)",
|
r"require(foo)",
|
||||||
|
// Unsupported extensions
|
||||||
|
r#"import "./test.png""#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let fail = vec![
|
let fail = vec![
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ impl Runtime {
|
||||||
fn resolver() -> Resolver {
|
fn resolver() -> Resolver {
|
||||||
Resolver::new(ResolveOptions {
|
Resolver::new(ResolveOptions {
|
||||||
extensions: VALID_EXTENSIONS.iter().map(|ext| format!(".{ext}")).collect(),
|
extensions: VALID_EXTENSIONS.iter().map(|ext| format!(".{ext}")).collect(),
|
||||||
|
condition_names: vec!["require".into(), "module".into()],
|
||||||
..ResolveOptions::default()
|
..ResolveOptions::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue