diff --git a/CHANGELOG.md b/CHANGELOG.md index 8357c12552a..8a23017212c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/crates/rome_cli/src/vcs.rs b/crates/rome_cli/src/vcs.rs index 650d5ef8482..7d76a2072bc 100644 --- a/crates/rome_cli/src/vcs.rs +++ b/crates/rome_cli/src/vcs.rs @@ -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| { diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index 14333f57db5..fe053588f96 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -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(); diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/ignore_vcs_os_independent_parse.snap b/crates/rome_cli/tests/snapshots/main_commands_check/ignore_vcs_os_independent_parse.snap new file mode 100644 index 00000000000..341ca486f17 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/ignore_vcs_os_independent_parse.snap @@ -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> +``` + +