-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable CSS linter and CSS formatter
- Loading branch information
Showing
40 changed files
with
952 additions
and
234 deletions.
There are no files selected for viewing
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
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
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,183 @@ | ||
use crate::run_cli; | ||
use crate::snap_test::{assert_cli_snapshot, SnapshotPayload}; | ||
use biome_console::BufferConsole; | ||
use biome_fs::MemoryFileSystem; | ||
use biome_service::DynRef; | ||
use bpaf::Args; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn should_not_format_files_by_default() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let css_file_content = r#"html {}"#; | ||
let css_file = Path::new("input.css"); | ||
fs.insert(css_file.into(), css_file_content.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from([("format"), css_file.as_os_str().to_str().unwrap()].as_slice()), | ||
); | ||
|
||
// no files processed error | ||
assert!(result.is_err(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"should_not_format_files_by_default", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} | ||
|
||
#[test] | ||
fn should_format_files_by_when_opt_in() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let css_file_content = r#"html {}"#; | ||
let css_file = Path::new("input.css"); | ||
fs.insert(css_file.into(), css_file_content.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
"format", | ||
"--css-formatter-enabled=true", | ||
css_file.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
// not formatted error | ||
assert!(result.is_err(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"should_format_files_by_when_opt_in", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} | ||
|
||
#[test] | ||
fn should_format_write_files_by_when_opt_in() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let css_file_content = r#"html {}"#; | ||
let css_file = Path::new("input.css"); | ||
fs.insert(css_file.into(), css_file_content.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
"format", | ||
"--write", | ||
"--css-formatter-enabled=true", | ||
css_file.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"should_format_write_files_by_when_opt_in", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} | ||
|
||
#[test] | ||
fn should_not_lint_files_by_default() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let file_path = Path::new("biome.json"); | ||
fs.insert( | ||
file_path.into(), | ||
r#"{ | ||
"linter": { "rules": { "all": true } } | ||
} | ||
"# | ||
.as_bytes(), | ||
); | ||
|
||
let css_file_content = r#"html {}"#; | ||
let css_file = Path::new("input.css"); | ||
fs.insert(css_file.into(), css_file_content.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from(["lint", css_file.as_os_str().to_str().unwrap()].as_slice()), | ||
); | ||
|
||
// no files processed error | ||
assert!(result.is_err(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"should_not_lint_files_by_default", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} | ||
|
||
#[test] | ||
fn should_lint_files_by_when_enabled() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let file_path = Path::new("biome.json"); | ||
fs.insert( | ||
file_path.into(), | ||
r#"{ | ||
"linter": { "rules": { "all": true } } | ||
} | ||
"# | ||
.as_bytes(), | ||
); | ||
|
||
let css_file_content = r#"html {}"#; | ||
let css_file = Path::new("input.css"); | ||
fs.insert(css_file.into(), css_file_content.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
"lint", | ||
"--css-linter-enabled=true", | ||
css_file.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
// diagnostic | ||
assert!(result.is_err(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"should_lint_files_by_when_enabled", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} |
Oops, something went wrong.