diff options
-rw-r--r-- | cli/args/config_file.rs | 8 | ||||
-rw-r--r-- | cli/args/flags.rs | 23 | ||||
-rw-r--r-- | cli/args/mod.rs | 10 | ||||
-rw-r--r-- | cli/schemas/config-file.v1.json | 8 | ||||
-rw-r--r-- | cli/tests/testdata/fmt/with_config/deno.jsonc | 3 | ||||
-rw-r--r-- | cli/tests/testdata/fmt/with_config/subdir/a.ts | 18 | ||||
-rw-r--r-- | cli/tests/testdata/run/with_config/auto_discovery_log.out | 2 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 12 |
8 files changed, 72 insertions, 12 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 2320a0b0d..106a15ddf 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -373,6 +373,13 @@ pub enum ProseWrap { Preserve, } +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] +pub enum SemiColons { + Prefer, + Asi, +} + #[derive(Clone, Debug, Default, Serialize, Deserialize)] #[serde(default, deny_unknown_fields, rename_all = "camelCase")] pub struct FmtOptionsConfig { @@ -381,6 +388,7 @@ pub struct FmtOptionsConfig { pub indent_width: Option<u8>, pub single_quote: Option<bool>, pub prose_wrap: Option<ProseWrap>, + pub semi_colons: Option<SemiColons>, } #[derive(Clone, Debug, Default, Deserialize)] diff --git a/cli/args/flags.rs b/cli/args/flags.rs index c6c922bd6..a5aff3d09 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -131,6 +131,7 @@ pub struct FmtFlags { pub indent_width: Option<NonZeroU8>, pub single_quote: Option<bool>, pub prose_wrap: Option<String>, + pub semi_colons: Option<String>, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -1214,6 +1215,13 @@ Ignore formatting a file by adding an ignore comment at the top of the file: .possible_values(["always", "never", "preserve"]) .help("Define how prose should be wrapped. Defaults to always."), ) + .arg( + Arg::new("options-semi") + .long("options-semi") + .takes_value(true) + .possible_values(["prefer", "asi"]) + .help("Use semi colons. Defaults to prefer."), + ) } fn init_subcommand<'a>() -> Command<'a> { @@ -2571,6 +2579,7 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) { let prose_wrap = matches .value_of("options-prose-wrap") .map(ToString::to_string); + let semi_colons = matches.value_of("options-semi").map(ToString::to_string); flags.subcommand = DenoSubcommand::Fmt(FmtFlags { check: matches.is_present("check"), @@ -2581,6 +2590,7 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) { indent_width, single_quote, prose_wrap, + semi_colons, }); } @@ -3598,6 +3608,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), ..Flags::default() } @@ -3619,6 +3630,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), ..Flags::default() } @@ -3640,6 +3652,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), ..Flags::default() } @@ -3661,6 +3674,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), watch: Some(vec![]), ..Flags::default() @@ -3684,6 +3698,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), watch: Some(vec![]), no_clear_screen: true, @@ -3714,6 +3729,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), watch: Some(vec![]), ..Flags::default() @@ -3736,6 +3752,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), ..Flags::default() @@ -3765,6 +3782,7 @@ mod tests { indent_width: None, single_quote: None, prose_wrap: None, + semi_colons: None, }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), watch: Some(vec![]), @@ -3782,7 +3800,9 @@ mod tests { "4", "--options-single-quote", "--options-prose-wrap", - "never" + "never", + "--options-semi", + "asi" ]); assert_eq!( r.unwrap(), @@ -3799,6 +3819,7 @@ mod tests { indent_width: Some(NonZeroU8::new(4).unwrap()), single_quote: Some(true), prose_wrap: Some("never".to_string()), + semi_colons: Some("asi".to_string()), }), ..Flags::default() } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index a81c84b59..6d81ae2af 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -15,6 +15,7 @@ pub use config_file::FmtOptionsConfig; pub use config_file::JsxImportSourceConfig; pub use config_file::LintRulesConfig; pub use config_file::ProseWrap; +pub use config_file::SemiColons; pub use config_file::TsConfig; pub use config_file::TsConfigForEmit; pub use config_file::TsConfigType; @@ -199,6 +200,15 @@ fn resolve_fmt_options( _ => unreachable!(), }); } + + if let Some(semi_colons) = &fmt_flags.semi_colons { + options.semi_colons = Some(match semi_colons.as_str() { + "prefer" => SemiColons::Prefer, + "asi" => SemiColons::Asi, + // validators in `flags.rs` makes other values unreachable + _ => unreachable!(), + }); + } } options diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index 4eece59df..96b1f202b 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -321,6 +321,14 @@ "never", "preserve" ] + }, + "semiColons": { + "description": "Whether to prefer using semicolons.", + "default": "prefer", + "enum": [ + "prefer", + "asi" + ] } } } diff --git a/cli/tests/testdata/fmt/with_config/deno.jsonc b/cli/tests/testdata/fmt/with_config/deno.jsonc index 3b9474e64..8901d6222 100644 --- a/cli/tests/testdata/fmt/with_config/deno.jsonc +++ b/cli/tests/testdata/fmt/with_config/deno.jsonc @@ -13,7 +13,8 @@ "lineWidth": 40, "indentWidth": 8, "singleQuote": true, - "proseWrap": "always" + "proseWrap": "always", + "semiColons": "asi" } } } diff --git a/cli/tests/testdata/fmt/with_config/subdir/a.ts b/cli/tests/testdata/fmt/with_config/subdir/a.ts index 4baf8d485..5474b3aa3 100644 --- a/cli/tests/testdata/fmt/with_config/subdir/a.ts +++ b/cli/tests/testdata/fmt/with_config/subdir/a.ts @@ -4,33 +4,33 @@ Deno.test( const response = await fetch( 'http://localhost:4545/assets/fixture.json', - ); + ) const response1 = - response.clone(); + response.clone() assert( response !== response1, - ); + ) assertEquals( response.status, response1 .status, - ); + ) assertEquals( response.statusText, response1 .statusText, - ); + ) const u8a = new Uint8Array( await response .arrayBuffer(), - ); + ) const u8a1 = new Uint8Array( await response1 .arrayBuffer(), - ); + ) for ( let i = 0; i < @@ -40,7 +40,7 @@ Deno.test( assertEquals( u8a[i], u8a1[i], - ); + ) } }, -); +) diff --git a/cli/tests/testdata/run/with_config/auto_discovery_log.out b/cli/tests/testdata/run/with_config/auto_discovery_log.out index a1f4ada1d..601c1adc6 100644 --- a/cli/tests/testdata/run/with_config/auto_discovery_log.out +++ b/cli/tests/testdata/run/with_config/auto_discovery_log.out @@ -1,3 +1,3 @@ -DEBUG RS - deno::args::config_file:529 - Config file found at '[WILDCARD]deno.jsonc' +DEBUG RS - [WILDCARD] - Config file found at '[WILDCARD]deno.jsonc' [WILDCARD] ok diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index d987d02d6..ae0923903 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -12,6 +12,7 @@ use crate::args::FilesConfig; use crate::args::FmtOptions; use crate::args::FmtOptionsConfig; use crate::args::ProseWrap; +use crate::args::SemiColons; use crate::colors; use crate::util::diff::diff; use crate::util::file_watcher; @@ -511,6 +512,17 @@ fn get_resolved_typescript_config( } } + if let Some(semi_colons) = options.semi_colons { + builder.semi_colons(match semi_colons { + SemiColons::Prefer => { + dprint_plugin_typescript::configuration::SemiColons::Prefer + } + SemiColons::Asi => { + dprint_plugin_typescript::configuration::SemiColons::Asi + } + }); + } + builder.build() } |