diff --git a/crates/oxc_language_server/fixtures/linter/init_nested_configs/.oxlintrc.json b/crates/oxc_language_server/fixtures/linter/init_nested_configs/.oxlintrc.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/crates/oxc_language_server/fixtures/linter/init_nested_configs/.oxlintrc.json @@ -0,0 +1 @@ +{} diff --git a/crates/oxc_language_server/fixtures/linter/init_nested_configs/deep1/.oxlintrc.json b/crates/oxc_language_server/fixtures/linter/init_nested_configs/deep1/.oxlintrc.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/crates/oxc_language_server/fixtures/linter/init_nested_configs/deep1/.oxlintrc.json @@ -0,0 +1 @@ +{} diff --git a/crates/oxc_language_server/fixtures/linter/init_nested_configs/deep1/deep2/.oxlintrc.json b/crates/oxc_language_server/fixtures/linter/init_nested_configs/deep1/deep2/.oxlintrc.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/crates/oxc_language_server/fixtures/linter/init_nested_configs/deep1/deep2/.oxlintrc.json @@ -0,0 +1 @@ +{} diff --git a/crates/oxc_language_server/src/linter/mod.rs b/crates/oxc_language_server/src/linter/mod.rs index 6c8edc9a212f0..4ef4ad8ba93d8 100644 --- a/crates/oxc_language_server/src/linter/mod.rs +++ b/crates/oxc_language_server/src/linter/mod.rs @@ -4,4 +4,4 @@ pub mod isolated_lint_handler; pub mod server_linter; #[cfg(test)] -mod tester; +pub mod tester; diff --git a/crates/oxc_language_server/src/worker.rs b/crates/oxc_language_server/src/worker.rs index 54d2fbb2a91bf..3f8852ce69e74 100644 --- a/crates/oxc_language_server/src/worker.rs +++ b/crates/oxc_language_server/src/worker.rs @@ -459,6 +459,8 @@ fn range_overlaps(a: Range, b: Range) -> bool { #[cfg(test)] mod tests { + use crate::linter::tester::get_file_uri; + use super::*; #[test] @@ -487,4 +489,34 @@ mod tests { .is_responsible_for_uri(&Uri::from_str("file:///path/to/other/file.js").unwrap()) ); } + + #[test] + fn test_init_nested_configs_with_disabled_nested_configs() { + let mut flags = FxHashMap::default(); + flags.insert("disable_nested_configs".to_string(), "true".to_string()); + + let configs = WorkspaceWorker::init_nested_configs( + &Uri::from_str("file:///root/").unwrap(), + &Options { flags, ..Options::default() }, + ); + + assert!(configs.is_empty()); + } + + #[test] + fn test_init_nested_configs() { + let configs = WorkspaceWorker::init_nested_configs( + &get_file_uri("fixtures/linter/init_nested_configs"), + &Options::default(), + ); + let configs = configs.pin(); + let mut configs_dirs = configs.keys().collect::>(); + // sorting the key because for consistent tests results + configs_dirs.sort(); + + assert!(configs_dirs.len() == 3); + assert!(configs_dirs[2].ends_with("deep2")); + assert!(configs_dirs[1].ends_with("deep1")); + assert!(configs_dirs[0].ends_with("init_nested_configs")); + } }