Skip to content

Commit c1ec1f7

Browse files
committed
fix(language_server): respect the root .oxlintrc.json file for ignorePatterns
1 parent 4c35f4a commit c1ec1f7

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rules": {
3+
"no-debugger": "error"
4+
},
5+
"ignorePatterns": [
6+
"**/*.ts"
7+
]
8+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
debugger;
2+

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::linter::{
1717
isolated_lint_handler::{IsolatedLintHandler, IsolatedLintHandlerOptions},
1818
};
1919
use crate::options::UnusedDisableDirectives;
20-
use crate::{ConcurrentHashMap, Options};
20+
use crate::{ConcurrentHashMap, OXC_CONFIG_FILE, Options};
2121

2222
use super::config_walker::ConfigWalker;
2323

@@ -31,24 +31,20 @@ impl ServerLinter {
3131
pub fn new(root_uri: &Uri, options: &Options) -> Self {
3232
let root_path = root_uri.to_file_path().unwrap();
3333
let (nested_configs, mut extended_paths) = Self::create_nested_configs(&root_path, options);
34-
let relative_config_path = options.config_path.clone();
35-
let oxlintrc = if let Some(relative_config_path) = relative_config_path {
36-
let config = normalize_path(root_path.join(relative_config_path));
37-
if config.try_exists().is_ok_and(|exists| exists) {
38-
if let Ok(oxlintrc) = Oxlintrc::from_file(&config) {
39-
oxlintrc
40-
} else {
41-
warn!("Failed to initialize oxlintrc config: {}", config.to_string_lossy());
42-
Oxlintrc::default()
43-
}
34+
let config_path = options.config_path.as_ref().map_or(OXC_CONFIG_FILE, |v| v);
35+
let config = normalize_path(root_path.join(config_path));
36+
let oxlintrc = if config.try_exists().is_ok_and(|exists| exists) {
37+
if let Ok(oxlintrc) = Oxlintrc::from_file(&config) {
38+
oxlintrc
4439
} else {
45-
warn!(
46-
"Config file not found: {}, fallback to default config",
47-
config.to_string_lossy()
48-
);
40+
warn!("Failed to initialize oxlintrc config: {}", config.to_string_lossy());
4941
Oxlintrc::default()
5042
}
5143
} else {
44+
warn!(
45+
"Config file not found: {}, fallback to default config",
46+
config.to_string_lossy()
47+
);
5248
Oxlintrc::default()
5349
};
5450

@@ -378,7 +374,12 @@ mod test {
378374
..Default::default()
379375
}),
380376
)
381-
// ToDo: this should be fixable
382377
.test_and_snapshot_single_file("test.js");
383378
}
379+
380+
#[test]
381+
fn test_root_ignore_patterns() {
382+
Tester::new("fixtures/linter/root_ignore_patterns", None)
383+
.test_and_snapshot_single_file("ignored-file.ts");
384+
}
384385
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/oxc_language_server/src/tester.rs
3+
input_file: crates/oxc_language_server/fixtures/linter/root_ignore_patterns/ignored-file.ts
4+
---
5+
File is ignored

crates/oxc_language_server/src/tester.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ impl Tester<'_> {
116116
#[expect(clippy::disallowed_methods)]
117117
pub fn test_and_snapshot_single_file(&self, relative_file_path: &str) {
118118
let uri = get_file_uri(&format!("{}/{}", self.relative_root_dir, relative_file_path));
119-
let reports = tokio::runtime::Runtime::new().unwrap().block_on(async {
120-
self.create_workspace_worker()
121-
.await
122-
.lint_file(&uri, None)
123-
.await
124-
.expect("lint file is ignored")
125-
});
126-
let snapshot = if reports.is_empty() {
127-
"No diagnostic reports".to_string()
119+
let reports = tokio::runtime::Runtime::new()
120+
.unwrap()
121+
.block_on(async { self.create_workspace_worker().await.lint_file(&uri, None).await });
122+
let snapshot = if let Some(reports) = reports {
123+
if reports.is_empty() {
124+
"No diagnostic reports".to_string()
125+
} else {
126+
reports.iter().map(get_snapshot_from_report).collect::<Vec<_>>().join("\n")
127+
}
128128
} else {
129-
reports.iter().map(get_snapshot_from_report).collect::<Vec<_>>().join("\n")
129+
"File is ignored".to_string()
130130
};
131131

132132
let snapshot_name = self.relative_root_dir.replace('/', "_");

0 commit comments

Comments
 (0)