diff options
author | Geert-Jan Zwiers <geertjanzwiers@protonmail.com> | 2023-01-13 22:39:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 22:39:19 +0100 |
commit | 052bcc62bba6f5b25eb016a5c8ebf0716ba5a0dc (patch) | |
tree | a33da4af3c41a48f29c4c3d6714cc36b08b3a080 /cli/tools/lint.rs | |
parent | 225114166aa7426d4b93fa13635559029c5ba65d (diff) |
refactor(cli/tools): reduce cloning (#17309)
Diffstat (limited to 'cli/tools/lint.rs')
-rw-r--r-- | cli/tools/lint.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index 413e3e34b..ba30c546a 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -97,7 +97,6 @@ pub async fn lint( let has_error = Arc::new(AtomicBool::new(false)); let deno_dir = cli_options.resolve_deno_dir()?; - let operation = |paths: Vec<PathBuf>| async { let incremental_cache = Arc::new(IncrementalCache::new( &deno_dir.lint_incremental_cache_db_file_path(), @@ -111,8 +110,9 @@ pub async fn lint( &paths, )); let target_files_len = paths.len(); - let reporter_kind = reporter_kind.clone(); - let reporter_lock = Arc::new(Mutex::new(create_reporter(reporter_kind))); + let reporter_lock = + Arc::new(Mutex::new(create_reporter(reporter_kind.clone()))); + run_parallelized(paths, { let has_error = has_error.clone(); let lint_rules = lint_rules.clone(); @@ -126,7 +126,7 @@ pub async fn lint( return Ok(()); } - let r = lint_file(file_path.clone(), file_text, lint_rules.clone()); + let r = lint_file(&file_path, file_text, lint_rules); if let Ok((file_diagnostics, file_text)) = &r { if file_diagnostics.is_empty() { // update the incremental cache if there were no diagnostics @@ -167,8 +167,7 @@ pub async fn lint( .await?; } else { if lint_options.is_stdin { - let reporter_lock = - Arc::new(Mutex::new(create_reporter(reporter_kind.clone()))); + let reporter_lock = Arc::new(Mutex::new(create_reporter(reporter_kind))); let r = lint_stdin(lint_rules); handle_lint_result( STDIN_FILE_NAME, @@ -246,12 +245,12 @@ pub fn create_linter( } fn lint_file( - file_path: PathBuf, + file_path: &PathBuf, source_code: String, lint_rules: Vec<Arc<dyn LintRule>>, ) -> Result<(Vec<LintDiagnostic>, String), AnyError> { let file_name = file_path.to_string_lossy().to_string(); - let media_type = MediaType::from(&file_path); + let media_type = MediaType::from(file_path); let linter = create_linter(media_type, lint_rules); @@ -334,7 +333,7 @@ impl LintReporter for PrettyLintReporter { &d.code, &pretty_message, &source_lines, - d.range.clone(), + &d.range, d.hint.as_ref(), &format_location(&JsStackFrame::from_location( Some(d.filename.clone()), @@ -417,7 +416,7 @@ pub fn format_diagnostic( diagnostic_code: &str, message_line: &str, source_lines: &[&str], - range: deno_lint::diagnostic::Range, + range: &deno_lint::diagnostic::Range, maybe_hint: Option<&String>, formatted_location: &str, ) -> String { |