diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index 24f40384eb7..7e48944623d 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -1104,17 +1104,29 @@ fn does_not_format_if_files_are_listed_in_ignore_option() { fn does_not_format_ignored_directories() { let mut console = BufferConsole::default(); let mut fs = MemoryFileSystem::default(); + let file_path = Path::new("rome.json"); fs.insert( file_path.into(), CONFIG_FORMATTER_IGNORED_DIRECTORIES.as_bytes(), ); - let ignored_file = Path::new("scripts/test.js"); - fs.insert(ignored_file.into(), <&str>::clone(&UNFORMATTED).as_bytes()); - - let file_to_format = Path::new("src/test.js"); - fs.insert(file_to_format.into(), UNFORMATTED.as_bytes()); + const FILES: [(&str, bool); 9] = [ + ("test.js", true), + ("test1.js", false), + ("test2.js", false), + ("test3/test.js", false), + ("test4/test.js", true), + ("test5/test.js", false), + ("test6/test.js", false), + ("test/test.test7.js", false), + ("test.test7.js", false), + ]; + + for (file_path, _) in FILES { + let file_path = Path::new(file_path); + fs.insert(file_path.into(), UNFORMATTED.as_bytes()); + } let result = run_cli( DynRef::Borrowed(&mut fs), @@ -1128,26 +1140,26 @@ fn does_not_format_ignored_directories() { assert!(result.is_ok(), "run_cli returned {result:?}"); - let mut file = fs - .open(ignored_file) - .expect("formatting target file was removed by the CLI"); + for (file_path, expect_formatted) in FILES { + let mut file = fs + .open(Path::new(file_path)) + .expect("formatting target file was removed by the CLI"); - let mut content = String::new(); - file.read_to_string(&mut content) - .expect("failed to read file from memory FS"); - - assert_eq!(content, UNFORMATTED, "we test the file is not formatted"); - drop(file); - let mut file = fs - .open(file_to_format) - .expect("formatting target file was removed by the CLI"); + let mut content = String::new(); + file.read_to_string(&mut content) + .expect("failed to read file from memory FS"); - let mut content = String::new(); - file.read_to_string(&mut content) - .expect("failed to read file from memory FS"); + let expected = if expect_formatted { + FORMATTED + } else { + UNFORMATTED + }; - assert_eq!(content, FORMATTED, "we test the file is formatted"); - drop(file); + assert_eq!( + content, expected, + "content of {file_path} doesn't match the expected content" + ); + } assert_cli_snapshot(SnapshotPayload::new( module_path!(), diff --git a/crates/rome_cli/tests/configs.rs b/crates/rome_cli/tests/configs.rs index ef9654b34ba..645af085130 100644 --- a/crates/rome_cli/tests/configs.rs +++ b/crates/rome_cli/tests/configs.rs @@ -207,7 +207,15 @@ pub const CONFIG_FORMATTER_AND_FILES_IGNORE: &str = r#"{ pub const CONFIG_FORMATTER_IGNORED_DIRECTORIES: &str = r#"{ "formatter": { - "ignore": ["scripts/*"] + "ignore": [ + "test1.js", + "./test2.js", + "./test3/**/*", + "/test4/**/*", + "test5/**/*", + "**/test6/*.js", + "*.test7.js" + ] } } "#; diff --git a/crates/rome_cli/tests/snapshots/main_commands_format/does_not_format_ignored_directories.snap b/crates/rome_cli/tests/snapshots/main_commands_format/does_not_format_ignored_directories.snap index 55e4d41eb6e..a5d15daf7b0 100644 --- a/crates/rome_cli/tests/snapshots/main_commands_format/does_not_format_ignored_directories.snap +++ b/crates/rome_cli/tests/snapshots/main_commands_format/does_not_format_ignored_directories.snap @@ -7,29 +7,80 @@ expression: content ```json { "formatter": { - "ignore": ["scripts/*"] + "ignore": [ + "test1.js", + "./test2.js", + "./test3/**/*", + "/test4/**/*", + "test5/**/*", + "**/test6/*.js", + "*.test7.js" + ] } } ``` -## `scripts/test.js` +## `test.js` + +```js +statement(); + +``` + +## `test.test7.js` + +```js + statement( ) +``` + +## `test/test.test7.js` + +```js + statement( ) +``` + +## `test1.js` + +```js + statement( ) +``` + +## `test2.js` ```js statement( ) ``` -## `src/test.js` +## `test3/test.js` + +```js + statement( ) +``` + +## `test4/test.js` ```js statement(); ``` +## `test5/test.js` + +```js + statement( ) +``` + +## `test6/test.js` + +```js + statement( ) +``` + # Emitted Messages ```block -Formatted 2 file(s) in