mirror of
https://github.com/denoland/deno.git
synced 2025-03-07 03:42:40 -05:00
compute plugins when resolving options
This commit is contained in:
parent
e5b57f641a
commit
4a9c1d68d8
3 changed files with 38 additions and 40 deletions
|
@ -361,11 +361,10 @@ impl WorkspaceLintOptions {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LintOptions {
|
||||
pub dir_path: PathBuf,
|
||||
pub rules: LintRulesConfig,
|
||||
pub files: FilePatterns,
|
||||
pub fix: bool,
|
||||
pub plugins: Vec<String>,
|
||||
pub plugins: Vec<Url>,
|
||||
}
|
||||
|
||||
impl Default for LintOptions {
|
||||
|
@ -381,7 +380,6 @@ impl LintOptions {
|
|||
files: FilePatterns::new_with_base(base),
|
||||
fix: false,
|
||||
plugins: vec![],
|
||||
dir_path: PathBuf::from("/"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,35 +387,33 @@ impl LintOptions {
|
|||
dir_path: PathBuf,
|
||||
lint_config: LintConfig,
|
||||
lint_flags: &LintFlags,
|
||||
) -> Self {
|
||||
Self {
|
||||
) -> Result<Self, AnyError> {
|
||||
let rules = resolve_lint_rules_options(
|
||||
lint_config.options.rules,
|
||||
lint_flags.maybe_rules_tags.clone(),
|
||||
lint_flags.maybe_rules_include.clone(),
|
||||
lint_flags.maybe_rules_exclude.clone(),
|
||||
);
|
||||
|
||||
let plugins = {
|
||||
let plugin_specifiers = lint_config.options.plugins;
|
||||
let mut plugins = Vec::with_capacity(plugin_specifiers.len());
|
||||
for plugin in &plugin_specifiers {
|
||||
// TODO(bartlomieju): handle import-mapped specifiers
|
||||
let url = resolve_url_or_path(plugin, &dir_path)?;
|
||||
plugins.push(url);
|
||||
}
|
||||
// ensure stability for hasher
|
||||
plugins.sort_unstable();
|
||||
plugins
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
files: lint_config.files,
|
||||
rules: resolve_lint_rules_options(
|
||||
lint_config.options.rules,
|
||||
lint_flags.maybe_rules_tags.clone(),
|
||||
lint_flags.maybe_rules_include.clone(),
|
||||
lint_flags.maybe_rules_exclude.clone(),
|
||||
),
|
||||
rules,
|
||||
fix: lint_flags.fix,
|
||||
plugins: lint_config.options.plugins,
|
||||
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);
|
||||
}
|
||||
// ensure stability for hasher
|
||||
specifiers.sort_unstable();
|
||||
Ok(Some(specifiers))
|
||||
plugins,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,7 +779,7 @@ impl CliOptions {
|
|||
.resolve_lint_config_for_members(&cli_arg_patterns)?;
|
||||
let mut result = Vec::with_capacity(member_configs.len());
|
||||
for (ctx, config) in member_configs {
|
||||
let options = LintOptions::resolve(ctx.dir_path(), config, lint_flags);
|
||||
let options = LintOptions::resolve(ctx.dir_path(), config, lint_flags)?;
|
||||
result.push((ctx, options));
|
||||
}
|
||||
Ok(result)
|
||||
|
|
|
@ -1634,17 +1634,19 @@ impl ConfigData {
|
|||
member_dir.dir_path(),
|
||||
(*lint_config).clone(),
|
||||
&LintFlags::default(),
|
||||
);
|
||||
)
|
||||
.inspect_err(|err| lsp_warn!(" Failed to resolve linter options: {}", err))
|
||||
.ok()
|
||||
.unwrap_or_default();
|
||||
let mut plugin_runner = None;
|
||||
let maybe_plugin_specifiers_result = lint_options.resolve_lint_plugins();
|
||||
if let Ok(Some(plugin_specifiers)) = maybe_plugin_specifiers_result {
|
||||
if !lint_options.plugins.is_empty() {
|
||||
fn logger_printer(msg: &str, _is_err: bool) {
|
||||
lsp_log!("pluggin runner - {}", msg);
|
||||
}
|
||||
let logger = crate::tools::lint::PluginLogger::new(logger_printer);
|
||||
let plugin_load_result =
|
||||
crate::tools::lint::create_runner_and_load_plugins(
|
||||
plugin_specifiers,
|
||||
lint_options.plugins.clone(),
|
||||
logger,
|
||||
lint_options.rules.exclude.clone(),
|
||||
)
|
||||
|
|
|
@ -288,7 +288,7 @@ impl WorkspaceLinter {
|
|||
|
||||
let exclude = lint_options.rules.exclude.clone();
|
||||
|
||||
let maybe_plugin_specifiers = lint_options.resolve_lint_plugins()?;
|
||||
let plugin_specifiers = lint_options.plugins.clone();
|
||||
let lint_rules = self.lint_rule_provider.resolve_lint_rules_err_empty(
|
||||
lint_options.rules,
|
||||
member_dir.maybe_deno_json().map(|c| c.as_ref()),
|
||||
|
@ -299,8 +299,8 @@ impl WorkspaceLinter {
|
|||
if lint_rules.supports_incremental_cache() {
|
||||
let mut hasher = FastInsecureHasher::new_deno_versioned();
|
||||
hasher.write_hashable(lint_rules.incremental_cache_state());
|
||||
if let Some(plugin_specifiers) = maybe_plugin_specifiers.as_ref() {
|
||||
hasher.write_hashable(plugin_specifiers);
|
||||
if !plugin_specifiers.is_empty() {
|
||||
hasher.write_hashable(&plugin_specifiers);
|
||||
}
|
||||
let state_hash = hasher.finish();
|
||||
|
||||
|
@ -322,7 +322,7 @@ impl WorkspaceLinter {
|
|||
}
|
||||
|
||||
let mut plugin_runner = None;
|
||||
if let Some(plugin_specifiers) = maybe_plugin_specifiers {
|
||||
if !plugin_specifiers.is_empty() {
|
||||
let logger = plugins::PluginLogger::new(logger_printer);
|
||||
let runner = plugins::create_runner_and_load_plugins(
|
||||
plugin_specifiers,
|
||||
|
@ -583,7 +583,7 @@ fn lint_stdin(
|
|||
let deno_lint_config =
|
||||
tsconfig_resolver.deno_lint_config(start_dir.dir_url())?;
|
||||
let lint_options =
|
||||
LintOptions::resolve(start_dir.dir_path(), lint_config, &lint_flags);
|
||||
LintOptions::resolve(start_dir.dir_path(), lint_config, &lint_flags)?;
|
||||
let configured_rules = lint_rule_provider.resolve_lint_rules_err_empty(
|
||||
lint_options.rules,
|
||||
start_dir.maybe_deno_json().map(|c| c.as_ref()),
|
||||
|
|
Loading…
Add table
Reference in a new issue