diff options
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/bench/mod.rs | 6 | ||||
-rw-r--r-- | cli/tools/check.rs | 2 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 51 | ||||
-rw-r--r-- | cli/tools/lint/linter.rs | 9 | ||||
-rw-r--r-- | cli/tools/lint/mod.rs | 29 | ||||
-rw-r--r-- | cli/tools/registry/pm/cache_deps.rs | 1 | ||||
-rw-r--r-- | cli/tools/test/mod.rs | 10 |
7 files changed, 83 insertions, 25 deletions
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index f133759c9..be5d0ad0e 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -442,7 +442,9 @@ pub async fn run_benchmarks( } let main_graph_container = factory.main_module_graph_container().await?; - main_graph_container.check_specifiers(&specifiers).await?; + main_graph_container + .check_specifiers(&specifiers, cli_options.ext_flag().as_ref()) + .await?; if workspace_bench_options.no_run { return Ok(()); @@ -569,7 +571,7 @@ pub async fn run_benchmarks_with_watch( factory .main_module_graph_container() .await? - .check_specifiers(&specifiers) + .check_specifiers(&specifiers, cli_options.ext_flag().as_ref()) .await?; if workspace_bench_options.no_run { diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 9c464fa16..c22afbb9a 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -73,7 +73,7 @@ pub async fn check( }; main_graph_container - .check_specifiers(&specifiers_for_typecheck) + .check_specifiers(&specifiers_for_typecheck, None) .await } diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 17ddf6c65..3f927545d 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -120,7 +120,13 @@ pub async fn format( }; } - format_files(caches, &fmt_flags, paths_with_options_batches).await?; + format_files( + caches, + cli_options, + &fmt_flags, + paths_with_options_batches, + ) + .await?; Ok(()) }) @@ -133,7 +139,8 @@ pub async fn format( let caches = factory.caches()?; let paths_with_options_batches = resolve_paths_with_options_batches(cli_options, &fmt_flags)?; - format_files(caches, &fmt_flags, paths_with_options_batches).await?; + format_files(caches, cli_options, &fmt_flags, paths_with_options_batches) + .await?; } Ok(()) @@ -172,6 +179,7 @@ fn resolve_paths_with_options_batches( async fn format_files( caches: &Arc<Caches>, + cli_options: &Arc<CliOptions>, fmt_flags: &FmtFlags, paths_with_options_batches: Vec<PathsWithOptions>, ) -> Result<(), AnyError> { @@ -199,6 +207,7 @@ async fn format_files( fmt_options.options, fmt_options.unstable, incremental_cache.clone(), + cli_options.ext_flag().clone(), ) .await?; incremental_cache.wait_completion().await; @@ -211,11 +220,16 @@ fn collect_fmt_files( cli_options: &CliOptions, files: FilePatterns, ) -> Result<Vec<PathBuf>, AnyError> { - FileCollector::new(|e| is_supported_ext_fmt(e.path)) - .ignore_git_folder() - .ignore_node_modules() - .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) - .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files) + FileCollector::new(|e| { + cli_options.ext_flag().as_ref().is_some_and(|ext| { + is_supported_ext_fmt(Path::new(&format!("placeholder.{ext}"))) + }) || is_supported_ext_fmt(e.path) + || e.path.extension().is_none() + }) + .ignore_git_folder() + .ignore_node_modules() + .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) + .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files) } /// Formats markdown (using <https://github.com/dprint/dprint-plugin-markdown>) and its code blocks @@ -449,8 +463,11 @@ pub fn format_file( file_text: &str, fmt_options: &FmtOptionsConfig, unstable_options: &UnstableFmtOptions, + ext: Option<String>, ) -> Result<Option<String>, AnyError> { - let ext = get_extension(file_path).unwrap_or_default(); + let ext = ext + .or_else(|| get_extension(file_path)) + .unwrap_or("ts".to_string()); match ext.as_str() { "md" | "mkd" | "mkdn" | "mdwn" | "mdown" | "markdown" => { @@ -493,14 +510,14 @@ pub fn format_file( "ipynb" => dprint_plugin_jupyter::format_text( file_text, |file_path: &Path, file_text: String| { - format_file(file_path, &file_text, fmt_options, unstable_options) + format_file(file_path, &file_text, fmt_options, unstable_options, None) }, ), _ => { let config = get_resolved_typescript_config(fmt_options); dprint_plugin_typescript::format_text( file_path, - None, + Some(&ext), file_text.to_string(), &config, ) @@ -526,6 +543,7 @@ trait Formatter { fmt_options: FmtOptionsConfig, unstable_options: UnstableFmtOptions, incremental_cache: Arc<IncrementalCache>, + ext: Option<String>, ) -> Result<(), AnyError>; fn finish(&self) -> Result<(), AnyError>; @@ -545,6 +563,7 @@ impl Formatter for CheckFormatter { fmt_options: FmtOptionsConfig, unstable_options: UnstableFmtOptions, incremental_cache: Arc<IncrementalCache>, + ext: Option<String>, ) -> Result<(), AnyError> { // prevent threads outputting at the same time let output_lock = Arc::new(Mutex::new(0)); @@ -566,6 +585,7 @@ impl Formatter for CheckFormatter { &file_text, &fmt_options, &unstable_options, + ext.clone(), ) { Ok(Some(formatted_text)) => { not_formatted_files_count.fetch_add(1, Ordering::Relaxed); @@ -643,6 +663,7 @@ impl Formatter for RealFormatter { fmt_options: FmtOptionsConfig, unstable_options: UnstableFmtOptions, incremental_cache: Arc<IncrementalCache>, + ext: Option<String>, ) -> Result<(), AnyError> { let output_lock = Arc::new(Mutex::new(0)); // prevent threads outputting at the same time @@ -662,7 +683,13 @@ impl Formatter for RealFormatter { &file_path, &file_contents.text, |file_path, file_text| { - format_file(file_path, file_text, &fmt_options, &unstable_options) + format_file( + file_path, + file_text, + &fmt_options, + &unstable_options, + ext.clone(), + ) }, ) { Ok(Some(formatted_text)) => { @@ -788,6 +815,7 @@ fn format_stdin( &source, &fmt_options.options, &fmt_options.unstable, + None, )?; if fmt_flags.check { #[allow(clippy::print_stdout)] @@ -1269,6 +1297,7 @@ mod test { ..Default::default() }, &UnstableFmtOptions::default(), + None, ) .unwrap() .unwrap(); diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs index 777fe4d09..2c2bc43ac 100644 --- a/cli/tools/lint/linter.rs +++ b/cli/tools/lint/linter.rs @@ -94,9 +94,16 @@ impl CliLinter { &self, file_path: &Path, source_code: String, + ext: Option<&str>, ) -> Result<(ParsedSource, Vec<LintDiagnostic>), AnyError> { let specifier = specifier_from_file_path(file_path)?; - let media_type = MediaType::from_specifier(&specifier); + let media_type = if let Some(ext) = ext { + MediaType::from_str(&format!("placeholder.{ext}")) + } else if file_path.extension().is_none() { + MediaType::TypeScript + } else { + MediaType::from_specifier(&specifier) + }; if self.fix { self.lint_file_and_fix(&specifier, media_type, source_code, file_path) diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index d5d174bf7..a52d4e462 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -117,6 +117,7 @@ pub async fn lint( for paths_with_options in paths_with_options_batches { linter .lint_files( + cli_options, paths_with_options.options, lint_config.clone(), paths_with_options.dir, @@ -155,7 +156,7 @@ pub async fn lint( start_dir.maybe_deno_json().map(|c| c.as_ref()), )?; let mut file_path = cli_options.initial_cwd().join(STDIN_FILE_NAME); - if let Some(ext) = &lint_flags.ext { + if let Some(ext) = cli_options.ext_flag() { file_path.set_extension(ext); } let r = lint_stdin(&file_path, lint_rules, deno_lint_config); @@ -179,6 +180,7 @@ pub async fn lint( for paths_with_options in paths_with_options_batches { linter .lint_files( + cli_options, paths_with_options.options, deno_lint_config.clone(), paths_with_options.dir, @@ -264,6 +266,7 @@ impl WorkspaceLinter { pub async fn lint_files( &mut self, + cli_options: &Arc<CliOptions>, lint_options: LintOptions, lint_config: LintConfig, member_dir: WorkspaceDirectory, @@ -348,6 +351,7 @@ impl WorkspaceLinter { let reporter_lock = self.reporter_lock.clone(); let maybe_incremental_cache = maybe_incremental_cache.clone(); let linter = linter.clone(); + let cli_options = cli_options.clone(); async move { run_parallelized(paths, { move |file_path| { @@ -361,7 +365,11 @@ impl WorkspaceLinter { } } - let r = linter.lint_file(&file_path, file_text); + let r = linter.lint_file( + &file_path, + file_text, + cli_options.ext_flag().as_deref(), + ); if let Ok((file_source, file_diagnostics)) = &r { if let Some(incremental_cache) = &maybe_incremental_cache { if file_diagnostics.is_empty() { @@ -421,11 +429,16 @@ fn collect_lint_files( cli_options: &CliOptions, files: FilePatterns, ) -> Result<Vec<PathBuf>, AnyError> { - FileCollector::new(|e| is_script_ext(e.path)) - .ignore_git_folder() - .ignore_node_modules() - .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) - .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files) + FileCollector::new(|e| { + cli_options.ext_flag().as_ref().is_some_and(|ext| { + is_script_ext(Path::new(&format!("placeholder.{ext}"))) + }) || is_script_ext(e.path) + || e.path.extension().is_none() + }) + .ignore_git_folder() + .ignore_node_modules() + .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) + .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files) } #[allow(clippy::print_stdout)] @@ -497,7 +510,7 @@ fn lint_stdin( }); linter - .lint_file(file_path, deno_ast::strip_bom(source_code)) + .lint_file(file_path, deno_ast::strip_bom(source_code), None) .map_err(AnyError::from) } diff --git a/cli/tools/registry/pm/cache_deps.rs b/cli/tools/registry/pm/cache_deps.rs index a03c30df8..a59817055 100644 --- a/cli/tools/registry/pm/cache_deps.rs +++ b/cli/tools/registry/pm/cache_deps.rs @@ -107,6 +107,7 @@ pub async fn cache_top_level_deps( false, deno_config::deno_json::TsTypeLib::DenoWorker, crate::file_fetcher::FetchPermissionsOption::AllowAll, + None, ) .await?; } diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index d043ffcba..e81abad0b 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1583,7 +1583,10 @@ pub async fn run_tests( // Typecheck main_graph_container - .check_specifiers(&specifiers_for_typecheck_and_test) + .check_specifiers( + &specifiers_for_typecheck_and_test, + cli_options.ext_flag().as_ref(), + ) .await?; if workspace_test_options.no_run { @@ -1757,7 +1760,10 @@ pub async fn run_tests_with_watch( // Typecheck main_graph_container - .check_specifiers(&specifiers_for_typecheck_and_test) + .check_specifiers( + &specifiers_for_typecheck_and_test, + cli_options.ext_flag().as_ref(), + ) .await?; if workspace_test_options.no_run { |