summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-11-04 17:57:29 +0000
committerGitHub <noreply@github.com>2024-11-04 17:57:29 +0000
commit9a39a98b57de4183e054ab170592c85c97fac183 (patch)
treeec13c5963d56f506d4111e9447d804d0214f2331 /cli/tools
parentfe9f0ee5934871175758857899fe64e56c397fd5 (diff)
fix(fmt): ignore file directive for YAML files (#26717)
Closes https://github.com/denoland/deno/issues/26712 Support `# deno-fmt-ignore-file` directive for YAML files. Also added tests for single line ignores.
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/fmt.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 81af25c34..837883561 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -353,6 +353,21 @@ fn format_yaml(
file_text: &str,
fmt_options: &FmtOptionsConfig,
) -> Result<Option<String>, AnyError> {
+ let ignore_file = file_text
+ .lines()
+ .take_while(|line| line.starts_with('#'))
+ .any(|line| {
+ line
+ .strip_prefix('#')
+ .unwrap()
+ .trim()
+ .starts_with("deno-fmt-ignore-file")
+ });
+
+ if ignore_file {
+ return Ok(None);
+ }
+
let formatted_str =
pretty_yaml::format_text(file_text, &get_resolved_yaml_config(fmt_options))
.map_err(AnyError::from)?;