diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index 7bff0077b4c..78ae85761bf 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -1,7 +1,8 @@ use pico_args::Arguments; use std::env::temp_dir; use std::ffi::OsString; -use std::fs::{create_dir, create_dir_all, remove_dir_all}; +use std::fs::{create_dir, create_dir_all, remove_dir_all, File}; +use std::io::Write; #[cfg(target_family = "unix")] use std::os::unix::fs::symlink; #[cfg(target_os = "windows")] @@ -9,8 +10,8 @@ use std::os::windows::fs::{symlink_dir, symlink_file}; use std::path::{Path, PathBuf}; use crate::configs::{ - CONFIG_FILE_SIZE_LIMIT, CONFIG_LINTER_AND_FILES_IGNORE, CONFIG_LINTER_DISABLED, - CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC, CONFIG_LINTER_IGNORED_FILES, + CONFIG_FILE_SIZE_LIMIT, CONFIG_IGNORE_SYMLINK, CONFIG_LINTER_AND_FILES_IGNORE, + CONFIG_LINTER_DISABLED, CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC, CONFIG_LINTER_IGNORED_FILES, CONFIG_LINTER_SUPPRESSED_GROUP, CONFIG_LINTER_SUPPRESSED_RULE, CONFIG_LINTER_UPGRADE_DIAGNOSTIC, CONFIG_RECOMMENDED_GROUP, }; @@ -855,6 +856,119 @@ fn fs_error_unknown() { )); } +// Symbolic link ignore pattern test +// +// Verifies, that ignore patterns to symbolic links are allowed. +// +// ├── rome.json +// ├── hidden_nested +// │   └── test +// │   └── symlink_testcase1_2 -> hidden_testcase1 +// ├── hidden_testcase1 +// │   └── test +// │   └── test.js // ok +// ├── hidden_testcase2 +// │   ├── test1.ts // ignored +// │   ├── test2.ts // ignored +// │   └── test.js // ok +// └── src +// ├── symlink_testcase1_1 -> hidden_nested +// └── symlink_testcase2 -> hidden_testcase2 +#[test] +fn fs_files_ignore_symlink() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let root_path = temp_dir().join("rome_test_files_ignore_symlink"); + let src_path = root_path.join("src"); + + let testcase1_path = root_path.join("hidden_testcase1"); + let testcase1_sub_path = testcase1_path.join("test"); + let testcase2_path = root_path.join("hidden_testcase2"); + + let nested_path = root_path.join("hidden_nested"); + let nested_sub_path = nested_path.join("test"); + + #[allow(unused_must_use)] + { + remove_dir_all(root_path.clone()); + } + create_dir(root_path.clone()).unwrap(); + create_dir(src_path.clone()).unwrap(); + create_dir_all(testcase1_sub_path.clone()).unwrap(); + create_dir(testcase2_path.clone()).unwrap(); + create_dir_all(nested_sub_path.clone()).unwrap(); + + // src/symlink_testcase1_1 + let symlink_testcase1_1_path = src_path.join("symlink_testcase1_1"); + // hidden_nested/test/symlink_testcase1_2 + let symlink_testcase1_2_path = nested_sub_path.join("symlink_testcase1_2"); + // src/symlink_testcase2 + let symlink_testcase2_path = src_path.join("symlink_testcase2"); + + #[cfg(target_family = "unix")] + { + // src/test/symlink_testcase1_1 -> hidden_nested + symlink(nested_path, symlink_testcase1_1_path).unwrap(); + // hidden_nested/test/symlink_testcase1_2 -> hidden_testcase1 + symlink(testcase1_path, symlink_testcase1_2_path).unwrap(); + // src/symlink_testcase2 -> hidden_testcase2 + symlink(testcase2_path.clone(), symlink_testcase2_path).unwrap(); + } + + #[cfg(target_os = "windows")] + { + check_windows_symlink!(symlink_dir(nested_path.clone(), symlink_testcase1_1_path)); + check_windows_symlink!(symlink_dir( + testcase1_path.clone(), + symlink_testcase1_2_path + )); + check_windows_symlink!(symlink_dir(testcase2_path.clone(), symlink_testcase2_path)); + } + + let config_path = root_path.join("rome.json"); + let mut config_file = File::create(config_path).unwrap(); + config_file + .write_all(CONFIG_IGNORE_SYMLINK.as_bytes()) + .unwrap(); + + let files: [PathBuf; 4] = [ + testcase1_sub_path.join("test.js"), // ok + testcase2_path.join("test.js"), // ok + testcase2_path.join("test1.ts"), // ignored + testcase2_path.join("test2.ts"), // ignored + ]; + + for file_path in files { + let mut file = File::create(file_path).unwrap(); + file.write_all(APPLY_SUGGESTED_BEFORE.as_bytes()).unwrap(); + } + + let result = run_cli( + DynRef::Owned(Box::new(OsFileSystem)), + &mut console, + Arguments::from_vec(vec![ + OsString::from("check"), + OsString::from("--config-path"), + OsString::from(root_path.clone()), + OsString::from("--apply"), + OsString::from(src_path), + ]), + ); + + remove_dir_all(root_path).unwrap(); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "fs_files_ignore_symlink", + fs, + console, + result, + )); +} + #[test] fn file_too_large() { let mut fs = MemoryFileSystem::default(); diff --git a/crates/rome_cli/tests/configs.rs b/crates/rome_cli/tests/configs.rs index e98dee64664..2bfc6981beb 100644 --- a/crates/rome_cli/tests/configs.rs +++ b/crates/rome_cli/tests/configs.rs @@ -251,3 +251,11 @@ pub const CONFIG_FILE_SIZE_LIMIT: &str = r#"{ "maxSize": 16 } }"#; + +pub const CONFIG_IGNORE_SYMLINK: &str = r#"{ + "files": { + "ignore": [ + "symlink_testcase2/**/*.ts" + ] + } +}"#; diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/fs_files_ignore_symlink.snap b/crates/rome_cli/tests/snapshots/main_commands_check/fs_files_ignore_symlink.snap new file mode 100644 index 00000000000..84e7f82e0a6 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/fs_files_ignore_symlink.snap @@ -0,0 +1,18 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +assertion_line: 346 +expression: content +--- +# Emitted Messages + +```block +Skipped 4 suggested fixes. +If you wish to apply the suggested (unsafe) fixes, use the command rome check --apply-unsafe + +``` + +```block +Fixed 2 file(s) in