From 23febf834348c995c802b4ef9ec40532865a48f7 Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:00:46 +0200 Subject: [PATCH 1/3] fix(rome_cli): Use lines() separator for os independent git ignore parsing --- crates/rome_cli/src/vcs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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| { From a3de5f50d348359e9c2e27a7046bf912de6d7a73 Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Sun, 11 Jun 2023 17:10:48 +0200 Subject: [PATCH 2/3] chore: Add changelogs --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdaecea0538..8952834c9e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## [Unreleased] ### CLI +#### Other changes +Fixes [#4556](https://github.com/rome/tools/issues/4556) using `lines()` to enable OS independent line parsing when processing the .gitignore file. ### Configuration ### Editors ### Formatter From e504e1a71f11313dab1bc17c6dec6743560512e6 Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Sun, 18 Jun 2023 23:01:13 +0200 Subject: [PATCH 3/3] test(rome_cli): Test LF and CRLF vcs ignore file parsing --- crates/rome_cli/tests/commands/check.rs | 62 +++++++++++++++++++ .../ignore_vcs_os_independent_parse.snap | 56 +++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 crates/rome_cli/tests/snapshots/main_commands_check/ignore_vcs_os_independent_parse.snap diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index edbe5febf44..6ce8aded524 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