-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(biome_service): search for, load .editorconfig files, and merge …
…settings
- Loading branch information
Showing
11 changed files
with
283 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use crate::run_cli; | ||
use crate::snap_test::assert_file_contents; | ||
use biome_console::BufferConsole; | ||
use biome_fs::MemoryFileSystem; | ||
use biome_service::DynRef; | ||
use bpaf::Args; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn should_use_editorconfig() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let editorconfig = Path::new(".editorconfig"); | ||
fs.insert( | ||
editorconfig.into(), | ||
r#" | ||
[*] | ||
max_line_length = 300 | ||
"#, | ||
); | ||
|
||
let test_file = Path::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"); | ||
"#; | ||
fs.insert(test_file.into(), contents); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
("format"), | ||
("--write"), | ||
test_file.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_file_contents(&fs, test_file, contents); | ||
} | ||
|
||
#[test] | ||
fn should_have_biome_override_editorconfig() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let editorconfig = Path::new(".editorconfig"); | ||
fs.insert( | ||
editorconfig.into(), | ||
r#" | ||
[*] | ||
max_line_length = 100 | ||
indent_style = tab | ||
"#, | ||
); | ||
let biomeconfig = Path::new("biome.json"); | ||
fs.insert( | ||
biomeconfig.into(), | ||
r#" | ||
{ | ||
"formatter": { | ||
"lineWidth": 90 | ||
} | ||
} | ||
"#, | ||
); | ||
|
||
let test_file = Path::new("test.js"); | ||
let contents = r#"console.log( | ||
"really long string that should break if the line width is <=90, but not at 100", | ||
); | ||
"#; | ||
fs.insert(test_file.into(), contents); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
("format"), | ||
("--write"), | ||
test_file.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_file_contents(&fs, test_file, contents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_use_editorconfig.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
source: crates/biome_cli/tests/snap_test.rs | ||
expression: content | ||
--- | ||
## `.editorconfig` | ||
|
||
```editorconfig | ||
[*] | ||
max_line_length = 300 | ||
``` | ||
|
||
## `test.js` | ||
|
||
```js | ||
console.log("really long string that should cause a break if the line width remains at the default 80 characters"); | ||
|
||
``` | ||
|
||
# Emitted Messages | ||
|
||
```block | ||
Checked 1 file in <TIME>. No fixes needed. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.