Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
faultyserver committed Dec 31, 2023
1 parent a0c6e2d commit 10f5d9e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
44 changes: 38 additions & 6 deletions crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,42 @@ fn applies_custom_quote_style() {

let file_path = Path::new("file.js");
fs.insert(file_path.into(), APPLY_QUOTE_STYLE_BEFORE.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(
[
("format"),
("--quote-style"),
("single"),
("--quote-properties"),
("preserve"),
("--write"),
file_path.as_os_str().to_str().unwrap(),
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_file_contents(&fs, file_path, APPLY_QUOTE_STYLE_AFTER);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"applies_custom_quote_style",
fs,
console,
result,
));
}

#[test]
fn applies_custom_css_quote_style() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let css_file_path = Path::new("file.css");
fs.insert(
css_file_path.into(),
Expand All @@ -603,12 +639,9 @@ fn applies_custom_quote_style() {
Args::from(
[
("format"),
("--quote-style"),
("--css-formatter-quote-style"),
("single"),
("--quote-properties"),
("preserve"),
("--write"),
file_path.as_os_str().to_str().unwrap(),
css_file_path.as_os_str().to_str().unwrap(),
]
.as_slice(),
Expand All @@ -617,12 +650,11 @@ fn applies_custom_quote_style() {

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_file_contents(&fs, file_path, APPLY_QUOTE_STYLE_AFTER);
assert_file_contents(&fs, css_file_path, APPLY_CSS_QUOTE_STYLE_AFTER);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"applies_custom_quote_style",
"applies_custom_css_quote_style",
fs,
console,
result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@ expression: content
"include": ["test2.js"],
"formatter": { "lineWidth": 120, "indentStyle": "space" },
"javascript": { "formatter": { "semicolons": "asNeeded" } }
},
{
"include": ["test.css"],
"formatter": { "lineWidth": 120, "indentStyle": "space" },
"css": { "formatter": { "quoteStyle": "single" } }
}
]
}
```

## `test.css`

```css
[class='foo'] {
background-image: url('/path/to/file.jpg');
}

```

## `test.js`

```js
Expand All @@ -38,7 +52,7 @@ const a = ["loreum", "ipsum"]
# Emitted Messages

```block
Formatted 2 file(s) in <TIME>
Formatted 3 file(s) in <TIME>
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `file.css`

```css
[class='foo'] {
background-image: url('/path/to/file.jpg');
}

```

# Emitted Messages

```block
Formatted 1 file(s) in <TIME>
```


4 changes: 1 addition & 3 deletions crates/biome_service/src/configuration/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ pub struct CssFormatter {
#[bpaf(long("css-formatter-line-width"), argument("NUMBER"), optional)]
pub line_width: Option<LineWidth>,

// TODO: Rename this to `css-formatter-quote-style` once it's also a
// top-level option. Right now this acts for both JS and CSS.
#[bpaf(long("quote-style"), argument("double|single"), optional, hide)]
#[bpaf(long("css-formatter-quote-style"), argument("double|single"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
pub quote_style: Option<QuoteStyle>,
}
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_service/src/configuration/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ fn to_javascript_language_settings(
.or(parent_formatter.bracket_same_line);
language_setting.formatter.enabled = formatter.enabled.or(parent_formatter.enabled);
language_setting.formatter.line_width = formatter.line_width.or(parent_formatter.line_width);
language_setting.formatter.line_ending = formatter.line_ending.or(parent_formatter.line_ending);
language_setting.formatter.indent_width = formatter
.indent_width
.map(Into::into)
Expand Down Expand Up @@ -482,6 +483,7 @@ fn to_json_language_settings(

language_setting.formatter.enabled = formatter.enabled.or(parent_formatter.enabled);
language_setting.formatter.line_width = formatter.line_width.or(parent_formatter.line_width);
language_setting.formatter.line_ending = formatter.line_ending.or(parent_formatter.line_ending);
language_setting.formatter.indent_width = formatter
.indent_width
.map(Into::into)
Expand Down Expand Up @@ -515,6 +517,7 @@ fn to_css_language_settings(

language_setting.formatter.enabled = formatter.enabled.or(parent_formatter.enabled);
language_setting.formatter.line_width = formatter.line_width.or(parent_formatter.line_width);
language_setting.formatter.line_ending = formatter.line_ending.or(parent_formatter.line_ending);
language_setting.formatter.indent_width = formatter
.indent_width
.map(Into::into)
Expand All @@ -524,6 +527,7 @@ fn to_css_language_settings(
.indent_style
.map(Into::into)
.or(parent_formatter.indent_style);
language_setting.formatter.quote_style = formatter.quote_style.or(parent_formatter.quote_style);

let parser = conf.parser.take().unwrap_or_default();
let parent_parser = &parent_settings.parser;
Expand Down

0 comments on commit 10f5d9e

Please sign in to comment.