From fecfbd4fec94f125e77569dd2365a4ebf34bf709 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Thu, 5 Sep 2024 18:27:16 +0200 Subject: [PATCH 01/14] feat: default to TS for file extension and support ext flag in more scenarios --- cli/args/flags.rs | 22 ++++----------- cli/args/mod.rs | 2 +- cli/lsp/language_server.rs | 1 + cli/tools/fmt.rs | 31 +++++++++++++++++----- cli/tools/lint/linter.rs | 9 ++++++- cli/tools/lint/mod.rs | 12 ++++++--- tests/specs/fmt/default_ts/__test__.jsonc | 18 +++++++++++++ tests/specs/fmt/default_ts/as_ts.js | 1 + tests/specs/fmt/default_ts/extensionless | 1 + tests/specs/lint/default_ts/__test__.jsonc | 18 +++++++++++++ tests/specs/lint/default_ts/as_ts.js | 1 + tests/specs/lint/default_ts/extensionless | 1 + tests/specs/mod.rs | 5 ++++ 13 files changed, 93 insertions(+), 29 deletions(-) create mode 100644 tests/specs/fmt/default_ts/__test__.jsonc create mode 100644 tests/specs/fmt/default_ts/as_ts.js create mode 100644 tests/specs/fmt/default_ts/extensionless create mode 100644 tests/specs/lint/default_ts/__test__.jsonc create mode 100644 tests/specs/lint/default_ts/as_ts.js create mode 100644 tests/specs/lint/default_ts/extensionless diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 9397f218071c6b..ea2e2e17316818 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -299,7 +299,6 @@ pub struct LintFlags { pub json: bool, pub compact: bool, pub watch: Option, - pub ext: Option, } impl LintFlags { @@ -2370,7 +2369,7 @@ fn install_subcommand() -> Command { Local installation -Add dependencies to the local project's configuration (deno.json / package.json) and installs them +Add dependencies to the local project's configuration (deno.json / package.json) and installs them in the package cache. If no dependency is specified, installs all dependencies listed in the config file. If the --entrypoint flag is passed, installs the dependencies of the specified entrypoint(s). @@ -2780,7 +2779,7 @@ fn task_subcommand() -> Command { cstr!( "Run a task defined in the configuration file. deno task build - + List all available tasks: deno task" ), @@ -2808,7 +2807,7 @@ fn test_subcommand() -> Command { Evaluate the given modules, run all tests declared with Deno.test() and report results to standard output: deno test src/fetch_test.ts src/signal_test.ts -Directory arguments are expanded to all contained files matching the glob {*_,*.,}test.{js,mjs,ts,mts,jsx,tsx} +Directory arguments are expanded to all contained files matching the glob {*_,*.,}test.{js,mjs,ts,mts,jsx,tsx} or **/__tests__/**: deno test src/ @@ -4571,8 +4570,9 @@ fn lsp_parse(flags: &mut Flags, _matches: &mut ArgMatches) { fn lint_parse(flags: &mut Flags, matches: &mut ArgMatches) { unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionOnly); - + ext_arg_parse(flags, matches); config_args_parse(flags, matches); + let files = match matches.remove_many::("files") { Some(f) => f.collect(), None => vec![], @@ -4597,7 +4597,6 @@ fn lint_parse(flags: &mut Flags, matches: &mut ArgMatches) { let json = matches.get_flag("json"); let compact = matches.get_flag("compact"); - let ext = matches.remove_one::("ext"); flags.subcommand = DenoSubcommand::Lint(LintFlags { files: FileFlags { @@ -4612,7 +4611,6 @@ fn lint_parse(flags: &mut Flags, matches: &mut ArgMatches) { json, compact, watch: watch_arg_parse(matches), - ext, }); } @@ -6415,7 +6413,6 @@ mod tests { json: false, compact: false, watch: Default::default(), - ext: None, }), ..Flags::default() } @@ -6444,7 +6441,6 @@ mod tests { json: false, compact: false, watch: Some(Default::default()), - ext: None, }), ..Flags::default() } @@ -6478,7 +6474,6 @@ mod tests { no_clear_screen: true, exclude: vec![], }), - ext: None, }), ..Flags::default() } @@ -6506,7 +6501,6 @@ mod tests { json: false, compact: false, watch: Default::default(), - ext: None, }), ..Flags::default() } @@ -6529,7 +6523,6 @@ mod tests { json: false, compact: false, watch: Default::default(), - ext: None, }), ..Flags::default() } @@ -6557,7 +6550,6 @@ mod tests { json: false, compact: false, watch: Default::default(), - ext: None, }), ..Flags::default() } @@ -6586,7 +6578,6 @@ mod tests { json: false, compact: false, watch: Default::default(), - ext: None, }), ..Flags::default() } @@ -6609,7 +6600,6 @@ mod tests { json: true, compact: false, watch: Default::default(), - ext: None, }), ..Flags::default() } @@ -6639,7 +6629,6 @@ mod tests { json: true, compact: false, watch: Default::default(), - ext: None, }), config_flag: ConfigFlag::Path("Deno.jsonc".to_string()), ..Flags::default() @@ -6670,7 +6659,6 @@ mod tests { json: false, compact: true, watch: Default::default(), - ext: None, }), config_flag: ConfigFlag::Path("Deno.jsonc".to_string()), ..Flags::default() diff --git a/cli/args/mod.rs b/cli/args/mod.rs index f7623323fe2418..b23b0ef3539344 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1130,7 +1130,7 @@ impl CliOptions { resolve_url_or_path(&compile_flags.source_file, self.initial_cwd())? } DenoSubcommand::Eval(_) => { - resolve_url_or_path("./$deno$eval", self.initial_cwd())? + resolve_url_or_path("./$deno$eval.ts", self.initial_cwd())? } DenoSubcommand::Repl(_) => { resolve_url_or_path("./$deno$repl.ts", self.initial_cwd())? diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 2bb13e5e4c5d74..2a46bdda3e3eac 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1410,6 +1410,7 @@ impl Inner { document.content(), &fmt_options, &unstable_options, + None, ) } }; diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 97f3b32152d58f..8c879604058244 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -120,7 +120,7 @@ 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 +133,7 @@ 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 +172,7 @@ fn resolve_paths_with_options_batches( async fn format_files( caches: &Arc, + cli_options: &Arc, fmt_flags: &FmtFlags, paths_with_options_batches: Vec, ) -> Result<(), AnyError> { @@ -199,6 +200,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,7 +213,7 @@ fn collect_fmt_files( cli_options: &CliOptions, files: FilePatterns, ) -> Result, AnyError> { - FileCollector::new(|e| is_supported_ext_fmt(e.path)) + 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)) @@ -447,8 +449,19 @@ pub fn format_file( file_text: &str, fmt_options: &FmtOptionsConfig, unstable_options: &UnstableFmtOptions, + ext: Option, ) -> Result, AnyError> { - let ext = get_extension(file_path).unwrap_or_default(); + let file_path = &if let Some(ext) = &ext { + file_path.with_extension(if let Some(prev_ext) = file_path.extension() { + format!("{}.{ext}", prev_ext.to_string_lossy()) + } else { + ext.clone() + }) + } else { + file_path.to_path_buf() + }; + + let ext = ext.or_else(|| get_extension(file_path)).unwrap_or_default(); match ext.as_str() { "md" | "mkd" | "mkdn" | "mdwn" | "mdown" | "markdown" => { @@ -491,7 +504,7 @@ 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) }, ), _ => { @@ -523,6 +536,7 @@ trait Formatter { fmt_options: FmtOptionsConfig, unstable_options: UnstableFmtOptions, incremental_cache: Arc, + ext: Option, ) -> Result<(), AnyError>; fn finish(&self) -> Result<(), AnyError>; @@ -542,6 +556,7 @@ impl Formatter for CheckFormatter { fmt_options: FmtOptionsConfig, unstable_options: UnstableFmtOptions, incremental_cache: Arc, + ext: Option, ) -> Result<(), AnyError> { // prevent threads outputting at the same time let output_lock = Arc::new(Mutex::new(0)); @@ -563,6 +578,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); @@ -640,6 +656,7 @@ impl Formatter for RealFormatter { fmt_options: FmtOptionsConfig, unstable_options: UnstableFmtOptions, incremental_cache: Arc, + ext: Option, ) -> Result<(), AnyError> { let output_lock = Arc::new(Mutex::new(0)); // prevent threads outputting at the same time @@ -659,7 +676,7 @@ 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)) => { @@ -785,6 +802,7 @@ fn format_stdin( &source, &fmt_options.options, &fmt_options.unstable, + None, )?; if fmt_flags.check { #[allow(clippy::print_stdout)] @@ -1263,6 +1281,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 777fe4d09bdae8..2c2bc43acb2caa 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), 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 5b51b2b40c045b..d53af81bdaef91 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -114,6 +114,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, @@ -152,7 +153,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); @@ -176,6 +177,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, @@ -261,6 +263,7 @@ impl WorkspaceLinter { pub async fn lint_files( &mut self, + cli_options: &Arc, lint_options: LintOptions, lint_config: LintConfig, member_dir: WorkspaceDirectory, @@ -345,6 +348,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| { @@ -358,7 +362,7 @@ 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() { @@ -418,7 +422,7 @@ fn collect_lint_files( cli_options: &CliOptions, files: FilePatterns, ) -> Result, AnyError> { - FileCollector::new(|e| is_script_ext(e.path)) + 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)) @@ -492,7 +496,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/tests/specs/fmt/default_ts/__test__.jsonc b/tests/specs/fmt/default_ts/__test__.jsonc new file mode 100644 index 00000000000000..f1fe0c64625628 --- /dev/null +++ b/tests/specs/fmt/default_ts/__test__.jsonc @@ -0,0 +1,18 @@ +{ + "tempDir": true, + "tests": { + "stdin": { + "args": "lint -", + "input": "const x: string = \"foo\";", + "output": "const x: string = \"foo\";\n" + }, + "ext_flag": { + "args": "lint --ext=ts as_ts.js", + "output": "Checked 1 file\n" + }, + "extensionless": { + "args": "lint extensionless", + "output": "Checked 1 file\n" + } + } +} diff --git a/tests/specs/fmt/default_ts/as_ts.js b/tests/specs/fmt/default_ts/as_ts.js new file mode 100644 index 00000000000000..72a35c2a887b82 --- /dev/null +++ b/tests/specs/fmt/default_ts/as_ts.js @@ -0,0 +1 @@ +const x: string = "foo"; diff --git a/tests/specs/fmt/default_ts/extensionless b/tests/specs/fmt/default_ts/extensionless new file mode 100644 index 00000000000000..72a35c2a887b82 --- /dev/null +++ b/tests/specs/fmt/default_ts/extensionless @@ -0,0 +1 @@ +const x: string = "foo"; diff --git a/tests/specs/lint/default_ts/__test__.jsonc b/tests/specs/lint/default_ts/__test__.jsonc new file mode 100644 index 00000000000000..24d77a79ef0979 --- /dev/null +++ b/tests/specs/lint/default_ts/__test__.jsonc @@ -0,0 +1,18 @@ +{ + "tempDir": true, + "tests": { + "stdin": { + "args": "fmt -", + "input": "const x: string = \"foo\";", + "output": "const x: string = \"foo\";\n" + }, + "ext_flag": { + "args": "fmt --ext=ts as_ts.js", + "output": "Checked 1 file\n" + }, + "extensionless": { + "args": "fmt extensionless", + "output": "Checked 1 file\n" + } + } +} diff --git a/tests/specs/lint/default_ts/as_ts.js b/tests/specs/lint/default_ts/as_ts.js new file mode 100644 index 00000000000000..72a35c2a887b82 --- /dev/null +++ b/tests/specs/lint/default_ts/as_ts.js @@ -0,0 +1 @@ +const x: string = "foo"; diff --git a/tests/specs/lint/default_ts/extensionless b/tests/specs/lint/default_ts/extensionless new file mode 100644 index 00000000000000..72a35c2a887b82 --- /dev/null +++ b/tests/specs/lint/default_ts/extensionless @@ -0,0 +1 @@ +const x: string = "foo"; diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs index 9565aa71ff065c..34221dd9da63d1 100644 --- a/tests/specs/mod.rs +++ b/tests/specs/mod.rs @@ -176,6 +176,7 @@ struct StepMetaData { pub command_name: Option, #[serde(default)] pub envs: HashMap, + pub input: Option, pub output: String, #[serde(default)] pub exit_code: i32, @@ -406,6 +407,10 @@ fn run_step( true => command.show_output(), false => command, }; + let command = match &step.input { + Some(input) => command.stdin_text(input), + None => command, + }; let output = command.run(); if step.output.ends_with(".out") { let test_output_path = cwd.join(&step.output); From 87f6f23e2146c2071f1cfb9947d983f5e78364de Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 6 Sep 2024 11:54:44 +0200 Subject: [PATCH 02/14] update dprint-plugin-typescript --- Cargo.lock | 4 ++-- cli/Cargo.toml | 2 +- cli/tools/fmt.rs | 13 +++---------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e45a73980785cb..fc911543ec797d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2517,9 +2517,9 @@ dependencies = [ [[package]] name = "dprint-plugin-typescript" -version = "0.91.7" +version = "0.91.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243879526ffc78aeb111719c3180f95820847c28eeeffb8d2585d1ec15a44fe4" +checksum = "f2bbde080586b8e3b55fdd6aafbf9170d331eb60cc461c227d3953c287e01063" dependencies = [ "anyhow", "deno_ast", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 016488e5c21c9d..fcc7587baa1360 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -102,7 +102,7 @@ dotenvy = "0.15.7" dprint-plugin-json = "=0.19.3" dprint-plugin-jupyter = "=0.1.3" dprint-plugin-markdown = "=0.17.8" -dprint-plugin-typescript = "=0.91.7" +dprint-plugin-typescript = "=0.91.8" env_logger = "=0.10.0" fancy-regex = "=0.10.0" faster-hex.workspace = true diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 8c879604058244..12db150bf12e79 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -313,6 +313,7 @@ fn format_markdown( codeblock_config.line_width = line_width; dprint_plugin_typescript::format_text( &fake_filename, + None, text.to_string(), &codeblock_config, ) @@ -407,6 +408,7 @@ pub fn format_html( typescript_config.line_width = hints.print_width as u32; dprint_plugin_typescript::format_text( &path, + None, text.to_string(), &typescript_config, ) @@ -451,16 +453,6 @@ pub fn format_file( unstable_options: &UnstableFmtOptions, ext: Option, ) -> Result, AnyError> { - let file_path = &if let Some(ext) = &ext { - file_path.with_extension(if let Some(prev_ext) = file_path.extension() { - format!("{}.{ext}", prev_ext.to_string_lossy()) - } else { - ext.clone() - }) - } else { - file_path.to_path_buf() - }; - let ext = ext.or_else(|| get_extension(file_path)).unwrap_or_default(); match ext.as_str() { @@ -511,6 +503,7 @@ pub fn format_file( let config = get_resolved_typescript_config(fmt_options); dprint_plugin_typescript::format_text( file_path, + Some(&ext), file_text.to_string(), &config, ) From f71239d4f1dcfdf7cb562fa0cb265ea6380273b9 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Tue, 17 Sep 2024 01:17:18 +0200 Subject: [PATCH 03/14] add tests for runtime case --- cli/args/flags.rs | 5 +++++ tests/specs/bench/default_ts/__test__.jsonc | 13 +++++++++++++ tests/specs/bench/default_ts/as_ts.js | 3 +++ tests/specs/bench/default_ts/extensionless | 3 +++ tests/specs/run/default_ts/__test__.jsonc | 18 ++++++++++++++++++ tests/specs/run/default_ts/as_ts.js | 2 ++ tests/specs/run/default_ts/extensionless | 2 ++ tests/specs/test/default_ts/__test__.jsonc | 13 +++++++++++++ tests/specs/test/default_ts/as_ts.js | 3 +++ tests/specs/test/default_ts/extensionless | 3 +++ 10 files changed, 65 insertions(+) create mode 100644 tests/specs/bench/default_ts/__test__.jsonc create mode 100644 tests/specs/bench/default_ts/as_ts.js create mode 100644 tests/specs/bench/default_ts/extensionless create mode 100644 tests/specs/run/default_ts/__test__.jsonc create mode 100644 tests/specs/run/default_ts/as_ts.js create mode 100644 tests/specs/run/default_ts/extensionless create mode 100644 tests/specs/test/default_ts/__test__.jsonc create mode 100644 tests/specs/test/default_ts/as_ts.js create mode 100644 tests/specs/test/default_ts/extensionless diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 2a4f6790d7cda0..7a396b30a47d4d 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -1687,6 +1687,7 @@ If you specify a directory instead of a file, the path is expanded to all contai .arg(no_clear_screen_arg()) .arg(script_arg().last(true)) .arg(env_file_arg()) + .arg(executable_ext_arg()) }) } @@ -2948,6 +2949,7 @@ or **/__tests__/**: .action(ArgAction::SetTrue) ) .arg(env_file_arg()) + .arg(executable_ext_arg()) ) } @@ -4107,6 +4109,7 @@ fn bench_parse( flags.type_check_mode = TypeCheckMode::Local; runtime_args_parse(flags, matches, true, false)?; + ext_arg_parse(flags, matches); // NOTE: `deno bench` always uses `--no-prompt`, tests shouldn't ever do // interactive prompts, unless done by user code @@ -4838,6 +4841,8 @@ fn test_parse( ) -> clap::error::Result<()> { flags.type_check_mode = TypeCheckMode::Local; runtime_args_parse(flags, matches, true, true)?; + ext_arg_parse(flags, matches); + // NOTE: `deno test` always uses `--no-prompt`, tests shouldn't ever do // interactive prompts, unless done by user code flags.permissions.no_prompt = true; diff --git a/tests/specs/bench/default_ts/__test__.jsonc b/tests/specs/bench/default_ts/__test__.jsonc new file mode 100644 index 00000000000000..a56a1c25377b1f --- /dev/null +++ b/tests/specs/bench/default_ts/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "tempDir": true, + "tests": { + "ext_flag": { + "args": "bench --ext=ts as_ts.js", + "output": "Checked 1 file\n" + }, + "extensionless": { + "args": "bench extensionless", + "output": "Checked 1 file\n" + } + } +} diff --git a/tests/specs/bench/default_ts/as_ts.js b/tests/specs/bench/default_ts/as_ts.js new file mode 100644 index 00000000000000..914439a9f7c1ab --- /dev/null +++ b/tests/specs/bench/default_ts/as_ts.js @@ -0,0 +1,3 @@ +Deno.bench(function foo() { + const x: string = "foo"; +}); diff --git a/tests/specs/bench/default_ts/extensionless b/tests/specs/bench/default_ts/extensionless new file mode 100644 index 00000000000000..914439a9f7c1ab --- /dev/null +++ b/tests/specs/bench/default_ts/extensionless @@ -0,0 +1,3 @@ +Deno.bench(function foo() { + const x: string = "foo"; +}); diff --git a/tests/specs/run/default_ts/__test__.jsonc b/tests/specs/run/default_ts/__test__.jsonc new file mode 100644 index 00000000000000..3da2a1f7d42656 --- /dev/null +++ b/tests/specs/run/default_ts/__test__.jsonc @@ -0,0 +1,18 @@ +{ + "tempDir": true, + "tests": { + "stdin": { + "args": "run -", + "input": "const x: string = \"foo\";", + "output": "const x: string = \"foo\";\n" + }, + "ext_flag": { + "args": "run --ext=ts as_ts.js", + "output": "foo\n" + }, + "extensionless": { + "args": "run extensionless", + "output": "foo\n" + } + } +} diff --git a/tests/specs/run/default_ts/as_ts.js b/tests/specs/run/default_ts/as_ts.js new file mode 100644 index 00000000000000..cef8995bcd7129 --- /dev/null +++ b/tests/specs/run/default_ts/as_ts.js @@ -0,0 +1,2 @@ +const x: string = "foo"; +console.log(x); diff --git a/tests/specs/run/default_ts/extensionless b/tests/specs/run/default_ts/extensionless new file mode 100644 index 00000000000000..cef8995bcd7129 --- /dev/null +++ b/tests/specs/run/default_ts/extensionless @@ -0,0 +1,2 @@ +const x: string = "foo"; +console.log(x); diff --git a/tests/specs/test/default_ts/__test__.jsonc b/tests/specs/test/default_ts/__test__.jsonc new file mode 100644 index 00000000000000..3eb76d7273d95a --- /dev/null +++ b/tests/specs/test/default_ts/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "tempDir": true, + "tests": { + "ext_flag": { + "args": "test --ext=ts as_ts.js", + "output": "Checked 1 file\n" + }, + "extensionless": { + "args": "test extensionless", + "output": "Checked 1 file\n" + } + } +} diff --git a/tests/specs/test/default_ts/as_ts.js b/tests/specs/test/default_ts/as_ts.js new file mode 100644 index 00000000000000..52cb8eacccaeb6 --- /dev/null +++ b/tests/specs/test/default_ts/as_ts.js @@ -0,0 +1,3 @@ +Deno.test(function foo() { + const x: string = "foo"; +}); diff --git a/tests/specs/test/default_ts/extensionless b/tests/specs/test/default_ts/extensionless new file mode 100644 index 00000000000000..52cb8eacccaeb6 --- /dev/null +++ b/tests/specs/test/default_ts/extensionless @@ -0,0 +1,3 @@ +Deno.test(function foo() { + const x: string = "foo"; +}); From 5b1e5e7b7ead0f02a7b05290897b340379c9cc77 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Tue, 17 Sep 2024 21:03:54 +0200 Subject: [PATCH 04/14] fix run, test and bench --- cli/cache/mod.rs | 2 +- cli/file_fetcher.rs | 11 +++++- cli/graph_container.rs | 4 ++- cli/lsp/testing/execution.rs | 1 + cli/module_loader.rs | 22 ++++++++++++ cli/tools/bench/mod.rs | 6 ++-- cli/tools/fmt.rs | 34 ++++++++++++++----- cli/tools/lint/mod.rs | 21 ++++++++---- cli/tools/registry/pm/cache_deps.rs | 1 + cli/tools/test/mod.rs | 5 ++- tests/specs/bench/default_ts/__test__.jsonc | 4 +-- tests/specs/bench/default_ts/ext.out | 6 ++++ .../specs/bench/default_ts/extensionless.out | 6 ++++ tests/specs/run/default_ts/__test__.jsonc | 4 +-- tests/specs/test/default_ts/__test__.jsonc | 4 +-- tests/specs/test/default_ts/ext.out | 6 ++++ tests/specs/test/default_ts/extensionless.out | 6 ++++ 17 files changed, 117 insertions(+), 26 deletions(-) create mode 100644 tests/specs/bench/default_ts/ext.out create mode 100644 tests/specs/bench/default_ts/extensionless.out create mode 100644 tests/specs/test/default_ts/ext.out create mode 100644 tests/specs/test/default_ts/extensionless.out diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 3b4e277607eb1f..3be7d0af2c9031 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -108,7 +108,7 @@ pub use deno_cache_dir::HttpCache; /// a concise interface to the DENO_DIR when building module graphs. pub struct FetchCacher { file_fetcher: Arc, - file_header_overrides: HashMap>, + pub file_header_overrides: HashMap>, global_http_cache: Arc, npm_resolver: Arc, module_info_cache: Arc, diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index ace4d3c7eefdee..7242b446913bf3 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -138,11 +138,20 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result { let local = specifier.to_file_path().map_err(|_| { uri_error(format!("Invalid file path.\n Specifier: {specifier}")) })?; + // If it doesnt have a extension, we want to treat it as typescript by default + let headers = if local.extension().is_none() { + Some(HashMap::from([( + "content-type".to_string(), + "application/typescript".to_string(), + )])) + } else { + None + }; let bytes = fs::read(local)?; Ok(File { specifier: specifier.clone(), - maybe_headers: None, + maybe_headers: headers, source: bytes.into(), }) } diff --git a/cli/graph_container.rs b/cli/graph_container.rs index 9f71045c6916ae..0d582c30ffed89 100644 --- a/cli/graph_container.rs +++ b/cli/graph_container.rs @@ -65,6 +65,7 @@ impl MainModuleGraphContainer { pub async fn check_specifiers( &self, specifiers: &[ModuleSpecifier], + ext_overwrite: Option<&String>, ) -> Result<(), AnyError> { let mut graph_permit = self.acquire_update_permit().await; let graph = graph_permit.graph_mut(); @@ -76,6 +77,7 @@ impl MainModuleGraphContainer { false, self.cli_options.ts_type_lib_window(), PermissionsContainer::allow_all(), + ext_overwrite, ) .await?; graph_permit.commit(); @@ -94,7 +96,7 @@ impl MainModuleGraphContainer { log::warn!("{} No matching files found.", colors::yellow("Warning")); } - self.check_specifiers(&specifiers).await + self.check_specifiers(&specifiers, None).await } pub fn collect_specifiers( diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 4ac565aa0b7c8e..db3e068afaff29 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -237,6 +237,7 @@ impl TestRun { .iter() .map(|s| (s.clone(), test::TestMode::Executable)) .collect(), + None, ) .await?; diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 186eb021011b7b..78066ed0fc07f8 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -107,11 +107,32 @@ impl ModuleLoadPreparer { is_dynamic: bool, lib: TsTypeLib, permissions: PermissionsContainer, + ext_overwrite: Option<&String>, ) -> Result<(), AnyError> { log::debug!("Preparing module load."); let _pb_clear_guard = self.progress_bar.clear_guard(); let mut cache = self.module_graph_builder.create_fetch_cacher(permissions); + if let Some(ext) = ext_overwrite { + let maybe_content_type = match ext.as_str() { + "ts" => Some("text/typescript"), + "tsx" => Some("text/tsx"), + "js" => Some("text/javascript"), + "jsx" => Some("text/jsx"), + _ => None, + }; + if let Some(content_type) = maybe_content_type { + for root in roots { + cache.file_header_overrides.insert( + root.clone(), + std::collections::HashMap::from([( + "content-type".to_string(), + content_type.to_string(), + )]), + ); + } + } + } log::debug!("Building module graph."); let has_type_checked = !graph.roots.is_empty(); @@ -770,6 +791,7 @@ impl ModuleLoader is_dynamic, lib, root_permissions, + None, ) .await?; update_permit.commit(); diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index 44ae8321d281e3..a0e0215a3cb6b1 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -434,7 +434,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(()); @@ -557,7 +559,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/fmt.rs b/cli/tools/fmt.rs index 12db150bf12e79..deb942ab37032a 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -120,7 +120,13 @@ pub async fn format( }; } - format_files(caches, cli_options, &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, cli_options, &fmt_flags, paths_with_options_batches).await?; + format_files(caches, cli_options, &fmt_flags, paths_with_options_batches) + .await?; } Ok(()) @@ -213,11 +220,16 @@ fn collect_fmt_files( cli_options: &CliOptions, files: FilePatterns, ) -> Result, AnyError> { - 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) + 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 ) and its code blocks @@ -669,7 +681,13 @@ impl Formatter for RealFormatter { &file_path, &file_contents.text, |file_path, file_text| { - format_file(file_path, file_text, &fmt_options, &unstable_options, ext.clone()) + format_file( + file_path, + file_text, + &fmt_options, + &unstable_options, + ext.clone(), + ) }, ) { Ok(Some(formatted_text)) => { diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 036a92fd2a70d0..a52d4e4625b1ef 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -365,7 +365,11 @@ impl WorkspaceLinter { } } - let r = linter.lint_file(&file_path, file_text, cli_options.ext_flag().as_deref()); + 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() { @@ -425,11 +429,16 @@ fn collect_lint_files( cli_options: &CliOptions, files: FilePatterns, ) -> Result, AnyError> { - 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) + 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)] diff --git a/cli/tools/registry/pm/cache_deps.rs b/cli/tools/registry/pm/cache_deps.rs index d292c32f589d9e..4316d80dee5aa6 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, deno_runtime::deno_permissions::PermissionsContainer::allow_all(), + None, ) .await?; } diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 7b172cf879ff32..12512f92abf7af 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1358,6 +1358,7 @@ pub async fn check_specifiers( file_fetcher: &FileFetcher, main_graph_container: &Arc, specifiers: Vec<(ModuleSpecifier, TestMode)>, + ext_overwrite: Option<&String>, ) -> Result<(), AnyError> { let inline_files = fetch_inline_files( file_fetcher, @@ -1395,7 +1396,7 @@ pub async fn check_specifiers( } main_graph_container - .check_specifiers(&module_specifiers) + .check_specifiers(&module_specifiers, ext_overwrite) .await?; Ok(()) @@ -1789,6 +1790,7 @@ pub async fn run_tests( file_fetcher, main_graph_container, specifiers_with_mode.clone(), + cli_options.ext_flag().as_ref(), ) .await?; @@ -1959,6 +1961,7 @@ pub async fn run_tests_with_watch( file_fetcher, main_graph_container, specifiers_with_mode.clone(), + cli_options.ext_flag().as_ref(), ) .await?; diff --git a/tests/specs/bench/default_ts/__test__.jsonc b/tests/specs/bench/default_ts/__test__.jsonc index a56a1c25377b1f..a5657290dfb010 100644 --- a/tests/specs/bench/default_ts/__test__.jsonc +++ b/tests/specs/bench/default_ts/__test__.jsonc @@ -3,11 +3,11 @@ "tests": { "ext_flag": { "args": "bench --ext=ts as_ts.js", - "output": "Checked 1 file\n" + "output": "ext.out" }, "extensionless": { "args": "bench extensionless", - "output": "Checked 1 file\n" + "output": "extensionless.out" } } } diff --git a/tests/specs/bench/default_ts/ext.out b/tests/specs/bench/default_ts/ext.out new file mode 100644 index 00000000000000..bb5003015d7a29 --- /dev/null +++ b/tests/specs/bench/default_ts/ext.out @@ -0,0 +1,6 @@ +Check file:///[WILDCARD]/as_ts.js + CPU | Apple M3 Max +Runtime | Deno 2.0.0-rc.1 (aarch64-apple-darwin) + +file:///[WILDCARD]/as_ts.js +[WILDCARD] diff --git a/tests/specs/bench/default_ts/extensionless.out b/tests/specs/bench/default_ts/extensionless.out new file mode 100644 index 00000000000000..81b345fa1f0262 --- /dev/null +++ b/tests/specs/bench/default_ts/extensionless.out @@ -0,0 +1,6 @@ +Check file:///[WILDCARD]/extensionless + CPU | Apple M3 Max +Runtime | Deno 2.0.0-rc.1 (aarch64-apple-darwin) + +file:///[WILDCARD]/extensionless +[WILDCARD] diff --git a/tests/specs/run/default_ts/__test__.jsonc b/tests/specs/run/default_ts/__test__.jsonc index 3da2a1f7d42656..07e3d8336823c5 100644 --- a/tests/specs/run/default_ts/__test__.jsonc +++ b/tests/specs/run/default_ts/__test__.jsonc @@ -3,8 +3,8 @@ "tests": { "stdin": { "args": "run -", - "input": "const x: string = \"foo\";", - "output": "const x: string = \"foo\";\n" + "input": "const x: string = \"foo\";console.log(x)", + "output": "foo\n" }, "ext_flag": { "args": "run --ext=ts as_ts.js", diff --git a/tests/specs/test/default_ts/__test__.jsonc b/tests/specs/test/default_ts/__test__.jsonc index 3eb76d7273d95a..778fca5c5183fa 100644 --- a/tests/specs/test/default_ts/__test__.jsonc +++ b/tests/specs/test/default_ts/__test__.jsonc @@ -3,11 +3,11 @@ "tests": { "ext_flag": { "args": "test --ext=ts as_ts.js", - "output": "Checked 1 file\n" + "output": "ext.out" }, "extensionless": { "args": "test extensionless", - "output": "Checked 1 file\n" + "output": "extensionless.out" } } } diff --git a/tests/specs/test/default_ts/ext.out b/tests/specs/test/default_ts/ext.out new file mode 100644 index 00000000000000..f184c12a8ae5d9 --- /dev/null +++ b/tests/specs/test/default_ts/ext.out @@ -0,0 +1,6 @@ +Check file:///[WILDCARD]/as_ts.js +running 1 test from ./as_ts.js +foo ... ok (0ms) + +ok | 1 passed | 0 failed (1ms) + diff --git a/tests/specs/test/default_ts/extensionless.out b/tests/specs/test/default_ts/extensionless.out new file mode 100644 index 00000000000000..5d5ecf872f424f --- /dev/null +++ b/tests/specs/test/default_ts/extensionless.out @@ -0,0 +1,6 @@ +Check file:///[WILDCARD]/extensionless +running 1 test from ./extensionless +foo ... ok (0ms) + +ok | 1 passed | 0 failed (1ms) + From 1b4fc1594c0f967cc3d7c7a9223b9b10cbedf14f Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 03:49:46 +0200 Subject: [PATCH 05/14] ignore files --- .dprint.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.dprint.json b/.dprint.json index 193db6febac60d..7ab480a4e8a889 100644 --- a/.dprint.json +++ b/.dprint.json @@ -39,10 +39,14 @@ "tests/node_compat/runner/TODO.md", "tests/node_compat/test", "tests/registry/", + "tests/specs/bench/default_ts", "tests/specs/fmt", "tests/specs/lint/bom", + "tests/specs/lint/default_ts", "tests/specs/lint/syntax_error_reporting", "tests/specs/publish/no_check_surfaces_syntax_error", + "tests/specs/run/default_ts", + "tests/specs/test/default_ts", "tests/testdata/byte_order_mark.ts", "tests/testdata/encoding", "tests/testdata/file_extensions/ts_with_js_extension.js", From 89e89c12f668b19e907e1d20a7392bfd04268fc0 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 12:01:34 +0200 Subject: [PATCH 06/14] fix some tests --- cli/tools/check.rs | 2 +- cli/tools/test/mod.rs | 10 ++++++++-- tests/integration/run_tests.rs | 11 ----------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 9c464fa1694fe8..c22afbb9a7fb86 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/test/mod.rs b/cli/tools/test/mod.rs index bfff90c4d8ef8d..e81abad0b26987 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, cli_options.ext_flag().as_ref()) + .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, cli_options.ext_flag().as_ref()) + .check_specifiers( + &specifiers_for_typecheck_and_test, + cli_options.ext_flag().as_ref(), + ) .await?; if workspace_test_options.no_run { diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index b47af238b75c21..39565496cc1b75 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -148,11 +148,6 @@ itest!(_021_mjs_modules { output: "run/021_mjs_modules.ts.out", }); -itest!(_023_no_ext { - args: "run --reload --check run/023_no_ext", - output: "run/023_no_ext.out", -}); - itest!(_025_reload_js_type_error { args: "run --quiet --reload run/025_reload_js_type_error.js", output: "run/025_reload_js_type_error.js.out", @@ -4209,12 +4204,6 @@ itest!(error_cause_recursive { exit_code: 1, }); -itest!(default_file_extension_is_js { - args: "run --check file_extensions/js_without_extension", - output: "file_extensions/js_without_extension.out", - exit_code: 0, -}); - itest!(js_without_extension { args: "run --ext js --check file_extensions/js_without_extension", output: "file_extensions/js_without_extension.out", From 29d98843f95cbb784c368b4f8724a982abdf4c5b Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 12:38:14 +0200 Subject: [PATCH 07/14] update lint --- tools/lint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lint.js b/tools/lint.js index a9f9400061f2d6..de0db015f31ca1 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -218,7 +218,7 @@ async function ensureNoNewITests() { "pm_tests.rs": 0, "publish_tests.rs": 0, "repl_tests.rs": 0, - "run_tests.rs": 333, + "run_tests.rs": 331, "shared_library_tests.rs": 0, "task_tests.rs": 4, "test_tests.rs": 0, From 6e64d24f35a596534ecdd71c2dbca0796f1dca72 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 13:22:41 +0200 Subject: [PATCH 08/14] fix --- cli/args/flags.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 21902f9e1297b8..b37aea865cd7e9 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -2118,8 +2118,6 @@ Ignore formatting a file by adding an ignore comment at the top of the file: Arg::new("ext") .long("ext") .help("Set content type of the supplied file") - // prefer using ts for formatting instead of js because ts works in more scenarios - .default_value("ts") .hide_default_value(true) .value_parser([ "ts", "tsx", "js", "jsx", "md", "json", "jsonc", "css", "scss", From 5238cb55ab45704a29fdb5e9f60ff94412a44e2f Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 13:55:03 +0200 Subject: [PATCH 09/14] fix --- cli/args/flags.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index b37aea865cd7e9..56a013fbf67dce 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -6269,7 +6269,6 @@ mod tests { unstable_yaml: false, watch: Default::default(), }), - ext: Some("ts".to_string()), ..Flags::default() } ); From ffd01db3c300929682cd591a36163d5fbcb94cf9 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 14:19:23 +0200 Subject: [PATCH 10/14] fix test --- cli/args/flags.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 56a013fbf67dce..7d0dabb78aac11 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -2118,7 +2118,6 @@ Ignore formatting a file by adding an ignore comment at the top of the file: Arg::new("ext") .long("ext") .help("Set content type of the supplied file") - .hide_default_value(true) .value_parser([ "ts", "tsx", "js", "jsx", "md", "json", "jsonc", "css", "scss", "sass", "less", "html", "svelte", "vue", "astro", "yml", "yaml", @@ -6295,7 +6294,6 @@ mod tests { unstable_yaml: false, watch: Default::default(), }), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6322,7 +6320,6 @@ mod tests { unstable_yaml: false, watch: Default::default(), }), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6349,7 +6346,6 @@ mod tests { unstable_yaml: false, watch: Some(Default::default()), }), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6389,7 +6385,6 @@ mod tests { exclude: vec![], }) }), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6423,7 +6418,6 @@ mod tests { unstable_yaml: false, watch: Some(Default::default()), }), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6450,7 +6444,6 @@ mod tests { unstable_yaml: false, watch: Default::default(), }), - ext: Some("ts".to_string()), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), ..Flags::default() } @@ -6486,7 +6479,6 @@ mod tests { watch: Some(Default::default()), }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6525,7 +6517,6 @@ mod tests { unstable_yaml: false, watch: Default::default(), }), - ext: Some("ts".to_string()), ..Flags::default() } ); @@ -6559,7 +6550,6 @@ mod tests { unstable_yaml: false, watch: Default::default(), }), - ext: Some("ts".to_string()), ..Flags::default() } ); From 82e517702e0791f80a9acb45febfcef89f49c016 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 15:02:43 +0200 Subject: [PATCH 11/14] fix --- tests/specs/test/default_ts/ext.out | 4 +--- tests/specs/test/default_ts/extensionless.out | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/specs/test/default_ts/ext.out b/tests/specs/test/default_ts/ext.out index f184c12a8ae5d9..55f7526a54e35d 100644 --- a/tests/specs/test/default_ts/ext.out +++ b/tests/specs/test/default_ts/ext.out @@ -1,6 +1,4 @@ Check file:///[WILDCARD]/as_ts.js running 1 test from ./as_ts.js -foo ... ok (0ms) - -ok | 1 passed | 0 failed (1ms) +[WILDCARD] diff --git a/tests/specs/test/default_ts/extensionless.out b/tests/specs/test/default_ts/extensionless.out index 5d5ecf872f424f..20d4ee2cb090aa 100644 --- a/tests/specs/test/default_ts/extensionless.out +++ b/tests/specs/test/default_ts/extensionless.out @@ -1,6 +1,4 @@ Check file:///[WILDCARD]/extensionless running 1 test from ./extensionless -foo ... ok (0ms) - -ok | 1 passed | 0 failed (1ms) +[WILDCARD] From f0caa06d92685d1ead2436b372e625a3e9e9213b Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 15:29:54 +0200 Subject: [PATCH 12/14] fix --- tests/specs/bench/default_ts/ext.out | 3 +-- tests/specs/bench/default_ts/extensionless.out | 3 +-- tests/specs/fmt/default_ts/__test__.jsonc | 6 +++--- tests/specs/lint/default_ts/__test__.jsonc | 6 +++--- tests/specs/lint/default_ts/as_ts.js | 2 +- tests/specs/lint/default_ts/extensionless | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/specs/bench/default_ts/ext.out b/tests/specs/bench/default_ts/ext.out index bb5003015d7a29..be4e34aac3d687 100644 --- a/tests/specs/bench/default_ts/ext.out +++ b/tests/specs/bench/default_ts/ext.out @@ -1,6 +1,5 @@ Check file:///[WILDCARD]/as_ts.js - CPU | Apple M3 Max -Runtime | Deno 2.0.0-rc.1 (aarch64-apple-darwin) +[WILDCARD] file:///[WILDCARD]/as_ts.js [WILDCARD] diff --git a/tests/specs/bench/default_ts/extensionless.out b/tests/specs/bench/default_ts/extensionless.out index 81b345fa1f0262..e9442310efa905 100644 --- a/tests/specs/bench/default_ts/extensionless.out +++ b/tests/specs/bench/default_ts/extensionless.out @@ -1,6 +1,5 @@ Check file:///[WILDCARD]/extensionless - CPU | Apple M3 Max -Runtime | Deno 2.0.0-rc.1 (aarch64-apple-darwin) +[WILDCARD] file:///[WILDCARD]/extensionless [WILDCARD] diff --git a/tests/specs/fmt/default_ts/__test__.jsonc b/tests/specs/fmt/default_ts/__test__.jsonc index f1fe0c64625628..24d77a79ef0979 100644 --- a/tests/specs/fmt/default_ts/__test__.jsonc +++ b/tests/specs/fmt/default_ts/__test__.jsonc @@ -2,16 +2,16 @@ "tempDir": true, "tests": { "stdin": { - "args": "lint -", + "args": "fmt -", "input": "const x: string = \"foo\";", "output": "const x: string = \"foo\";\n" }, "ext_flag": { - "args": "lint --ext=ts as_ts.js", + "args": "fmt --ext=ts as_ts.js", "output": "Checked 1 file\n" }, "extensionless": { - "args": "lint extensionless", + "args": "fmt extensionless", "output": "Checked 1 file\n" } } diff --git a/tests/specs/lint/default_ts/__test__.jsonc b/tests/specs/lint/default_ts/__test__.jsonc index 24d77a79ef0979..f1fe0c64625628 100644 --- a/tests/specs/lint/default_ts/__test__.jsonc +++ b/tests/specs/lint/default_ts/__test__.jsonc @@ -2,16 +2,16 @@ "tempDir": true, "tests": { "stdin": { - "args": "fmt -", + "args": "lint -", "input": "const x: string = \"foo\";", "output": "const x: string = \"foo\";\n" }, "ext_flag": { - "args": "fmt --ext=ts as_ts.js", + "args": "lint --ext=ts as_ts.js", "output": "Checked 1 file\n" }, "extensionless": { - "args": "fmt extensionless", + "args": "lint extensionless", "output": "Checked 1 file\n" } } diff --git a/tests/specs/lint/default_ts/as_ts.js b/tests/specs/lint/default_ts/as_ts.js index 72a35c2a887b82..3508e99b63291a 100644 --- a/tests/specs/lint/default_ts/as_ts.js +++ b/tests/specs/lint/default_ts/as_ts.js @@ -1 +1 @@ -const x: string = "foo"; +const _x: string = "foo"; diff --git a/tests/specs/lint/default_ts/extensionless b/tests/specs/lint/default_ts/extensionless index 72a35c2a887b82..3508e99b63291a 100644 --- a/tests/specs/lint/default_ts/extensionless +++ b/tests/specs/lint/default_ts/extensionless @@ -1 +1 @@ -const x: string = "foo"; +const _x: string = "foo"; From 0d60d266277c02f12f4c58a8d43fe75c8fb3b1ea Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 16:17:33 +0200 Subject: [PATCH 13/14] fix --- cli/tools/fmt.rs | 2 +- tests/specs/lint/default_ts/__test__.jsonc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 8538419cab7c05..7bdf0fbb66c469 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -465,7 +465,7 @@ pub fn format_file( unstable_options: &UnstableFmtOptions, ext: Option, ) -> Result, AnyError> { - let ext = ext.or_else(|| 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" => { diff --git a/tests/specs/lint/default_ts/__test__.jsonc b/tests/specs/lint/default_ts/__test__.jsonc index f1fe0c64625628..ff0f342ab843fa 100644 --- a/tests/specs/lint/default_ts/__test__.jsonc +++ b/tests/specs/lint/default_ts/__test__.jsonc @@ -3,8 +3,8 @@ "tests": { "stdin": { "args": "lint -", - "input": "const x: string = \"foo\";", - "output": "const x: string = \"foo\";\n" + "input": "const _x: string = \"foo\";", + "output": "Checked 1 file\n" }, "ext_flag": { "args": "lint --ext=ts as_ts.js", From 5e723e49e547b867d7457cb12a55c307ce545ab0 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 18 Sep 2024 16:35:07 +0200 Subject: [PATCH 14/14] fmt --- cli/tools/fmt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 7bdf0fbb66c469..3f927545d95fad 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -465,7 +465,9 @@ pub fn format_file( unstable_options: &UnstableFmtOptions, ext: Option, ) -> Result, AnyError> { - let ext = ext.or_else(|| get_extension(file_path)).unwrap_or("ts".to_string()); + let ext = ext + .or_else(|| get_extension(file_path)) + .unwrap_or("ts".to_string()); match ext.as_str() { "md" | "mkd" | "mkdn" | "mdwn" | "mdown" | "markdown" => {