From a07134e23ba84cd3c708b8a778324932c88a3c5c Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 4 Aug 2024 09:44:54 +0800 Subject: [PATCH] feat: add `preferSingleLine` option --- docs/config.md | 54 +++++++++ dprint_plugin/deployment/schema.json | 55 +++++++++ dprint_plugin/src/config.rs | 51 +++++++++ malva/src/config.rs | 105 ++++++++++++++++++ malva/src/doc_gen/at_rule/custom_selector.rs | 7 +- malva/src/doc_gen/helpers.rs | 27 ++++- malva/src/doc_gen/less.rs | 21 +++- malva/src/doc_gen/sass.rs | 35 +++++- malva/src/doc_gen/selector.rs | 19 +++- malva/src/doc_gen/value.rs | 7 +- malva/tests/fmt/css/at-rule/keyframes.snap | 9 +- .../fmt/css/attribute/custom-selector.snap | 4 +- malva/tests/fmt/css/params/params.snap | 3 +- malva/tests/fmt/css/parens/parens.snap | 59 ++++++++-- .../tests/fmt/css/prefer-single-line/all.css | 8 ++ .../tests/fmt/css/prefer-single-line/all.snap | 7 ++ .../css/prefer-single-line/function-args.css | 8 ++ .../css/prefer-single-line/function-args.snap | 8 ++ .../fmt/css/prefer-single-line/selectors.css | 13 +++ .../fmt/css/prefer-single-line/selectors.snap | 15 +++ malva/tests/fmt/css/quotes/always-double.snap | 4 +- malva/tests/fmt/css/quotes/always-single.snap | 4 +- malva/tests/fmt/css/quotes/prefer-double.snap | 4 +- malva/tests/fmt/css/quotes/prefer-single.snap | 4 +- .../fmt/css/selector-list/selectors.snap | 3 +- malva/tests/fmt/less/less/less.snap | 84 ++++++++++---- .../fmt/less/prefer-single-line/all.less | 16 +++ .../fmt/less/prefer-single-line/all.snap | 10 ++ .../prefer-single-line/import-options.less | 16 +++ .../prefer-single-line/import-options.snap | 18 +++ .../less/prefer-single-line/mixin-args.less | 16 +++ .../less/prefer-single-line/mixin-args.snap | 18 +++ .../less/prefer-single-line/mixin-params.less | 16 +++ .../less/prefer-single-line/mixin-params.snap | 18 +++ malva/tests/fmt/scss/at-rule/mixin.snap | 7 +- malva/tests/fmt/scss/at-rule/return.snap | 5 +- .../fmt/scss/map/function-argument-2.snap | 5 +- .../fmt/scss/prefer-single-line/all.scss | 31 ++++++ .../fmt/scss/prefer-single-line/all.snap | 16 +++ .../fmt/scss/prefer-single-line/content.scss | 31 ++++++ .../fmt/scss/prefer-single-line/content.snap | 36 ++++++ .../prefer-single-line/function-args.scss | 31 ++++++ .../prefer-single-line/function-args.snap | 36 ++++++ .../fmt/scss/prefer-single-line/map.scss | 31 ++++++ .../fmt/scss/prefer-single-line/map.snap | 36 ++++++ .../prefer-single-line/module-config.scss | 31 ++++++ .../prefer-single-line/module-config.snap | 36 ++++++ .../fmt/scss/prefer-single-line/params.scss | 31 ++++++ .../fmt/scss/prefer-single-line/params.snap | 36 ++++++ malva/tests/fmt/scss/scss/scss.snap | 15 ++- malva/tests/fmt/stylefmt/readme.snap | 3 +- 51 files changed, 1103 insertions(+), 60 deletions(-) create mode 100644 malva/tests/fmt/css/prefer-single-line/all.css create mode 100644 malva/tests/fmt/css/prefer-single-line/all.snap create mode 100644 malva/tests/fmt/css/prefer-single-line/function-args.css create mode 100644 malva/tests/fmt/css/prefer-single-line/function-args.snap create mode 100644 malva/tests/fmt/css/prefer-single-line/selectors.css create mode 100644 malva/tests/fmt/css/prefer-single-line/selectors.snap create mode 100644 malva/tests/fmt/less/prefer-single-line/all.less create mode 100644 malva/tests/fmt/less/prefer-single-line/all.snap create mode 100644 malva/tests/fmt/less/prefer-single-line/import-options.less create mode 100644 malva/tests/fmt/less/prefer-single-line/import-options.snap create mode 100644 malva/tests/fmt/less/prefer-single-line/mixin-args.less create mode 100644 malva/tests/fmt/less/prefer-single-line/mixin-args.snap create mode 100644 malva/tests/fmt/less/prefer-single-line/mixin-params.less create mode 100644 malva/tests/fmt/less/prefer-single-line/mixin-params.snap create mode 100644 malva/tests/fmt/scss/prefer-single-line/all.scss create mode 100644 malva/tests/fmt/scss/prefer-single-line/all.snap create mode 100644 malva/tests/fmt/scss/prefer-single-line/content.scss create mode 100644 malva/tests/fmt/scss/prefer-single-line/content.snap create mode 100644 malva/tests/fmt/scss/prefer-single-line/function-args.scss create mode 100644 malva/tests/fmt/scss/prefer-single-line/function-args.snap create mode 100644 malva/tests/fmt/scss/prefer-single-line/map.scss create mode 100644 malva/tests/fmt/scss/prefer-single-line/map.snap create mode 100644 malva/tests/fmt/scss/prefer-single-line/module-config.scss create mode 100644 malva/tests/fmt/scss/prefer-single-line/module-config.snap create mode 100644 malva/tests/fmt/scss/prefer-single-line/params.scss create mode 100644 malva/tests/fmt/scss/prefer-single-line/params.snap diff --git a/docs/config.md b/docs/config.md index ce89e07..9f65700 100644 --- a/docs/config.md +++ b/docs/config.md @@ -646,6 +646,60 @@ Default option is `"always"`. [key=value] {} ``` +## `preferSingleLine` + +Control whether items should be placed on single line as possible, even they're originally on multiple lines. + +Default option is `false`. + +This global option can be overridden by different syntax nodes: + +- `selectors.preferSingleLine` (`blockSelectorLinebreak` must be `"consistent"`, otherwise this will be ignored) +- `functionArgs.preferSingleLine` +- `sassContentAtRule.preferSingleLine` +- `sassIncludeAtRule.preferSingleLine` +- `sassMap.preferSingleLine` +- `sassModuleConfig.preferSingleLine` +- `sassParams.preferSingleLine` +- `lessImportOptions.preferSingleLine` +- `lessMixinArgs.preferSingleLine` +- `lessMixinParams.preferSingleLine` + +Given the following example CSS: + +```css +a { + color: rgb( + 0, + 0, 0 + ); +} +``` + +### Example for `false` + +[Playground](https://malva-play.vercel.app/?code=H4sIAAAAAAAAA0tUqOZSUEjOz8kvslIoSk%2FSAPIUFAx0oJSCAZChac1VywUAA9K0WikAAAA%3D&config=H4sIAAAAAAAAA6vmUlBQKihKTUstCs7MS89J9cnMS1WyUkhLzClO5aoFAEOBhgUfAAAA&syntax=css) + +```css +a { + color: rgb( + 0, + 0, + 0 + ); +} +``` + +### Example for `true` + +[Playground](https://malva-play.vercel.app/?code=H4sIAAAAAAAAA0tUqOZSUEjOz8kvslIoSk%2FSAPIUFAx0oJSCAZChac1VywUAA9K0WikAAAA%3D&config=H4sIAAAAAAAAA6vmUlBQKihKTUstCs7MS89J9cnMS1WyUigpKk3lqgUAfjpc%2BR4AAAA%3D&syntax=css) + +```css +a { + color: rgb(0, 0, 0); +} +``` + ## `selectorOverrideCommentDirective` Text directive for overriding selector formatting. diff --git a/dprint_plugin/deployment/schema.json b/dprint_plugin/deployment/schema.json index 3de78f8..98bfcfd 100644 --- a/dprint_plugin/deployment/schema.json +++ b/dprint_plugin/deployment/schema.json @@ -206,6 +206,61 @@ ], "default": "always" }, + "preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": "boolean", + "default": false + }, + "selectors.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "functionArgs.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "sassContentAtRule.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "sassIncludeAtRule.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "sassMap.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "sassModuleConfig.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "sassParams.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "lessImportOptions.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "lessMixinArgs.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, + "lessMixinParams.preferSingleLine": { + "description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.", + "type": ["boolean", "null"], + "default": null + }, "selectorOverrideCommentDirective": { "description": "Text directive for overriding selector formatting.", "type": "string", diff --git a/dprint_plugin/src/config.rs b/dprint_plugin/src/config.rs index 604b889..c0d40ca 100644 --- a/dprint_plugin/src/config.rs +++ b/dprint_plugin/src/config.rs @@ -207,6 +207,57 @@ pub(crate) fn resolve_config( Default::default() } }, + prefer_single_line: get_value(&mut config, "preferSingleLine", false, &mut diagnostics), + selectors_prefer_single_line: get_nullable_value( + &mut config, + "selectorsPreferSingleLine", + &mut diagnostics, + ), + function_args_prefer_single_line: get_nullable_value( + &mut config, + "functionArgsPreferSingleLine", + &mut diagnostics, + ), + sass_content_at_rule_prefer_single_line: get_nullable_value( + &mut config, + "sassContentAtRulePreferSingleLine", + &mut diagnostics, + ), + sass_include_at_rule_prefer_single_line: get_nullable_value( + &mut config, + "sassIncludeAtRulePreferSingleLine", + &mut diagnostics, + ), + sass_map_prefer_single_line: get_nullable_value( + &mut config, + "sassMapPreferSingleLine", + &mut diagnostics, + ), + sass_module_config_prefer_single_line: get_nullable_value( + &mut config, + "sassModuleConfigPreferSingleLine", + &mut diagnostics, + ), + sass_params_prefer_single_line: get_nullable_value( + &mut config, + "sassParamsPreferSingleLine", + &mut diagnostics, + ), + less_import_options_prefer_single_line: get_nullable_value( + &mut config, + "lessImportOptionsPreferSingleLine", + &mut diagnostics, + ), + less_mixin_args_prefer_single_line: get_nullable_value( + &mut config, + "lessMixinArgsPreferSingleLine", + &mut diagnostics, + ), + less_mixin_params_prefer_single_line: get_nullable_value( + &mut config, + "lessMixinParamsPreferSingleLine", + &mut diagnostics, + ), selector_override_comment_directive: get_value( &mut config, "selectorOverrideCommentDirective", diff --git a/malva/src/config.rs b/malva/src/config.rs index f9c741d..3475b4f 100644 --- a/malva/src/config.rs +++ b/malva/src/config.rs @@ -135,6 +135,100 @@ pub struct LanguageOptions { /// See [`attrValueQuotes`](https://github.com/g-plane/malva/blob/main/docs/config.md#attrvaluequotes) on GitHub pub attr_value_quotes: AttrValueQuotes, + #[cfg_attr(feature = "config_serde", serde(alias = "preferSingleLine"))] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub prefer_single_line: bool, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "selectors.prefer_single_line", + alias = "selectors.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub selectors_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "function_args.prefer_single_line", + alias = "functionArgs.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub function_args_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "sass_content_at_rule.prefer_single_line", + alias = "sassContentAtRule.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub sass_content_at_rule_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "sass_include_at_rule.prefer_single_line", + alias = "sassIncludeAtRule.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub sass_include_at_rule_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "sass_map.prefer_single_line", + alias = "sassMap.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub sass_map_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "sass_module_config.prefer_single_line", + alias = "sassModuleConfig.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub sass_module_config_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "sass_params.prefer_single_line", + alias = "sassParams.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub sass_params_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "less_import_options.prefer_single_line", + alias = "lessImportOptions.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub less_import_options_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "less_mixin_args.prefer_single_line", + alias = "lessMixinArgs.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub less_mixin_args_prefer_single_line: Option, + #[cfg_attr( + feature = "config_serde", + serde( + rename = "less_mixin_params.prefer_single_line", + alias = "lessMixinParams.preferSingleLine" + ) + )] + /// See [`preferSingleLine`](https://github.com/g-plane/malva/blob/main/docs/config.md#prefersingleline) on GitHub + pub less_mixin_params_prefer_single_line: Option, + #[cfg_attr( feature = "config_serde", serde(alias = "selectorOverrideCommentDirective") @@ -163,6 +257,17 @@ impl Default for LanguageOptions { single_line_block_threshold: None, keyframe_selector_notation: None, attr_value_quotes: AttrValueQuotes::default(), + prefer_single_line: false, + selectors_prefer_single_line: None, + function_args_prefer_single_line: None, + sass_content_at_rule_prefer_single_line: None, + sass_include_at_rule_prefer_single_line: None, + sass_map_prefer_single_line: None, + sass_module_config_prefer_single_line: None, + sass_params_prefer_single_line: None, + less_import_options_prefer_single_line: None, + less_mixin_args_prefer_single_line: None, + less_mixin_params_prefer_single_line: None, selector_override_comment_directive: "malva-selector-override".into(), ignore_comment_directive: "malva-ignore".into(), } diff --git a/malva/src/doc_gen/at_rule/custom_selector.rs b/malva/src/doc_gen/at_rule/custom_selector.rs index 3720646..68db4ca 100644 --- a/malva/src/doc_gen/at_rule/custom_selector.rs +++ b/malva/src/doc_gen/at_rule/custom_selector.rs @@ -33,7 +33,12 @@ impl<'s> DocGen<'s> for CustomSelectorArgs<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, &self.args, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.args, + ctx.options.selectors_prefer_single_line, + ctx, + ), ) .format(&self.args, &self.comma_spans, self.span.start, ctx, state), self.args diff --git a/malva/src/doc_gen/helpers.rs b/malva/src/doc_gen/helpers.rs index 818f789..01fe335 100644 --- a/malva/src/doc_gen/helpers.rs +++ b/malva/src/doc_gen/helpers.rs @@ -44,7 +44,25 @@ where ",", match linebreak { BlockSelectorLineBreak::Always => Doc::hard_line(), - BlockSelectorLineBreak::Consistent => Doc::line_or_space(), + BlockSelectorLineBreak::Consistent => { + if ctx + .options + .selectors_prefer_single_line + .unwrap_or(ctx.options.prefer_single_line) + || selectors + .first() + .zip(selectors.get(1)) + .is_some_and(|(first, second)| { + ctx.line_bounds + .line_distance(first.span().end, second.span().start) + == 0 + }) + { + Doc::line_or_space() + } else { + Doc::hard_line() + } + } BlockSelectorLineBreak::Wrap => Doc::soft_line(), }, ) @@ -335,13 +353,18 @@ pub(super) fn ident_to_lowercase<'s>( pub(super) fn get_smart_linebreak( start: usize, elements: &[N], + prefer_single_line: Option, ctx: &Ctx<'_, '_>, ) -> Doc<'static> where N: Spanned, { + let prefer_single_line = prefer_single_line.unwrap_or(ctx.options.prefer_single_line); match elements.first() { - Some(element) if ctx.line_bounds.line_distance(start, element.span().start) > 0 => { + Some(element) + if !prefer_single_line + && ctx.line_bounds.line_distance(start, element.span().start) > 0 => + { Doc::hard_line() } _ => Doc::line_or_space(), diff --git a/malva/src/doc_gen/less.rs b/malva/src/doc_gen/less.rs index 2149ce0..3935b94 100644 --- a/malva/src/doc_gen/less.rs +++ b/malva/src/doc_gen/less.rs @@ -206,7 +206,12 @@ impl<'s> DocGen<'s> for LessImportOptions<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, &self.names, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.names, + ctx.options.less_import_options_prefer_single_line, + ctx, + ), ) .with_trailing() .format(&self.names, &self.comma_spans, self.span.start, ctx, state), @@ -425,7 +430,12 @@ impl<'s> DocGen<'s> for LessMixinArguments<'s> { .append( helpers::SeparatedListFormatter::new( if self.is_comma_separated { "," } else { ";" }, - helpers::get_smart_linebreak(self.span.start, &self.args, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.args, + ctx.options.less_mixin_args_prefer_single_line, + ctx, + ), ) .with_trailing() .format( @@ -617,7 +627,12 @@ impl<'s> DocGen<'s> for LessMixinParameters<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( if self.is_comma_separated { "," } else { ";" }, - helpers::get_smart_linebreak(self.span.start, &self.params, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.params, + ctx.options.less_mixin_params_prefer_single_line, + ctx, + ), ) .with_trailing() .format( diff --git a/malva/src/doc_gen/sass.rs b/malva/src/doc_gen/sass.rs index ce1a645..0761ca8 100644 --- a/malva/src/doc_gen/sass.rs +++ b/malva/src/doc_gen/sass.rs @@ -150,7 +150,12 @@ impl<'s> DocGen<'s> for SassContent<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, &self.args, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.args, + ctx.options.sass_content_at_rule_prefer_single_line, + ctx, + ), ) .with_trailing() .format(&self.args, &self.comma_spans, self.span.start, ctx, state), @@ -462,7 +467,12 @@ impl<'s> DocGen<'s> for SassIncludeArgs<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, &self.args, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.args, + ctx.options.sass_include_at_rule_prefer_single_line, + ctx, + ), ) .with_trailing() .format(&self.args, &self.comma_spans, self.span.start, ctx, state), @@ -656,7 +666,12 @@ impl<'s> DocGen<'s> for SassMap<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, &self.items, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.items, + ctx.options.sass_map_prefer_single_line, + ctx, + ), ) .with_trailing() .format(&self.items, &self.comma_spans, self.span.start, ctx, state), @@ -705,7 +720,12 @@ impl<'s> DocGen<'s> for SassModuleConfig<'s> { .append(helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, &self.items, ctx), + helpers::get_smart_linebreak( + self.span.start, + &self.items, + ctx.options.sass_module_config_prefer_single_line, + ctx, + ), ) .with_trailing() .format( @@ -833,7 +853,12 @@ impl<'s> DocGen<'s> for SassParameters<'s> { helpers::format_parenthesized( helpers::SeparatedListFormatter::new( ",", - helpers::get_smart_linebreak(self.span.start, ¶ms, ctx), + helpers::get_smart_linebreak( + self.span.start, + ¶ms, + ctx.options.sass_params_prefer_single_line, + ctx, + ), ) .with_trailing() .format(¶ms, &self.comma_spans, self.span.start, ctx, state), diff --git a/malva/src/doc_gen/selector.rs b/malva/src/doc_gen/selector.rs index 47e0857..5aa47d9 100644 --- a/malva/src/doc_gen/selector.rs +++ b/malva/src/doc_gen/selector.rs @@ -561,7 +561,24 @@ impl<'s> DocGen<'s> for SimpleSelector<'s> { impl<'s> DocGen<'s> for SelectorList<'s> { fn doc(&self, ctx: &Ctx<'_, 's>, state: &State) -> Doc<'s> { - helpers::SeparatedListFormatter::new(",", Doc::line_or_space()).format( + let space_after_separator = if ctx + .options + .selectors_prefer_single_line + .unwrap_or(ctx.options.prefer_single_line) + || self + .selectors + .first() + .zip(self.selectors.get(1)) + .is_some_and(|(first, second)| { + ctx.line_bounds + .line_distance(first.span.end, second.span.start) + == 0 + }) { + Doc::line_or_space() + } else { + Doc::hard_line() + }; + helpers::SeparatedListFormatter::new(",", space_after_separator).format( &self.selectors, &self.comma_spans, self.span.start, diff --git a/malva/src/doc_gen/value.rs b/malva/src/doc_gen/value.rs index f9530c5..59f07e2 100644 --- a/malva/src/doc_gen/value.rs +++ b/malva/src/doc_gen/value.rs @@ -342,7 +342,12 @@ impl<'s> DocGen<'s> for Function<'s> { format_group(group, &mut pos, separator.clone(), ctx, state) } }), - Doc::line_or_space(), + helpers::get_smart_linebreak( + self.span.start, + &self.args, + ctx.options.function_args_prefer_single_line, + ctx, + ), )); let mut has_last_line_comment = false; diff --git a/malva/tests/fmt/css/at-rule/keyframes.snap b/malva/tests/fmt/css/at-rule/keyframes.snap index 7407075..e2694c1 100644 --- a/malva/tests/fmt/css/at-rule/keyframes.snap +++ b/malva/tests/fmt/css/at-rule/keyframes.snap @@ -9,7 +9,8 @@ source: malva/tests/fmt.rs 30% { top: 50px; } - 68%, 72% { + 68%, + 72% { left: 50px; } 100% { @@ -73,7 +74,8 @@ source: malva/tests/fmt.rs 30% { top: 50px; } - 68%, 72% { + 68%, + 72% { left: 50px; } 100% { @@ -93,7 +95,8 @@ source: malva/tests/fmt.rs top: 50px; } - 68%, 72% { + 68%, + 72% { left: 50px; } diff --git a/malva/tests/fmt/css/attribute/custom-selector.snap b/malva/tests/fmt/css/attribute/custom-selector.snap index 30310e9..20adbd8 100644 --- a/malva/tests/fmt/css/attribute/custom-selector.snap +++ b/malva/tests/fmt/css/attribute/custom-selector.snap @@ -3,4 +3,6 @@ source: malva/tests/fmt.rs --- @custom-selector :--icon i[class^="icon-"], i[class*=" icon-"]; @custom-selector :--icon i[class^="icon-"], i[class*=" icon-"]; -@custom-selector :--icon i[class^="icon-"], i[class*=" icon-"]; +@custom-selector :--icon + i[class^="icon-"], +i[class*=" icon-"]; diff --git a/malva/tests/fmt/css/params/params.snap b/malva/tests/fmt/css/params/params.snap index 83c90c6..7d5e00f 100644 --- a/malva/tests/fmt/css/params/params.snap +++ b/malva/tests/fmt/css/params/params.snap @@ -1,6 +1,7 @@ --- source: malva/tests/fmt.rs --- -.clusterPlannerDialog input[type="text"], .clusterPlannerDialog .uiTypeahead { +.clusterPlannerDialog input[type="text"], +.clusterPlannerDialog .uiTypeahead { width: 220px; } diff --git a/malva/tests/fmt/css/parens/parens.snap b/malva/tests/fmt/css/parens/parens.snap index ec1b62e..c87b049 100644 --- a/malva/tests/fmt/css/parens/parens.snap +++ b/malva/tests/fmt/css/parens/parens.snap @@ -7,8 +7,36 @@ a { prop3: func(1px, 1px, 1px, func(1px, 1px, 1px, func(1px, 1px, 1px))); prop4: func(1px, 1px, 1px, func(1px, 1px, 1px, func(1px, 1px, 1px))); prop5: func(1px, 1px, 1px, func(1px, 1px, 1px, func(1px, 1px, 1px))); - prop6: func(1px, 1px, 1px, func(1px, 1px, 1px, func(1px, 1px, 1px))); - prop7: func(1px, 1px, 1px, func(1px, 1px, 1px, func(1px, 1px, 1px))); + prop6: func( + 1px, + 1px, + 1px, + func( + 1px, + 1px, + 1px, + func( + 1px, + 1px, + 1px + ) + ) + ); + prop7: func( + 1px, + 1px, + 1px, + func( + 1px, + 1px, + 1px, + func( + 1px, + 1px, + 1px + ) + ) + ); prop8: very-very-very-very-very-very-vey-very-very-long-func( 1px, 1px, @@ -39,7 +67,11 @@ a { 1px, 1px, 1px, - very-very-very-very-very-very-vey-very-very-long-func(1px, 1px, 1px) + very-very-very-very-very-very-vey-very-very-long-func( + 1px, + 1px, + 1px + ) ) ); prop11: very-very-very-very-very-very-vey-very-very-long-func( @@ -50,7 +82,11 @@ a { 1px, 1px, 1px, - very-very-very-very-very-very-vey-very-very-long-func(1px, 1px, 1px) + very-very-very-very-very-very-vey-very-very-long-func( + 1px, + 1px, + 1px + ) ) ); } @@ -80,9 +116,18 @@ a { prop20: attr(data-size em, 20); prop21: attr(data-size em, 20); prop22: attr(data-size em, 20); - prop23: attr(data-size em, 20); - prop24: attr(data-size em, 20); - prop25: attr(data-size em, 20); + prop23: attr( + data-size em, + 20 + ); + prop24: attr( + data-size em, + 20 + ); + prop25: attr( + data-size em, + 20 + ); } .bar { diff --git a/malva/tests/fmt/css/prefer-single-line/all.css b/malva/tests/fmt/css/prefer-single-line/all.css new file mode 100644 index 0000000..1685628 --- /dev/null +++ b/malva/tests/fmt/css/prefer-single-line/all.css @@ -0,0 +1,8 @@ +/*cfg preferSingleLine = true*/ +a, +b { + color: rgb( + 0, + 0, 0 + ); +} diff --git a/malva/tests/fmt/css/prefer-single-line/all.snap b/malva/tests/fmt/css/prefer-single-line/all.snap new file mode 100644 index 0000000..334054d --- /dev/null +++ b/malva/tests/fmt/css/prefer-single-line/all.snap @@ -0,0 +1,7 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg preferSingleLine = true*/ +a, b { + color: rgb(0, 0, 0); +} diff --git a/malva/tests/fmt/css/prefer-single-line/function-args.css b/malva/tests/fmt/css/prefer-single-line/function-args.css new file mode 100644 index 0000000..4ab9d42 --- /dev/null +++ b/malva/tests/fmt/css/prefer-single-line/function-args.css @@ -0,0 +1,8 @@ +/*cfg "functionArgs.preferSingleLine" = true*/ +a, +b { + color: rgb( + 0, + 0, 0 + ); +} diff --git a/malva/tests/fmt/css/prefer-single-line/function-args.snap b/malva/tests/fmt/css/prefer-single-line/function-args.snap new file mode 100644 index 0000000..7d800e9 --- /dev/null +++ b/malva/tests/fmt/css/prefer-single-line/function-args.snap @@ -0,0 +1,8 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "functionArgs.preferSingleLine" = true*/ +a, +b { + color: rgb(0, 0, 0); +} diff --git a/malva/tests/fmt/css/prefer-single-line/selectors.css b/malva/tests/fmt/css/prefer-single-line/selectors.css new file mode 100644 index 0000000..961de1c --- /dev/null +++ b/malva/tests/fmt/css/prefer-single-line/selectors.css @@ -0,0 +1,13 @@ +/*cfg "selectors.preferSingleLine" = true*/ +a, +b { + color: rgb( + 0, + 0, 0 + ); +} + +@keyframes kf { + from, + to {} +} diff --git a/malva/tests/fmt/css/prefer-single-line/selectors.snap b/malva/tests/fmt/css/prefer-single-line/selectors.snap new file mode 100644 index 0000000..07d666d --- /dev/null +++ b/malva/tests/fmt/css/prefer-single-line/selectors.snap @@ -0,0 +1,15 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "selectors.preferSingleLine" = true*/ +a, b { + color: rgb( + 0, + 0, + 0 + ); +} + +@keyframes kf { + from, to {} +} diff --git a/malva/tests/fmt/css/quotes/always-double.snap b/malva/tests/fmt/css/quotes/always-double.snap index 36579d8..9a686d6 100644 --- a/malva/tests/fmt/css/quotes/always-double.snap +++ b/malva/tests/fmt/css/quotes/always-double.snap @@ -7,7 +7,9 @@ source: malva/tests/fmt.rs @charset 'UTF-8'; /* Single quotes are invalid here. Keep them since we don't know what the user is doing. */ @supports (content: one "two" three "four") { - a[href="foo" y], abbr[title^="It\'s a trap!"], img[src=""] { + a[href="foo" y], + abbr[title^="It\'s a trap!"], + img[src=""] { /* Simple strings. */ content: "abc"; content: "abc"; diff --git a/malva/tests/fmt/css/quotes/always-single.snap b/malva/tests/fmt/css/quotes/always-single.snap index 534afed..2b70249 100644 --- a/malva/tests/fmt/css/quotes/always-single.snap +++ b/malva/tests/fmt/css/quotes/always-single.snap @@ -8,7 +8,9 @@ source: malva/tests/fmt.rs @charset 'UTF-8'; /* Single quotes are invalid here. Keep them since we don't know what the user is doing. */ @supports (content: one 'two' three 'four') { - a[href='foo' y], abbr[title^='It\'s a trap!'], img[src=''] { + a[href='foo' y], + abbr[title^='It\'s a trap!'], + img[src=''] { /* Simple strings. */ content: 'abc'; content: 'abc'; diff --git a/malva/tests/fmt/css/quotes/prefer-double.snap b/malva/tests/fmt/css/quotes/prefer-double.snap index 3235c40..6680530 100644 --- a/malva/tests/fmt/css/quotes/prefer-double.snap +++ b/malva/tests/fmt/css/quotes/prefer-double.snap @@ -8,7 +8,9 @@ source: malva/tests/fmt.rs @charset 'UTF-8'; /* Single quotes are invalid here. Keep them since we don't know what the user is doing. */ @supports (content: one "two" three "four") { - a[href="foo" y], abbr[title^="It\'s a trap!"], img[src=""] { + a[href="foo" y], + abbr[title^="It\'s a trap!"], + img[src=""] { /* Simple strings. */ content: "abc"; content: "abc"; diff --git a/malva/tests/fmt/css/quotes/prefer-single.snap b/malva/tests/fmt/css/quotes/prefer-single.snap index e5b0042..d6c83e3 100644 --- a/malva/tests/fmt/css/quotes/prefer-single.snap +++ b/malva/tests/fmt/css/quotes/prefer-single.snap @@ -8,7 +8,9 @@ source: malva/tests/fmt.rs @charset 'UTF-8'; /* Single quotes are invalid here. Keep them since we don't know what the user is doing. */ @supports (content: one 'two' three 'four') { - a[href='foo' y], abbr[title^='It\'s a trap!'], img[src=''] { + a[href='foo' y], + abbr[title^='It\'s a trap!'], + img[src=''] { /* Simple strings. */ content: 'abc'; content: 'abc'; diff --git a/malva/tests/fmt/css/selector-list/selectors.snap b/malva/tests/fmt/css/selector-list/selectors.snap index bbfcf43..c4a3b62 100644 --- a/malva/tests/fmt/css/selector-list/selectors.snap +++ b/malva/tests/fmt/css/selector-list/selectors.snap @@ -32,7 +32,8 @@ source: malva/tests/fmt.rs .parent, .another-parent {} .parent, .another-parent {} .parent, .another-parent {} -.parent, .another-parent {} +.parent, +.another-parent {} .parent.child {} .parent .child {} diff --git a/malva/tests/fmt/less/less/less.snap b/malva/tests/fmt/less/less/less.snap index a247de4..123d19a 100644 --- a/malva/tests/fmt/less/less/less.snap +++ b/malva/tests/fmt/less/less/less.snap @@ -186,7 +186,8 @@ style comment! */ @import "library"; // library.less @import "typo.css"; -a, .link { +a, +.link { color: #428bca; } .widget { @@ -199,7 +200,8 @@ a, .link { @link-color-hover: darken(@link-color, 10%); // Usage -a, .link { +a, +.link { color: @link-color; } a:hover { @@ -320,7 +322,8 @@ nav ul { nav ul { background: blue; } -.inline, nav ul { +.inline, +nav ul { color: red; } @@ -344,15 +347,19 @@ nav ul { // the above an the below do the same thing .e:extend(.f, .g) {} -.big-division, .big-bag:extend(.bag), .big-bucket:extend(.bucket) { +.big-division, +.big-bag:extend(.bag), +.big-bucket:extend(.bucket) { // body } -pre:hover, .some-class { +pre:hover, +.some-class { &:extend(div pre); } -pre:hover:extend(div pre), .some-class:extend(div pre) {} +pre:hover:extend(div pre), +.some-class:extend(div pre) {} .bucket { tr { @@ -362,7 +369,8 @@ pre:hover:extend(div pre), .some-class:extend(div pre) {} } .some-class:extend(.bucket tr) {} // nested ruleset is recognized -.bucket tr, .some-class { +.bucket tr, +.some-class { color: blue; } @@ -374,11 +382,14 @@ pre:hover:extend(div pre), .some-class:extend(div pre) {} } .some-class:extend(tr .bucket) {} // nested ruleset is recognized -tr .bucket, .some-class { +tr .bucket, +.some-class { color: blue; } -.a.class, .class.a, .class > .a { +.a.class, +.class.a, +.class > .a { color: blue; } .test:extend(.class) {} // this will NOT match the any selectors above @@ -424,19 +435,29 @@ link:hover:visited { .singleQuote:extend([title="identifier"]) {} .doubleQuote:extend([title="identifier"]) {} -[title="identifier"], .noQuote, .singleQuote, .doubleQuote { +[title="identifier"], +.noQuote, +.singleQuote, +.doubleQuote { color: blue; } -[title="identifier"], .noQuote, .singleQuote, .doubleQuote { +[title="identifier"], +.noQuote, +.singleQuote, +.doubleQuote { color: blue; } -[title="identifier"], .noQuote, .singleQuote, .doubleQuote { +[title="identifier"], +.noQuote, +.singleQuote, +.doubleQuote { color: blue; } -.a.b.test, .test.c { +.a.b.test, +.test.c { color: orange; } .test { @@ -447,10 +468,14 @@ link:hover:visited { .replacement:extend(.test all) {} -.a.b.test, .test.c, .a.b.replacement, .replacement.c { +.a.b.test, +.test.c, +.a.b.replacement, +.replacement.c { color: orange; } -.test:hover, .replacement:hover { +.test:hover, +.replacement:hover { color: green; } @@ -500,7 +525,8 @@ link:hover:visited { } @media print { - .selector, .screenClass { + .selector, + .screenClass { /* ruleset inside the same media was extended */ color: black; } @@ -549,25 +575,31 @@ link:hover:visited { .topLevel:extend(.selector) {} /* top level extend matches everything */ @media screen { - .selector, .topLevel { + .selector, + .topLevel { /* ruleset inside media was extended */ color: blue; } } @media screen and (min-width: 1023px) { - .selector, .topLevel { + .selector, + .topLevel { /* ruleset inside nested media was extended */ color: blue; } } -.alert-info, .widget { +.alert-info, +.widget { /* declarations */ } .alert:extend(.alert-info, .widget) {} -.alert-info, .widget, .alert, .alert { +.alert-info, +.widget, +.alert, +.alert { /* declarations */ } @@ -624,7 +656,9 @@ link:hover:visited { &:extend(.my-inline-block); } -.my-inline-block, .thing1, .thing2 { +.my-inline-block, +.thing1, +.thing2 { display: inline-block; font-size: 0; } @@ -1438,7 +1472,8 @@ a:hover { .grand .parent.grand .parent { color: blue; } -.grand .parent, .grand .parentish { +.grand .parent, +.grand .parentish { color: cyan; } @@ -1465,7 +1500,10 @@ p, a, ul, li { } } -p, a, ul, li { +p, +a, +ul, +li { border-top: 2px dotted #366; } p + p, diff --git a/malva/tests/fmt/less/prefer-single-line/all.less b/malva/tests/fmt/less/prefer-single-line/all.less new file mode 100644 index 0000000..2cd6609 --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/all.less @@ -0,0 +1,16 @@ +/*cfg preferSingleLine = true*/ + +@import ( + inline, + css, multiple +) url("import/invalid-css.less"); + +.mixin( + @a, + @b, @c +) {} + +.mixin( + @a, + @b, @c +); diff --git a/malva/tests/fmt/less/prefer-single-line/all.snap b/malva/tests/fmt/less/prefer-single-line/all.snap new file mode 100644 index 0000000..00ecb6b --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/all.snap @@ -0,0 +1,10 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg preferSingleLine = true*/ + +@import (inline, css, multiple) url("import/invalid-css.less"); + +.mixin(@a, @b, @c) {} + +.mixin(@a, @b, @c); diff --git a/malva/tests/fmt/less/prefer-single-line/import-options.less b/malva/tests/fmt/less/prefer-single-line/import-options.less new file mode 100644 index 0000000..657ca25 --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/import-options.less @@ -0,0 +1,16 @@ +/*cfg "lessImportOptions.preferSingleLine" = true*/ + +@import ( + inline, + css, multiple +) url("import/invalid-css.less"); + +.mixin( + @a, + @b, @c +) {} + +.mixin( + @a, + @b, @c +); diff --git a/malva/tests/fmt/less/prefer-single-line/import-options.snap b/malva/tests/fmt/less/prefer-single-line/import-options.snap new file mode 100644 index 0000000..41680fa --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/import-options.snap @@ -0,0 +1,18 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "lessImportOptions.preferSingleLine" = true*/ + +@import (inline, css, multiple) url("import/invalid-css.less"); + +.mixin( + @a, + @b, + @c +) {} + +.mixin( + @a, + @b, + @c +); diff --git a/malva/tests/fmt/less/prefer-single-line/mixin-args.less b/malva/tests/fmt/less/prefer-single-line/mixin-args.less new file mode 100644 index 0000000..a70e90d --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/mixin-args.less @@ -0,0 +1,16 @@ +/*cfg "lessMixinArgs.preferSingleLine" = true*/ + +@import ( + inline, + css, multiple +) url("import/invalid-css.less"); + +.mixin( + @a, + @b, @c +) {} + +.mixin( + @a, + @b, @c +); diff --git a/malva/tests/fmt/less/prefer-single-line/mixin-args.snap b/malva/tests/fmt/less/prefer-single-line/mixin-args.snap new file mode 100644 index 0000000..b1f3b27 --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/mixin-args.snap @@ -0,0 +1,18 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "lessMixinArgs.preferSingleLine" = true*/ + +@import ( + inline, + css, + multiple +) url("import/invalid-css.less"); + +.mixin( + @a, + @b, + @c +) {} + +.mixin(@a, @b, @c); diff --git a/malva/tests/fmt/less/prefer-single-line/mixin-params.less b/malva/tests/fmt/less/prefer-single-line/mixin-params.less new file mode 100644 index 0000000..0aa2568 --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/mixin-params.less @@ -0,0 +1,16 @@ +/*cfg "lessMixinParams.preferSingleLine" = true*/ + +@import ( + inline, + css, multiple +) url("import/invalid-css.less"); + +.mixin( + @a, + @b, @c +) {} + +.mixin( + @a, + @b, @c +); diff --git a/malva/tests/fmt/less/prefer-single-line/mixin-params.snap b/malva/tests/fmt/less/prefer-single-line/mixin-params.snap new file mode 100644 index 0000000..6b98651 --- /dev/null +++ b/malva/tests/fmt/less/prefer-single-line/mixin-params.snap @@ -0,0 +1,18 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "lessMixinParams.preferSingleLine" = true*/ + +@import ( + inline, + css, + multiple +) url("import/invalid-css.less"); + +.mixin(@a, @b, @c) {} + +.mixin( + @a, + @b, + @c +); diff --git a/malva/tests/fmt/scss/at-rule/mixin.snap b/malva/tests/fmt/scss/at-rule/mixin.snap index 8e0c33b..f148ffa 100644 --- a/malva/tests/fmt/scss/at-rule/mixin.snap +++ b/malva/tests/fmt/scss/at-rule/mixin.snap @@ -49,7 +49,12 @@ source: malva/tests/fmt.rs @mixin button-variant($hover-background: darken($background, 7.5%)) {} @mixin button-variant($hover-background: darken($background, 7.5%)) {} @mixin button-variant($hover-background: darken($background, 7.5%)) {} -@mixin button-variant($hover-background: darken($background, 7.5%)) {} +@mixin button-variant( + $hover-background: darken( + $background, + 7.5% + ) +) {} @mixin button-variant($foo: "...") {} @mixin button-variant($foo: " ... ") {} @mixin button-variant($foo: " ... ") {} diff --git a/malva/tests/fmt/scss/at-rule/return.snap b/malva/tests/fmt/scss/at-rule/return.snap index dc23dfe..869ccaa 100644 --- a/malva/tests/fmt/scss/at-rule/return.snap +++ b/malva/tests/fmt/scss/at-rule/return.snap @@ -44,5 +44,8 @@ source: malva/tests/fmt.rs @return map-merge($obj, $ext-obj); } @function extend($obj, $ext-obj) { - @return map-merge($obj, $ext-obj); + @return map-merge( + $obj, + $ext-obj + ); } diff --git a/malva/tests/fmt/scss/map/function-argument-2.snap b/malva/tests/fmt/scss/map/function-argument-2.snap index 43f4269..2e51f01 100644 --- a/malva/tests/fmt/scss/map/function-argument-2.snap +++ b/malva/tests/fmt/scss/map/function-argument-2.snap @@ -19,5 +19,8 @@ $display-breakpoints: map-deep-merge( ); @each $name, $hue in $hues { - $map: map.merge($map, ("#{$prefix}-#{$name}": blend.set($base, $hue: $hue))); + $map: map.merge( + $map, + ("#{$prefix}-#{$name}": blend.set($base, $hue: $hue)) + ); } diff --git a/malva/tests/fmt/scss/prefer-single-line/all.scss b/malva/tests/fmt/scss/prefer-single-line/all.scss new file mode 100644 index 0000000..2a2780b --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/all.scss @@ -0,0 +1,31 @@ +/*cfg preferSingleLine = true*/ + +@use 'library' with ( + $var1: 1, + $var2: 2, $var3: 3 +); + +$var: namespace.fn( + 1, + 2, 3 +); + +@include mixin ( + 1, + 2, 3 +) { + @content( + 1, + 2, 3 + ); +} + +$map: ( + k1: v1, + k2: v2, k3: v3 +); + +@function fn( + $arg1, + $arg2, $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/all.snap b/malva/tests/fmt/scss/prefer-single-line/all.snap new file mode 100644 index 0000000..ac5020a --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/all.snap @@ -0,0 +1,16 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg preferSingleLine = true*/ + +@use "library" with ($var1: 1, $var2: 2, $var3: 3); + +$var: namespace.fn(1, 2, 3); + +@include mixin(1, 2, 3) { + @content (1, 2, 3); +} + +$map: (k1: v1, k2: v2, k3: v3); + +@function fn($arg1, $arg2, $arg3) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/content.scss b/malva/tests/fmt/scss/prefer-single-line/content.scss new file mode 100644 index 0000000..e85f458 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/content.scss @@ -0,0 +1,31 @@ +/*cfg "sassContentAtRule.preferSingleLine" = true*/ + +@use 'library' with ( + $var1: 1, + $var2: 2, $var3: 3 +); + +$var: namespace.fn( + 1, + 2, 3 +); + +@include mixin ( + 1, + 2, 3 +) { + @content( + 1, + 2, 3 + ); +} + +$map: ( + k1: v1, + k2: v2, k3: v3 +); + +@function fn( + $arg1, + $arg2, $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/content.snap b/malva/tests/fmt/scss/prefer-single-line/content.snap new file mode 100644 index 0000000..85d8c2d --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/content.snap @@ -0,0 +1,36 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "sassContentAtRule.preferSingleLine" = true*/ + +@use "library" with ( + $var1: 1, + $var2: 2, + $var3: 3 +); + +$var: namespace.fn( + 1, + 2, + 3 +); + +@include mixin( + 1, + 2, + 3 +) { + @content (1, 2, 3); +} + +$map: ( + k1: v1, + k2: v2, + k3: v3 +); + +@function fn( + $arg1, + $arg2, + $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/function-args.scss b/malva/tests/fmt/scss/prefer-single-line/function-args.scss new file mode 100644 index 0000000..2a77b46 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/function-args.scss @@ -0,0 +1,31 @@ +/*cfg "functionArgs.preferSingleLine" = true*/ + +@use 'library' with ( + $var1: 1, + $var2: 2, $var3: 3 +); + +$var: namespace.fn( + 1, + 2, 3 +); + +@include mixin ( + 1, + 2, 3 +) { + @content( + 1, + 2, 3 + ); +} + +$map: ( + k1: v1, + k2: v2, k3: v3 +); + +@function fn( + $arg1, + $arg2, $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/function-args.snap b/malva/tests/fmt/scss/prefer-single-line/function-args.snap new file mode 100644 index 0000000..637ebc3 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/function-args.snap @@ -0,0 +1,36 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "functionArgs.preferSingleLine" = true*/ + +@use "library" with ( + $var1: 1, + $var2: 2, + $var3: 3 +); + +$var: namespace.fn(1, 2, 3); + +@include mixin( + 1, + 2, + 3 +) { + @content ( + 1, + 2, + 3 + ); +} + +$map: ( + k1: v1, + k2: v2, + k3: v3 +); + +@function fn( + $arg1, + $arg2, + $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/map.scss b/malva/tests/fmt/scss/prefer-single-line/map.scss new file mode 100644 index 0000000..a00c751 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/map.scss @@ -0,0 +1,31 @@ +/*cfg "sassMap.preferSingleLine" = true*/ + +@use 'library' with ( + $var1: 1, + $var2: 2, $var3: 3 +); + +$var: namespace.fn( + 1, + 2, 3 +); + +@include mixin ( + 1, + 2, 3 +) { + @content( + 1, + 2, 3 + ); +} + +$map: ( + k1: v1, + k2: v2, k3: v3 +); + +@function fn( + $arg1, + $arg2, $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/map.snap b/malva/tests/fmt/scss/prefer-single-line/map.snap new file mode 100644 index 0000000..0a779df --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/map.snap @@ -0,0 +1,36 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "sassMap.preferSingleLine" = true*/ + +@use "library" with ( + $var1: 1, + $var2: 2, + $var3: 3 +); + +$var: namespace.fn( + 1, + 2, + 3 +); + +@include mixin( + 1, + 2, + 3 +) { + @content ( + 1, + 2, + 3 + ); +} + +$map: (k1: v1, k2: v2, k3: v3); + +@function fn( + $arg1, + $arg2, + $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/module-config.scss b/malva/tests/fmt/scss/prefer-single-line/module-config.scss new file mode 100644 index 0000000..68b6307 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/module-config.scss @@ -0,0 +1,31 @@ +/*cfg "sassModuleConfig.preferSingleLine" = true*/ + +@use 'library' with ( + $var1: 1, + $var2: 2, $var3: 3 +); + +$var: namespace.fn( + 1, + 2, 3 +); + +@include mixin ( + 1, + 2, 3 +) { + @content( + 1, + 2, 3 + ); +} + +$map: ( + k1: v1, + k2: v2, k3: v3 +); + +@function fn( + $arg1, + $arg2, $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/module-config.snap b/malva/tests/fmt/scss/prefer-single-line/module-config.snap new file mode 100644 index 0000000..f78350a --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/module-config.snap @@ -0,0 +1,36 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "sassModuleConfig.preferSingleLine" = true*/ + +@use "library" with ($var1: 1, $var2: 2, $var3: 3); + +$var: namespace.fn( + 1, + 2, + 3 +); + +@include mixin( + 1, + 2, + 3 +) { + @content ( + 1, + 2, + 3 + ); +} + +$map: ( + k1: v1, + k2: v2, + k3: v3 +); + +@function fn( + $arg1, + $arg2, + $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/params.scss b/malva/tests/fmt/scss/prefer-single-line/params.scss new file mode 100644 index 0000000..e32f1d7 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/params.scss @@ -0,0 +1,31 @@ +/*cfg "sassParams.preferSingleLine" = true*/ + +@use 'library' with ( + $var1: 1, + $var2: 2, $var3: 3 +); + +$var: namespace.fn( + 1, + 2, 3 +); + +@include mixin ( + 1, + 2, 3 +) { + @content( + 1, + 2, 3 + ); +} + +$map: ( + k1: v1, + k2: v2, k3: v3 +); + +@function fn( + $arg1, + $arg2, $arg3 +) {} diff --git a/malva/tests/fmt/scss/prefer-single-line/params.snap b/malva/tests/fmt/scss/prefer-single-line/params.snap new file mode 100644 index 0000000..3c4d422 --- /dev/null +++ b/malva/tests/fmt/scss/prefer-single-line/params.snap @@ -0,0 +1,36 @@ +--- +source: malva/tests/fmt.rs +--- +/*cfg "sassParams.preferSingleLine" = true*/ + +@use "library" with ( + $var1: 1, + $var2: 2, + $var3: 3 +); + +$var: namespace.fn( + 1, + 2, + 3 +); + +@include mixin( + 1, + 2, + 3 +) { + @content ( + 1, + 2, + 3 + ); +} + +$map: ( + k1: v1, + k2: v2, + k3: v3 +); + +@function fn($arg1, $arg2, $arg3) {} diff --git a/malva/tests/fmt/scss/scss/scss.snap b/malva/tests/fmt/scss/scss/scss.snap index 7ef743a..cd00dbc 100644 --- a/malva/tests/fmt/scss/scss/scss.snap +++ b/malva/tests/fmt/scss/scss/scss.snap @@ -115,9 +115,18 @@ $map: ( $map: map-merge($map, ($key: $value)); $map: map-merge($map, ($key: $value)); $map: map-merge($map, ($key: $value)); -$map: map-merge($map, ($key: $value)); -$map: map-merge($map, ($key: $value)); -$map: map-merge($map, ($key: $value)); +$map: map-merge( + $map, + ($key: $value) +); +$map: map-merge( + $map, + ($key: $value) +); +$map: map-merge( + $map, + ($key: $value) +); $longVariable: ( (mobile $mobile) (tablet $tablet) (desktop $desktop) (wide $wide) diff --git a/malva/tests/fmt/stylefmt/readme.snap b/malva/tests/fmt/stylefmt/readme.snap index 0b6b9ed..23b1063 100644 --- a/malva/tests/fmt/stylefmt/readme.snap +++ b/malva/tests/fmt/stylefmt/readme.snap @@ -3,7 +3,8 @@ source: malva/tests/fmt.rs --- // mixin for clearfix @mixin clearfix() { - &:before, &:after { + &:before, + &:after { content: " "; display: table; }