diff --git a/CHANGELOG.md b/CHANGELOG.md index 45774896b92..fdb9b5614be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,31 @@ ## [Unreleased] ### CLI + +#### Other changes + +- Add a new option to ignore unknown files + + ```shell + rome format ./src --files-ignore-unknown=true + ``` + Doing so, Rome won't emit diagnostics for file that it doesn't know how to handle. + ### Configuration + +#### Other changes + +- Add a new option to ignore unknown files: + + ```json + { + "files": { + "ignoreUnknown": true + } + } + ``` + Doing so, Rome won't emit diagnostics for file that it doesn't know how to handle. + ### Editors ### Formatter ### Linter diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index edbe5febf44..1817f2c3110 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -2273,3 +2273,34 @@ if (true) { result, )); } + +#[test] +fn ignores_unknown_file() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path1 = Path::new("test.txt"); + fs.insert(file_path1.into(), *b"content"); + + let file_path2 = Path::new("test.js"); + fs.insert(file_path2.into(), *b"console.log('bar');\n"); + + 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(), + "--files-ignore-unknown=true", + ]), + ); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "ignores_unknown_file", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/commands/ci.rs b/crates/rome_cli/tests/commands/ci.rs index 91336618b17..2419a88b2d3 100644 --- a/crates/rome_cli/tests/commands/ci.rs +++ b/crates/rome_cli/tests/commands/ci.rs @@ -871,3 +871,34 @@ file2.js result, )); } + +#[test] +fn ignores_unknown_file() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path1 = Path::new("test.txt"); + fs.insert(file_path1.into(), *b"content"); + + let file_path2 = Path::new("test.js"); + fs.insert(file_path2.into(), *b"console.log('bar');\n"); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[ + ("ci"), + file_path1.as_os_str().to_str().unwrap(), + file_path2.as_os_str().to_str().unwrap(), + "--files-ignore-unknown=true", + ]), + ); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "ignores_unknown_file", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index 0b5ac88e3fe..f2ed9400461 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -1442,7 +1442,7 @@ fn no_supported_file_found() { let result = run_cli( DynRef::Borrowed(&mut fs), &mut console, - Args::from(&[("check"), "."]), + Args::from(&[("format"), "."]), ); eprintln!("{:?}", console.out_buffer); @@ -1608,3 +1608,34 @@ file2.js result, )); } + +#[test] +fn ignores_unknown_file() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path1 = Path::new("test.txt"); + fs.insert(file_path1.into(), *b"content"); + + let file_path2 = Path::new("test.js"); + fs.insert(file_path2.into(), *b"console.log('bar');\n"); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[ + ("format"), + file_path1.as_os_str().to_str().unwrap(), + file_path2.as_os_str().to_str().unwrap(), + "--files-ignore-unknown=true", + ]), + ); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "ignores_unknown_file", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap index fe477cd16f5..11bf0c324c9 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_check/check_help.snap @@ -33,6 +33,8 @@ Available options: The configuration of the filesystem --files-max-size The maximum allowed size for source code files in bytes. Files above this limit will be ignored for performance reason. Defaults to 1 MiB + --files-ignore-unknown Tells Rome to not emit diagnostics when handling files + that doesn't know Options applied to the formatter --indent-style The indent style. diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/ignores_unknown_file.snap b/crates/rome_cli/tests/snapshots/main_commands_check/ignores_unknown_file.snap new file mode 100644 index 00000000000..d0f28633bd4 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/ignores_unknown_file.snap @@ -0,0 +1,24 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +## `test.js` + +```js +console.log('bar'); + +``` + +## `test.txt` + +```txt +content +``` + +# Emitted Messages + +```block +Checked 1 file(s) in