Skip to content

Commit 4a6bb21

Browse files
committed
test(language_server): add test for import plugin integration (#10364)
see comment #7118 (comment)
1 parent ba538ff commit 4a6bb21

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [
3+
"import"
4+
],
5+
"rules": {
6+
"import/no-cycle": "error"
7+
}
8+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Debugger should be shown as a warning
2+
debugger;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// should report cycle detected
2+
import { b } from './dep-b.ts';
3+
4+
b();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// this file is also included in dep-a.ts and dep-a.ts should report a no-cycle diagnostic
2+
import './dep-a.ts';
3+
4+
export function b() { /* ... */ }

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,37 @@ mod test {
9797
Tester::new().test_and_snapshot_single_file("fixtures/linter/vue/debugger.vue");
9898
Tester::new().test_and_snapshot_single_file("fixtures/linter/svelte/debugger.svelte");
9999
}
100+
101+
#[test]
102+
fn test_cross_module_debugger() {
103+
let config_store: oxc_linter::ConfigStore = ConfigStoreBuilder::from_oxlintrc(
104+
false,
105+
Oxlintrc::from_file(&PathBuf::from("fixtures/linter/cross_module/.oxlintrc.json"))
106+
.unwrap(),
107+
)
108+
.unwrap()
109+
.build()
110+
.unwrap();
111+
let linter = Linter::new(LintOptions::default(), config_store);
112+
113+
Tester::new_with_linter(linter)
114+
.test_and_snapshot_single_file("fixtures/linter/cross_module/debugger.ts");
115+
}
116+
117+
#[test]
118+
// ToDo: only available with runtime oxc-project/oxc#10268
119+
fn test_cross_module_no_cycle() {
120+
let config_store = ConfigStoreBuilder::from_oxlintrc(
121+
false,
122+
Oxlintrc::from_file(&PathBuf::from("fixtures/linter/cross_module/.oxlintrc.json"))
123+
.unwrap(),
124+
)
125+
.unwrap()
126+
.build()
127+
.unwrap();
128+
let linter = Linter::new(LintOptions::default(), config_store);
129+
130+
Tester::new_with_linter(linter)
131+
.test_and_snapshot_single_file("fixtures/linter/cross_module/dep-a.ts");
132+
}
100133
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/oxc_language_server/src/linter/tester.rs
3+
---
4+
code: "eslint(no-debugger)"
5+
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger"
6+
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
7+
range: Range { start: Position { line: 1, character: 0 }, end: Position { line: 1, character: 9 } }
8+
related_information[0].message: ""
9+
related_information[0].location.uri: "file://<variable>/fixtures/linter/cross_module/debugger.ts"
10+
related_information[0].location.range: Range { start: Position { line: 1, character: 0 }, end: Position { line: 1, character: 9 } }
11+
severity: Some(Warning)
12+
source: Some("oxc")
13+
tags: None
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
source: crates/oxc_language_server/src/linter/tester.rs
3+
---
4+
No diagnostic reports

0 commit comments

Comments
 (0)