Skip to content

Commit 0cb1809

Browse files
committed
feat: rename to singleLineTopLevelDeclarations
from `topLevelDeclarations.preferSingleLine`
1 parent 4e77747 commit 0cb1809

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
- [keyframeSelectorNotation](./config/keyframe-selector-notation.md)
2020
- [attrValueQuotes](./config/attr-value-quotes.md)
2121
- [preferSingleLine](./config/prefer-single-line.md)
22+
- [singleLineTopLevelDeclarations](./config/single-line-top-level-declarations.md)
2223
- [selectorOverrideCommentDirective](./config/selector-override-comment-directive.md)
2324
- [ignoreCommentDirective](./config/ignore-comment-directive.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# `singleLineTopLevelDeclarations`
2+
3+
Control whether to force to format all top-level declarations on a single line.
4+
5+
When this option is `true`, trailing semicolons are removed.
6+
7+
Most of the time, you don't need to set this option, because declarations at top level are invalid,
8+
but if you're formatting HTML's `style` attribute, you may want to set this to `true`.
9+
10+
Default option is `false`.
11+
12+
## Example for `false`
13+
14+
[Playground](https://malva-play.vercel.app/?code=H4sIAAAAAAAAAyvPTCnJsFIwNDAoqLDmykjNTM8ogXEBfacJkBwAAAA%3D&config=H4sIAAAAAAAAA6vmUlBQKs7MS89J9cnMSw3JL%2FBJLUvNcUlNzkksSizJzM8rVrJSSEvMKU7lqgUASka%2FoS0AAAA%3D&syntax=css)
15+
16+
```css
17+
width: 100px;
18+
height: 100px;
19+
```
20+
21+
## Example for `true`
22+
23+
[Playground](https://malva-play.vercel.app/?code=H4sIAAAAAAAAAyvPTCnJsFIwNDAoqLDmykjNTM8ogXEBfacJkBwAAAA%3D&config=H4sIAAAAAAAAA6vmUlBQKs7MS89J9cnMSw3JL%2FBJLUvNcUlNzkksSizJzM8rVrJSKCkqTeWqBQAYXl8RLAAAAA%3D%3D&syntax=css)
24+
25+
```css
26+
width: 100px; height: 100px
27+
```

dprint_plugin/deployment/schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@
261261
"type": ["boolean", "null"],
262262
"default": null
263263
},
264-
"topLevelDeclarations.preferSingleLine": {
265-
"description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.",
266-
"type": ["boolean", "null"],
267-
"default": null
264+
"singleLineTopLevelDeclarations": {
265+
"description": "Control whether to force to format all top-level declarations on a single line.",
266+
"type": "boolean",
267+
"default": false
268268
},
269269
"selectorOverrideCommentDirective": {
270270
"description": "Text directive for overriding selector formatting.",

dprint_plugin/src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ pub(crate) fn resolve_config(
259259
"lessMixinParamsPreferSingleLine",
260260
&mut diagnostics,
261261
),
262-
top_level_declarations_prefer_single_line: get_nullable_value(
262+
single_line_top_level_declarations: get_value(
263263
&mut config,
264-
"topLevelDeclarationsPreferSingleLine",
264+
"singleLineTopLevelDeclarations",
265+
false,
265266
&mut diagnostics,
266267
),
267268
selector_override_comment_directive: get_value(

malva/src/config.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,13 @@ pub struct LanguageOptions {
235235
)]
236236
/// See [`preferSingleLine`](https://malva.netlify.app/config/prefer-single-line.html)
237237
pub less_mixin_params_prefer_single_line: Option<bool>,
238+
238239
#[cfg_attr(
239240
feature = "config_serde",
240-
serde(
241-
rename = "top_level_declarations.prefer_single_line",
242-
alias = "topLevelDeclarations.preferSingleLine"
243-
)
241+
serde(alias = "singleLineTopLevelDeclarations")
244242
)]
245-
/// See [`preferSingleLine`](https://malva.netlify.app/config/prefer-single-line.html)
246-
pub top_level_declarations_prefer_single_line: Option<bool>,
243+
/// See [`singleLineTopLevelDeclarations`](https://malva.netlify.app/config/single-line-top-level-declarations.html)
244+
pub single_line_top_level_declarations: bool,
247245

248246
#[cfg_attr(
249247
feature = "config_serde",
@@ -284,7 +282,7 @@ impl Default for LanguageOptions {
284282
less_import_options_prefer_single_line: None,
285283
less_mixin_args_prefer_single_line: None,
286284
less_mixin_params_prefer_single_line: None,
287-
top_level_declarations_prefer_single_line: None,
285+
single_line_top_level_declarations: false,
288286
selector_override_comment_directive: "malva-selector-override".into(),
289287
ignore_comment_directive: "malva-ignore".into(),
290288
}

malva/src/doc_gen/stmt.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,7 @@ impl<'s> DocGen<'s> for Stylesheet<'s> {
342342
fn doc(&self, ctx: &Ctx<'_, 's>, state: &State) -> Doc<'s> {
343343
let mut stmt_docs = vec![];
344344
if ctx.syntax == Syntax::Css
345-
&& matches!(
346-
ctx.options.top_level_declarations_prefer_single_line,
347-
Some(true)
348-
)
345+
&& ctx.options.single_line_top_level_declarations
349346
&& self.statements.iter().all(|stmt| stmt.is_declaration())
350347
{
351348
// Declarations can't be at the top level in CSS,

0 commit comments

Comments
 (0)