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:
parent
0a28ac650a
commit
0e8457d7c3
2 changed files with 18 additions and 23 deletions
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue