Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_cli): Use lines() separator for os independent git ignore pa… #4558

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#### Other changes

- Fixes [#4556](https://github.com/rome/tools/issues/4556) using `lines()` to enable OS independent line parsing when processing the .gitignore file.
- Add a new option to ignore unknown files

```shell
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_cli/src/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) fn read_vcs_ignore_file(

if let Some((buffer, _)) = buffer {
return Ok(buffer
.split('\n')
.lines()
// remove empty lines
.filter(|line| !line.is_empty())
.filter_map(|item| {
Expand Down
62 changes: 62 additions & 0 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,68 @@ file2.js
));
}

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

let rome_json = r#"{
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}"#;

let git_ignore = "something.js\nfile2.js\r\nfile3.js";

let code3 = r#"console.log('rome is cool');"#;
let code2 = r#"foo.call(); bar.call();"#;
let code1 = r#"blah.call();"#;

let file_path1 = Path::new("file1.js");
fs.insert(file_path1.into(), code1.as_bytes());

// ignored files
let file_path2 = Path::new("file2.js");
fs.insert(file_path2.into(), code2.as_bytes());
let file_path3 = Path::new("file3.js");
fs.insert(file_path3.into(), code3.as_bytes());

// configuration
let config_path = Path::new("rome.json");
fs.insert(config_path.into(), rome_json.as_bytes());

// git folder
let git_folder = Path::new(".git");
fs.insert(git_folder.into(), "".as_bytes());

// git ignore file
let ignore_file = Path::new(".gitignore");
fs.insert(ignore_file.into(), git_ignore.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(&[
("check"),
file_path1.as_os_str().to_str().unwrap(),
file_path2.as_os_str().to_str().unwrap(),
file_path3.as_os_str().to_str().unwrap(),
]),
);

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

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

#[test]
fn ignore_vcs_ignored_file_via_cli() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
source: crates/rome_cli/tests/snap_test.rs
assertion_line: 346
expression: content
---
## `rome.json`

```json
{
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}
```

## `.git`

```git

```

## `.gitignore`

```gitignore
something.js
file2.js
file3.js
```

## `file1.js`

```js
blah.call();
```

## `file2.js`

```js
foo.call(); bar.call();
```

## `file3.js`

```js
console.log('rome is cool');
```

# Emitted Messages

```block
Checked 1 file(s) in <TIME>
```