diff options
Diffstat (limited to 'cli/args')
-rw-r--r-- | cli/args/flags.rs | 29 | ||||
-rw-r--r-- | cli/args/mod.rs | 33 |
2 files changed, 56 insertions, 6 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 6affa9f08..e283abc24 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -200,6 +200,7 @@ pub struct FmtFlags { pub prose_wrap: Option<String>, pub no_semicolons: Option<bool>, pub watch: Option<WatchFlags>, + pub unstable_yaml: bool, } impl FmtFlags { @@ -2074,6 +2075,13 @@ Ignore formatting a file by adding an ignore comment at the top of the file: "Don't use semicolons except where necessary. Defaults to false.", ), ) + .arg( + Arg::new("unstable-yaml") + .long("unstable-yaml") + .help("Enable formatting YAML files.") + .value_parser(FalseyValueParser::new()) + .action(ArgAction::SetTrue), + ) }) } @@ -4088,6 +4096,7 @@ fn fmt_parse(flags: &mut Flags, matches: &mut ArgMatches) { let single_quote = matches.remove_one::<bool>("single-quote"); let prose_wrap = matches.remove_one::<String>("prose-wrap"); let no_semicolons = matches.remove_one::<bool>("no-semicolons"); + let unstable_yaml = matches.get_flag("unstable-yaml"); flags.subcommand = DenoSubcommand::Fmt(FmtFlags { check: matches.get_flag("check"), @@ -4099,6 +4108,7 @@ fn fmt_parse(flags: &mut Flags, matches: &mut ArgMatches) { prose_wrap, no_semicolons, watch: watch_arg_parse(matches), + unstable_yaml, }); } @@ -5781,6 +5791,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Default::default(), }), ext: Some("ts".to_string()), @@ -5804,6 +5815,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Default::default(), }), ext: Some("ts".to_string()), @@ -5827,6 +5839,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Default::default(), }), ext: Some("ts".to_string()), @@ -5850,6 +5863,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Some(Default::default()), }), ext: Some("ts".to_string()), @@ -5857,8 +5871,13 @@ mod tests { } ); - let r = - flags_from_vec(svec!["deno", "fmt", "--watch", "--no-clear-screen"]); + let r = flags_from_vec(svec![ + "deno", + "fmt", + "--watch", + "--no-clear-screen", + "--unstable-yaml" + ]); assert_eq!( r.unwrap(), Flags { @@ -5874,6 +5893,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: true, watch: Some(WatchFlags { hmr: false, no_clear_screen: true, @@ -5908,6 +5928,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Some(Default::default()), }), ext: Some("ts".to_string()), @@ -5931,6 +5952,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Default::default(), }), ext: Some("ts".to_string()), @@ -5962,6 +5984,7 @@ mod tests { single_quote: None, prose_wrap: None, no_semicolons: None, + unstable_yaml: false, watch: Some(Default::default()), }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), @@ -5998,6 +6021,7 @@ mod tests { single_quote: Some(true), prose_wrap: Some("never".to_string()), no_semicolons: Some(true), + unstable_yaml: false, watch: Default::default(), }), ext: Some("ts".to_string()), @@ -6028,6 +6052,7 @@ mod tests { single_quote: Some(false), prose_wrap: None, no_semicolons: Some(false), + unstable_yaml: false, watch: Default::default(), }), ext: Some("ts".to_string()), diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 3d35d8c36..fcc1a8d7c 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -279,9 +279,15 @@ impl BenchOptions { } } +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +pub struct UnstableFmtOptions { + pub yaml: bool, +} + #[derive(Clone, Debug)] pub struct FmtOptions { pub options: FmtOptionsConfig, + pub unstable: UnstableFmtOptions, pub files: FilePatterns, } @@ -295,13 +301,21 @@ impl FmtOptions { pub fn new_with_base(base: PathBuf) -> Self { Self { options: FmtOptionsConfig::default(), + unstable: Default::default(), files: FilePatterns::new_with_base(base), } } - pub fn resolve(fmt_config: FmtConfig, fmt_flags: &FmtFlags) -> Self { + pub fn resolve( + fmt_config: FmtConfig, + unstable: UnstableFmtOptions, + fmt_flags: &FmtFlags, + ) -> Self { Self { options: resolve_fmt_options(fmt_flags, fmt_config.options), + unstable: UnstableFmtOptions { + yaml: unstable.yaml || fmt_flags.unstable_yaml, + }, files: fmt_config.files, } } @@ -1306,14 +1320,21 @@ impl CliOptions { let member_configs = self .workspace() .resolve_fmt_config_for_members(&cli_arg_patterns)?; + let unstable = self.resolve_config_unstable_fmt_options(); let mut result = Vec::with_capacity(member_configs.len()); for (ctx, config) in member_configs { - let options = FmtOptions::resolve(config, fmt_flags); + let options = FmtOptions::resolve(config, unstable.clone(), fmt_flags); result.push((ctx, options)); } Ok(result) } + pub fn resolve_config_unstable_fmt_options(&self) -> UnstableFmtOptions { + UnstableFmtOptions { + yaml: self.workspace().has_unstable("fmt-yaml"), + } + } + pub fn resolve_workspace_lint_options( &self, lint_flags: &LintFlags, @@ -1640,8 +1661,12 @@ impl CliOptions { .map(|granular_flag| granular_flag.0) .collect(); - let mut another_unstable_flags = - Vec::from(["sloppy-imports", "byonm", "bare-node-builtins"]); + let mut another_unstable_flags = Vec::from([ + "sloppy-imports", + "byonm", + "bare-node-builtins", + "fmt-yaml", + ]); // add more unstable flags to the same vector holding granular flags all_valid_unstable_flags.append(&mut another_unstable_flags); |