Skip to content

Commit

Permalink
chore: update config
Browse files Browse the repository at this point in the history
  • Loading branch information
fireairforce committed Mar 2, 2025
1 parent 99b9d96 commit 6913575
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 42 deletions.
1 change: 1 addition & 0 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl CommandRunner for FormatCommandPayload {

formatter.enabled = Some(true.into());
}

if self.css_formatter.is_some() {
let css = configuration.css.get_or_insert_with(Default::default);
css.formatter.merge_with(self.css_formatter.clone());
Expand Down
87 changes: 47 additions & 40 deletions crates/biome_cli/tests/cases/editorconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,53 @@ indent_size = 8
"#;
fs.insert(test_file.into(), contents);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["format", "--write", test_file.as_str()].as_slice()),
);

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

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

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

let editorconfig = Utf8Path::new(".editorconfig");
fs.insert(
editorconfig.into(),
r#"
[*]
indent_style = space
indent_size = 8
"#,
);

let test_file = Utf8Path::new("test.js");
let contents = r#"function setName(name) {
currentName = name;
}
"#;
fs.insert(test_file.into(), contents);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"format",
"--write",
"--use-editorconfig=true",
"--use-editorconfig=false",
test_file.as_str(),
]
.as_slice(),
Expand All @@ -45,7 +84,7 @@ indent_size = 8

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig",
"should_not_use_editorconfig",
fs,
console,
result,
Expand Down Expand Up @@ -127,7 +166,7 @@ indent_size = 8
let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["check", "--use-editorconfig=true", test_file.as_str()].as_slice()),
Args::from(["check", test_file.as_str()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");
Expand Down Expand Up @@ -226,15 +265,7 @@ indent_style = tab
let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"format",
"--write",
"--use-editorconfig=true",
test_file.as_str(),
]
.as_slice(),
),
Args::from(["format", "--write", test_file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand Down Expand Up @@ -275,15 +306,7 @@ indent_size = 8
let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"check",
"--indent-width=4",
"--use-editorconfig=true",
test_file.as_str(),
]
.as_slice(),
),
Args::from(["check", "--indent-width=4", test_file.as_str()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");
Expand Down Expand Up @@ -336,15 +359,7 @@ indent_style = space
let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"check",
"--use-editorconfig=true",
test_file.as_str(),
test_file2.as_str(),
]
.as_slice(),
),
Args::from(["check", test_file.as_str(), test_file2.as_str()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");
Expand Down Expand Up @@ -383,7 +398,7 @@ indent_size = 8
let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["ci", "--use-editorconfig=true", test_file.as_str()].as_slice()),
Args::from(["ci", test_file.as_str()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");
Expand Down Expand Up @@ -467,15 +482,7 @@ insert_final_newline = false
let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"format",
"--write",
"--use-editorconfig=true",
test_file.as_str(),
]
.as_slice(),
),
Args::from(["format", "--write", test_file.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
snapshot_kind: text
---
## `.editorconfig`

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

## `test.js`

```js
function setName(name) {
currentName = name;
}

```

# Emitted Messages

```block
Formatted 1 file in <TIME>. Fixed 1 file.
```
3 changes: 1 addition & 2 deletions crates/biome_configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ impl Configuration {
pub fn use_editorconfig(&self) -> bool {
self.formatter
.as_ref()
.and_then(|f| f.use_editorconfig)
.is_some_and(|editorconfig| editorconfig.value())
.is_some_and(|c| c.use_editorconfig_resolved())
}

pub fn get_json_linter_configuration(&self) -> JsonLinterConfiguration {
Expand Down

0 comments on commit 6913575

Please sign in to comment.