Skip to content

Commit

Permalink
refactor(editorconfig): remove support for max_line_length (#4894)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jan 13, 2025
1 parent c9d0ba8 commit d43aa7e
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
cli: major
---

# Remove support for `max_line_length` from `.editorconfig`, as it isn't part of the official spec anymore
77 changes: 45 additions & 32 deletions crates/biome_cli/tests/cases/editorconfig.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::run_cli;
use crate::snap_test::{assert_cli_snapshot, assert_file_contents, SnapshotPayload};
use crate::snap_test::{assert_cli_snapshot, SnapshotPayload};
use biome_console::BufferConsole;
use biome_fs::MemoryFileSystem;
use bpaf::Args;
Expand All @@ -15,12 +15,15 @@ fn should_use_editorconfig() {
editorconfig.into(),
r#"
[*]
max_line_length = 300
indent_style = space
indent_size = 8
"#,
);

let test_file = Utf8Path::new("test.js");
let contents = r#"console.log("really long string that should cause a break if the line width remains at the default 80 characters");
let contents = r#"function setName(name) {
currentName = name;
}
"#;
fs.insert(test_file.into(), contents);

Expand All @@ -40,7 +43,6 @@ max_line_length = 300

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig",
Expand All @@ -60,7 +62,8 @@ fn should_use_editorconfig_enabled_from_biome_conf() {
editorconfig.into(),
r#"
[*]
max_line_length = 300
indent_style = space
indent_size = 8
"#,
);

Expand All @@ -76,7 +79,9 @@ max_line_length = 300
);

let test_file = Utf8Path::new("test.js");
let contents = r#"console.log("really long string that should cause a break if the line width remains at the default 80 characters");
let contents = r#"function setName(name) {
currentName = name;
}
"#;
fs.insert(test_file.into(), contents);

Expand All @@ -88,7 +93,6 @@ max_line_length = 300

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig_enabled_from_biome_conf",
Expand All @@ -108,12 +112,15 @@ fn should_use_editorconfig_check() {
editorconfig.into(),
r#"
[*]
max_line_length = 300
indent_style = space
indent_size = 8
"#,
);

let test_file = Utf8Path::new("test.js");
let contents = r#"console.log("really long string that should cause a break if the line width remains at the default 80 characters");
let contents = r#"function setName(name) {
currentName = name;
}
"#;
fs.insert(test_file.into(), contents);

Expand All @@ -123,9 +130,8 @@ max_line_length = 300
Args::from(["check", "--use-editorconfig=true", test_file.as_str()].as_slice()),
);

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig_check",
Expand All @@ -145,7 +151,8 @@ fn should_use_editorconfig_check_enabled_from_biome_conf() {
editorconfig.into(),
r#"
[*]
max_line_length = 300
indent_style = space
indent_size = 8
"#,
);

Expand All @@ -161,7 +168,9 @@ max_line_length = 300
);

let test_file = Utf8Path::new("test.js");
let contents = r#"console.log("really long string that should cause a break if the line width remains at the default 80 characters");
let contents = r#"function setName(name) {
currentName = name;
}
"#;
fs.insert(test_file.into(), contents);

Expand All @@ -171,9 +180,8 @@ max_line_length = 300
Args::from(["check", test_file.as_str()].as_slice()),
);

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig_check_enabled_from_biome_conf",
Expand All @@ -193,13 +201,12 @@ fn should_have_biome_override_editorconfig() {
editorconfig.into(),
r#"
[*]
max_line_length = 100
indent_style = tab
"#,
);
let biomeconfig = Utf8Path::new("biome.json");
let biome_config_path = Utf8Path::new("biome.json");
fs.insert(
biomeconfig.into(),
biome_config_path.into(),
r#"
{
"formatter": {
Expand Down Expand Up @@ -232,7 +239,6 @@ indent_style = tab

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_have_biome_override_editorconfig",
Expand All @@ -252,29 +258,35 @@ fn should_have_cli_override_editorconfig() {
editorconfig.into(),
r#"
[*]
max_line_length = 90
indent_style = space
indent_size = 8
"#,
);

let test_file = Utf8Path::new("test.js");
fs.insert(test_file.into(), r#"console.log("really long string that should break if the line width is <=90, but not at 100");
"#);
fs.insert(
test_file.into(),
r#"function setName(name) {
currentName = name;
}
"#,
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"check",
"--line-width=100",
"--indent-width=4",
"--use-editorconfig=true",
test_file.as_str(),
]
.as_slice(),
),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
Expand Down Expand Up @@ -356,12 +368,15 @@ fn should_use_editorconfig_ci() {
editorconfig.into(),
r#"
[*]
max_line_length = 300
indent_style = space
indent_size = 8
"#,
);

let test_file = Utf8Path::new("test.js");
let contents = r#"console.log("really long string that should cause a break if the line width remains at the default 80 characters");
let contents = r#"function setName(name) {
currentName = name;
}
"#;
fs.insert(test_file.into(), contents);

Expand All @@ -371,9 +386,8 @@ max_line_length = 300
Args::from(["ci", "--use-editorconfig=true", test_file.as_str()].as_slice()),
);

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig_ci",
Expand All @@ -393,7 +407,8 @@ fn should_use_editorconfig_ci_enabled_from_biome_conf() {
editorconfig.into(),
r#"
[*]
max_line_length = 300
indent_style = space
indent_size = 8
"#,
);

Expand All @@ -419,9 +434,8 @@ max_line_length = 300
Args::from(["ci", test_file.as_str()].as_slice()),
);

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig_ci_enabled_from_biome_conf",
Expand Down Expand Up @@ -466,7 +480,6 @@ insert_final_newline = false

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

assert_file_contents(&fs, test_file, contents);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_emit_diagnostics",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `biome.json`

Expand All @@ -17,7 +18,6 @@ expression: content
```editorconfig
[*]
max_line_length = 100
indent_style = tab
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `.editorconfig`

```editorconfig
[*]
max_line_length = 90
indent_style = space
indent_size = 8
```

## `test.js`

```js
console.log("really long string that should break if the line width is <=90, but not at 100");
function setName(name) {
currentName = name;
}

```

# Termination Message

```block
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks.
```

# Emitted Messages

```block
test.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Formatter would have printed the following content:
1 1 │ function setName(name) {
2 │ - ·currentName·=·name;
2 │ + ····currentName·=·name;
3 3 │ }
4 4 │
```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `.editorconfig`

```editorconfig
[*]
max_line_length = 300
indent_style = space
indent_size = 8
```

## `test.js`

```js
console.log("really long string that should cause a break if the line width remains at the default 80 characters");
function setName(name) {
currentName = name;
}

```

# Emitted Messages

```block
Formatted 1 file in <TIME>. No fixes applied.
Formatted 1 file in <TIME>. Fixed 1 file.
```
Loading

0 comments on commit d43aa7e

Please sign in to comment.