Skip to content

Commit

Permalink
fix: migrate prettier auto endofline to LF as it's the default (#2145)
Browse files Browse the repository at this point in the history
Co-authored-by: Ze-Zheng Wu <[email protected]>
  • Loading branch information
eMerzh and Sec-ant authored Mar 22, 2024
1 parent f0b4b03 commit 3c389ba
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fixes [#2131](https://github.com/biomejs/biome/issues/2131), where folders were incorrectly ignored when running the command `check`. Now folders are correctly ignored based on their command. Contributed by @ematipico

- Smoother handling of `"endOfLine": "auto"` in prettier migration: falling back to `"lf"` ([#2145](https://github.com/biomejs/biome/pull/2145)). Contributed by @eMerzh

### Configuration

#### Bug fixes
Expand Down
8 changes: 7 additions & 1 deletion crates/biome_cli/src/execute/migrate/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum EndOfLine {
Lf,
Crlf,
Cr,
Auto,
}

#[derive(Clone, Debug, Default, Deserializable, Eq, PartialEq)]
Expand Down Expand Up @@ -134,6 +135,7 @@ impl From<EndOfLine> for LineEnding {
EndOfLine::Lf => LineEnding::Lf,
EndOfLine::Crlf => LineEnding::Crlf,
EndOfLine::Cr => LineEnding::Cr,
EndOfLine::Auto => LineEnding::default(),
}
}
}
Expand Down Expand Up @@ -342,8 +344,12 @@ pub(crate) fn read_prettier_files(
}));
} else {
let prettier_configuration = deserialized.into_deserialized();

if let Some(prettier_configuration) = prettier_configuration {
if prettier_configuration.end_of_line == EndOfLine::Auto {
console.log(markup! {
<Warn>"Prettier's `\"endOfLine\": \"auto\"` option is not supported in Biome. The default `\"lf\"` option is used instead."</Warn>
});
}
let formatter_configuration = prettier_configuration
.clone()
.try_into()
Expand Down
31 changes: 31 additions & 0 deletions crates/biome_cli/tests/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,37 @@ fn prettier_migrate() {
));
}

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

let configuration = r#"{}"#;
let prettier = r#"{ "endOfLine": "auto" }"#;

let configuration_path = Path::new("biome.json");
fs.insert(configuration_path.into(), configuration.as_bytes());

let prettier_path = Path::new(".prettierrc");
fs.insert(prettier_path.into(), prettier.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("migrate"), "prettier"].as_slice()),
);

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

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

#[test]
fn prettier_migrate_with_ignore() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{}
```

## `.prettierrc`

```prettierrc
{ "endOfLine": "auto" }
```

# Emitted Messages

```block
Prettier's `"endOfLine": "auto"` option is not supported in Biome. The default `"lf"` option is used instead.
```

```block
biome.json migrate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
i Configuration file can be updated.
1 │ - {}
1 │ + {
2 │ + → "formatter":·{
3 │ + → → "enabled":·true,
4 │ + → → "formatWithErrors":·false,
5 │ + → → "indentStyle":·"space",
6 │ + → → "indentWidth":·2,
7 │ + → → "lineEnding":·"lf",
8 │ + → → "lineWidth":·80,
9 │ + → → "attributePosition":·"auto"
10 │ + → },
11 │ + → "javascript":·{
12 │ + → → "formatter":·{
13 │ + → → → "jsxQuoteStyle":·"double",
14 │ + → → → "quoteProperties":·"asNeeded",
15 │ + → → → "trailingComma":·"all",
16 │ + → → → "semicolons":·"asNeeded",
17 │ + → → → "arrowParentheses":·"always",
18 │ + → → → "bracketSpacing":·true,
19 │ + → → → "bracketSameLine":·false,
20 │ + → → → "quoteStyle":·"single",
21 │ + → → → "attributePosition":·"auto"
22 │ + → → }
23 │ + → }
24 │ + }
25 │ +
```

```block
Run the command with the option --write to apply the changes.
```
2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fixes [#2131](https://github.com/biomejs/biome/issues/2131), where folders were incorrectly ignored when running the command `check`. Now folders are correctly ignored based on their command. Contributed by @ematipico

- Smoother handling of `"endOfLine": "auto"` in prettier migration: falling back to `"lf"` ([#2145](https://github.com/biomejs/biome/pull/2145)). Contributed by @eMerzh

### Configuration

#### Bug fixes
Expand Down

0 comments on commit 3c389ba

Please sign in to comment.