From 0da81205d57e947e82aa02206f8ba6822c624ebc Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 2 Aug 2024 15:52:48 +0200 Subject: feat(unstable/fmt): move yaml formatting behind unstable flag (#24848) This moves YAML formatting behind an unstable flag for Deno 1.46. This will make it opt-in to start and then we can remove the flag to make it on by default in version of Deno after that. This can be specified by doing `deno fmt --unstable-yaml` or by specifying the following in a deno.json file: ```json { "unstable": ["fmt-yaml"] } ``` --- cli/args/mod.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'cli/args/mod.rs') 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); -- cgit v1.2.3