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"]
}
```
This commit is contained in:
David Sherret 2024-08-02 15:52:48 +02:00 committed by GitHub
parent 2aad92c30b
commit 0da81205d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 185 additions and 69 deletions

View file

@ -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);