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

@ -92,6 +92,7 @@ use crate::args::CaData;
use crate::args::CacheSetting;
use crate::args::CliOptions;
use crate::args::Flags;
use crate::args::UnstableFmtOptions;
use crate::factory::CliFactory;
use crate::file_fetcher::FileFetcher;
use crate::graph_util;
@ -1361,6 +1362,16 @@ impl Inner {
.clone();
fmt_options.use_tabs = Some(!params.options.insert_spaces);
fmt_options.indent_width = Some(params.options.tab_size as u8);
let maybe_workspace = self
.config
.tree
.data_for_specifier(&specifier)
.map(|d| &d.member_dir.workspace);
let unstable_options = UnstableFmtOptions {
yaml: maybe_workspace
.map(|w| w.has_unstable("fmt-yaml"))
.unwrap_or(false),
};
let document = document.clone();
move || {
let format_result = match document.maybe_parsed_source() {
@ -1378,7 +1389,12 @@ impl Inner {
.map(|ext| file_path.with_extension(ext))
.unwrap_or(file_path);
// it's not a js/ts file, so attempt to format its contents
format_file(&file_path, document.content(), &fmt_options)
format_file(
&file_path,
document.content(),
&fmt_options,
&unstable_options,
)
}
};
match format_result {