-
-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grit): implement CSS plugins (#4448)
- Loading branch information
Showing
36 changed files
with
610 additions
and
111 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
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 |
---|---|---|
|
@@ -9,4 +9,5 @@ mod migrate; | |
mod migrate_eslint; | ||
mod migrate_prettier; | ||
mod rage; | ||
mod search; | ||
mod version; |
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,118 @@ | ||
use biome_console::BufferConsole; | ||
use biome_fs::MemoryFileSystem; | ||
use biome_service::DynRef; | ||
use bpaf::Args; | ||
use std::path::Path; | ||
|
||
use crate::{ | ||
run_cli, | ||
snap_test::{assert_cli_snapshot, SnapshotPayload}, | ||
}; | ||
|
||
// Feel free to add content at the end of this dummy file. It shouldn't affect | ||
// existing tests. | ||
const CSS_FILE_CONTENT: &str = r#"div { | ||
color: green; | ||
}"#; | ||
|
||
// Feel free to add content at the end of this dummy file. It shouldn't affect | ||
// existing tests. | ||
const JS_FILE_CONTENT: &str = r#"const a = 'foo';"#; | ||
|
||
#[test] | ||
fn search_css_pattern() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let file_path = Path::new("file.css"); | ||
fs.insert(file_path.into(), CSS_FILE_CONTENT.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
"search", | ||
"--language=css", | ||
"`color: green`", | ||
file_path.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"search_css_pattern", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} | ||
|
||
#[test] | ||
fn search_css_pattern_shorthand() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let file_path = Path::new("file.css"); | ||
fs.insert(file_path.into(), CSS_FILE_CONTENT.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
"search", | ||
"-lcss", | ||
"`color: green`", | ||
file_path.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"search_css_pattern_shorthand", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} | ||
|
||
#[test] | ||
fn search_js_pattern() { | ||
let mut fs = MemoryFileSystem::default(); | ||
let mut console = BufferConsole::default(); | ||
|
||
let file_path = Path::new("file.js"); | ||
fs.insert(file_path.into(), JS_FILE_CONTENT.as_bytes()); | ||
|
||
let result = run_cli( | ||
DynRef::Borrowed(&mut fs), | ||
&mut console, | ||
Args::from( | ||
[ | ||
"search", | ||
"`\"foo\"`", | ||
file_path.as_os_str().to_str().unwrap(), | ||
] | ||
.as_slice(), | ||
), | ||
); | ||
|
||
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_cli_snapshot(SnapshotPayload::new( | ||
module_path!(), | ||
"search_js_pattern", | ||
fs, | ||
console, | ||
result, | ||
)); | ||
} |
24 changes: 24 additions & 0 deletions
24
crates/biome_cli/tests/snapshots/main_commands_search/search_css_pattern.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,24 @@ | ||
--- | ||
source: crates/biome_cli/tests/snap_test.rs | ||
expression: content | ||
--- | ||
## `file.css` | ||
|
||
```css | ||
div { | ||
color: green; | ||
} | ||
``` | ||
|
||
# Emitted Messages | ||
|
||
```block | ||
file.css:2:5 search ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
2 │ color: green; | ||
``` | ||
|
||
```block | ||
Searched 1 file in <TIME>. Found 1 match. | ||
``` |
24 changes: 24 additions & 0 deletions
24
crates/biome_cli/tests/snapshots/main_commands_search/search_css_pattern_shorthand.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,24 @@ | ||
--- | ||
source: crates/biome_cli/tests/snap_test.rs | ||
expression: content | ||
--- | ||
## `file.css` | ||
|
||
```css | ||
div { | ||
color: green; | ||
} | ||
``` | ||
|
||
# Emitted Messages | ||
|
||
```block | ||
file.css:2:5 search ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
2 │ color: green; | ||
``` | ||
|
||
```block | ||
Searched 1 file in <TIME>. Found 1 match. | ||
``` |
22 changes: 22 additions & 0 deletions
22
crates/biome_cli/tests/snapshots/main_commands_search/search_js_pattern.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,22 @@ | ||
--- | ||
source: crates/biome_cli/tests/snap_test.rs | ||
expression: content | ||
--- | ||
## `file.js` | ||
|
||
```js | ||
const a = 'foo'; | ||
``` | ||
|
||
# Emitted Messages | ||
|
||
```block | ||
file.js:1:11 search ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
1 │ const a = 'foo'; | ||
``` | ||
|
||
```block | ||
Searched 1 file in <TIME>. Found 1 match. | ||
``` |
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.