From f6efc9f357525c5033a21fd053187c3272279e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 24 Dec 2024 10:52:36 +0100 Subject: [PATCH] plugins are run inside CliLinter now --- cli/tools/lint/linter.rs | 19 ++++++++++++++----- cli/tools/lint/mod.rs | 29 ++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs index f74d51b9c6..14893c4c83 100644 --- a/cli/tools/lint/linter.rs +++ b/cli/tools/lint/linter.rs @@ -75,10 +75,6 @@ impl CliLinter { } } - pub fn get_plugin_runner(&self) -> Option>> { - self.maybe_plugin_runner.clone() - } - pub fn run_plugins( &self, parsed_source: ParsedSource, @@ -131,7 +127,7 @@ impl CliLinter { MediaType::from_specifier(&specifier) }; - if self.fix { + let result = if self.fix { self.lint_file_and_fix(&specifier, media_type, source_code, file_path) } else { self @@ -143,6 +139,19 @@ impl CliLinter { config: self.deno_lint_config.clone(), }) .map_err(AnyError::from) + }; + + match result { + Ok((file_source, mut file_diagnostics)) => { + // TODO(bartlomieju): now add it to `linter.lint_with_ast()`. + // TODO(bartlomieju): plugins don't support fixing for now. + let plugin_diagnostics = + self.run_plugins(file_source.clone(), file_path.to_path_buf())?; + + file_diagnostics.extend_from_slice(&plugin_diagnostics); + Ok((file_source, file_diagnostics)) + } + Err(err) => Err(err), } } diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index cad6d9fe63..17da5e7ef5 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -341,27 +341,18 @@ impl WorkspaceLinter { file_text, cli_options.ext_flag().as_deref(), ); - let r = match r { - Ok((file_source, mut file_diagnostics)) => { - // TODO(bartlomieju): now move it to `linter.lint_file()` and `linter.lint_with_ast()`. - let plugin_diagnostics = - linter.run_plugins(file_source.clone(), file_path.clone())?; - - file_diagnostics.extend_from_slice(&plugin_diagnostics); - if let Some(incremental_cache) = &maybe_incremental_cache_ { - if file_diagnostics.is_empty() { - // update the incremental cache if there were no diagnostics - incremental_cache.update_file( - &file_path, - // ensure the returned text is used here as it may have been modified via --fix - file_source.text(), - ) - } + if let Ok((file_source, file_diagnostics)) = &r { + if let Some(incremental_cache) = &maybe_incremental_cache_ { + if file_diagnostics.is_empty() { + // update the incremental cache if there were no diagnostics + incremental_cache.update_file( + &file_path, + // ensure the returned text is used here as it may have been modified via --fix + file_source.text(), + ) } - Ok((file_source, file_diagnostics)) } - Err(err) => Err(err), - }; + } let success = handle_lint_result( &file_path.to_string_lossy(),