Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"no-debugger": "error"
},
"ignorePatterns": [
"**/*.ts"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
debugger;

33 changes: 17 additions & 16 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::linter::{
isolated_lint_handler::{IsolatedLintHandler, IsolatedLintHandlerOptions},
};
use crate::options::UnusedDisableDirectives;
use crate::{ConcurrentHashMap, Options};
use crate::{ConcurrentHashMap, OXC_CONFIG_FILE, Options};

use super::config_walker::ConfigWalker;

Expand All @@ -31,24 +31,20 @@ impl ServerLinter {
pub fn new(root_uri: &Uri, options: &Options) -> Self {
let root_path = root_uri.to_file_path().unwrap();
let (nested_configs, mut extended_paths) = Self::create_nested_configs(&root_path, options);
let relative_config_path = options.config_path.clone();
let oxlintrc = if let Some(relative_config_path) = relative_config_path {
let config = normalize_path(root_path.join(relative_config_path));
if config.try_exists().is_ok_and(|exists| exists) {
if let Ok(oxlintrc) = Oxlintrc::from_file(&config) {
oxlintrc
} else {
warn!("Failed to initialize oxlintrc config: {}", config.to_string_lossy());
Oxlintrc::default()
}
let config_path = options.config_path.as_ref().map_or(OXC_CONFIG_FILE, |v| v);
let config = normalize_path(root_path.join(config_path));
let oxlintrc = if config.try_exists().is_ok_and(|exists| exists) {
if let Ok(oxlintrc) = Oxlintrc::from_file(&config) {
oxlintrc
} else {
warn!(
"Config file not found: {}, fallback to default config",
config.to_string_lossy()
);
warn!("Failed to initialize oxlintrc config: {}", config.to_string_lossy());
Oxlintrc::default()
}
} else {
warn!(
"Config file not found: {}, fallback to default config",
config.to_string_lossy()
);
Oxlintrc::default()
};

Expand Down Expand Up @@ -378,7 +374,12 @@ mod test {
..Default::default()
}),
)
// ToDo: this should be fixable
.test_and_snapshot_single_file("test.js");
}

#[test]
fn test_root_ignore_patterns() {
Tester::new("fixtures/linter/root_ignore_patterns", None)
.test_and_snapshot_single_file("ignored-file.ts");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/root_ignore_patterns/ignored-file.ts
---
File is ignored
20 changes: 10 additions & 10 deletions crates/oxc_language_server/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ impl Tester<'_> {
#[expect(clippy::disallowed_methods)]
pub fn test_and_snapshot_single_file(&self, relative_file_path: &str) {
let uri = get_file_uri(&format!("{}/{}", self.relative_root_dir, relative_file_path));
let reports = tokio::runtime::Runtime::new().unwrap().block_on(async {
self.create_workspace_worker()
.await
.lint_file(&uri, None)
.await
.expect("lint file is ignored")
});
let snapshot = if reports.is_empty() {
"No diagnostic reports".to_string()
let reports = tokio::runtime::Runtime::new()
.unwrap()
.block_on(async { self.create_workspace_worker().await.lint_file(&uri, None).await });
let snapshot = if let Some(reports) = reports {
if reports.is_empty() {
"No diagnostic reports".to_string()
} else {
reports.iter().map(get_snapshot_from_report).collect::<Vec<_>>().join("\n")
}
} else {
reports.iter().map(get_snapshot_from_report).collect::<Vec<_>>().join("\n")
"File is ignored".to_string()
};

let snapshot_name = self.relative_root_dir.replace('/', "_");
Expand Down
Loading