0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

simplify plugin loading

This commit is contained in:
Bartek Iwańczuk 2024-12-24 10:27:15 +01:00
parent 0a28ac650a
commit 0e8457d7c3
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 18 additions and 23 deletions

View file

@ -467,6 +467,20 @@ impl LintOptions {
dir_path,
}
}
pub fn resolve_lint_plugins(&self) -> Result<Option<Vec<Url>>, AnyError> {
if self.plugins.is_empty() {
return Ok(None);
}
let mut specifiers = Vec::with_capacity(self.plugins.len());
for plugin in &self.plugins {
// TODO(bartlomieju): handle import-mapped specifiers
let url = resolve_url_or_path(plugin, &self.dir_path)?;
specifiers.push(url);
}
Ok(Some(specifiers))
}
}
fn resolve_lint_rules_options(

View file

@ -297,31 +297,12 @@ impl WorkspaceLinter {
))
});
let maybe_plugins = if lint_options.plugins.is_empty() {
None
} else {
Some(lint_options.plugins.clone())
};
let plugin_specifiers = if let Some(plugins) = maybe_plugins {
let mut plugin_specifiers = Vec::with_capacity(plugins.len());
// TODO(bartlomieju): handle import-mapped specifiers
for plugin in plugins {
let url = resolve_url_or_path(&plugin, &lint_options.dir_path)?;
plugin_specifiers.push(url);
}
plugin_specifiers
} else {
vec![]
};
let plugin_runner = if !plugin_specifiers.is_empty() {
let mut plugin_runner = None;
if let Some(plugin_specifiers) = lint_options.resolve_lint_plugins()? {
let runner =
plugins::create_runner_and_load_plugins(plugin_specifiers).await?;
Some(Arc::new(Mutex::new(runner)))
} else {
None
};
plugin_runner = Some(Arc::new(Mutex::new(runner)));
}
let linter = Arc::new(CliLinter::new(CliLinterOptions {
configured_rules: lint_rules,