summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
authorPig Fang <g-plane@hotmail.com>2024-08-10 00:52:23 +0800
committerGitHub <noreply@github.com>2024-08-09 18:52:23 +0200
commit82884348cb1b424a4c4452ef734bc4e760926b2f (patch)
treea64142bb68dc2509dd9ec421a9a88fcec1e6f65e /cli/args
parent218ee1b1ffebbb53aa82c8ce55e7ee7061342249 (diff)
feat(fmt): support CSS, SCSS, Sass and Less (#24870)
This PR integrates [Malva](https://github.com/g-plane/malva) into `deno fmt`, which introduces the ability to format CSS, SCSS, Sass and Less files. On Linux x64 6.10, this PR increases about 800KiB: ``` ❯ wc -c target/release/deno 125168728 target/release/deno ❯ wc -c target/release/deno 124349456 target/release/deno ```
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs25
-rw-r--r--cli/args/mod.rs7
2 files changed, 29 insertions, 3 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index e28ce549b..acdcaf8a7 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_css: bool,
pub unstable_yaml: bool,
}
@@ -2018,8 +2019,8 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
// prefer using ts for formatting instead of js because ts works in more scenarios
.default_value("ts")
.value_parser([
- "ts", "tsx", "js", "jsx", "md", "json", "jsonc", "yml", "yaml",
- "ipynb",
+ "ts", "tsx", "js", "jsx", "md", "json", "jsonc", "css", "scss",
+ "sass", "less", "yml", "yaml", "ipynb",
]),
)
.arg(
@@ -2097,6 +2098,13 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
),
)
.arg(
+ Arg::new("unstable-css")
+ .long("unstable-css")
+ .help("Enable formatting CSS, SCSS, Sass and Less files.")
+ .value_parser(FalseyValueParser::new())
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
Arg::new("unstable-yaml")
.long("unstable-yaml")
.help("Enable formatting YAML files.")
@@ -4163,6 +4171,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_css = matches.get_flag("unstable-css");
let unstable_yaml = matches.get_flag("unstable-yaml");
flags.subcommand = DenoSubcommand::Fmt(FmtFlags {
@@ -4175,6 +4184,7 @@ fn fmt_parse(flags: &mut Flags, matches: &mut ArgMatches) {
prose_wrap,
no_semicolons,
watch: watch_arg_parse(matches),
+ unstable_css,
unstable_yaml,
});
}
@@ -5881,6 +5891,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Default::default(),
}),
@@ -5905,6 +5916,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Default::default(),
}),
@@ -5929,6 +5941,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Default::default(),
}),
@@ -5953,6 +5966,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Some(Default::default()),
}),
@@ -5966,6 +5980,7 @@ mod tests {
"fmt",
"--watch",
"--no-clear-screen",
+ "--unstable-css",
"--unstable-yaml"
]);
assert_eq!(
@@ -5983,6 +5998,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: true,
unstable_yaml: true,
watch: Some(WatchFlags {
hmr: false,
@@ -6018,6 +6034,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Some(Default::default()),
}),
@@ -6042,6 +6059,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Default::default(),
}),
@@ -6074,6 +6092,7 @@ mod tests {
single_quote: None,
prose_wrap: None,
no_semicolons: None,
+ unstable_css: false,
unstable_yaml: false,
watch: Some(Default::default()),
}),
@@ -6111,6 +6130,7 @@ mod tests {
single_quote: Some(true),
prose_wrap: Some("never".to_string()),
no_semicolons: Some(true),
+ unstable_css: false,
unstable_yaml: false,
watch: Default::default(),
}),
@@ -6142,6 +6162,7 @@ mod tests {
single_quote: Some(false),
prose_wrap: None,
no_semicolons: Some(false),
+ unstable_css: false,
unstable_yaml: false,
watch: Default::default(),
}),
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index bd49c0c15..afad0528c 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -281,6 +281,7 @@ impl BenchOptions {
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct UnstableFmtOptions {
+ pub css: bool,
pub yaml: bool,
}
@@ -314,6 +315,7 @@ impl FmtOptions {
Self {
options: resolve_fmt_options(fmt_flags, fmt_config.options),
unstable: UnstableFmtOptions {
+ css: unstable.css || fmt_flags.unstable_css,
yaml: unstable.yaml || fmt_flags.unstable_yaml,
},
files: fmt_config.files,
@@ -1330,8 +1332,10 @@ impl CliOptions {
}
pub fn resolve_config_unstable_fmt_options(&self) -> UnstableFmtOptions {
+ let workspace = self.workspace();
UnstableFmtOptions {
- yaml: self.workspace().has_unstable("fmt-yaml"),
+ css: workspace.has_unstable("fmt-css"),
+ yaml: workspace.has_unstable("fmt-yaml"),
}
}
@@ -1664,6 +1668,7 @@ impl CliOptions {
"sloppy-imports",
"byonm",
"bare-node-builtins",
+ "fmt-css",
"fmt-yaml",
]);
// add more unstable flags to the same vector holding granular flags