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
10 changes: 5 additions & 5 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,7 @@ mod test {
#[test]
fn test_cross_module_no_cycle_nested_config() {
Tester::new("fixtures/linter/cross_module_nested_config", None)
.test_and_snapshot_single_file("dep-a.ts");
Tester::new("fixtures/linter/cross_module_nested_config", None)
.test_and_snapshot_single_file("folder/folder-dep-a.ts");
.test_and_snapshot_multiple_file(&["dep-a.ts", "folder/folder-dep-a.ts"]);
}

#[test]
Expand Down Expand Up @@ -603,8 +601,10 @@ mod test {
#[test]
fn test_root_ignore_patterns() {
let tester = Tester::new("fixtures/linter/ignore_patterns", None);
tester.test_and_snapshot_single_file("ignored-file.ts");
tester.test_and_snapshot_single_file("another_config/not-ignored-file.ts");
tester.test_and_snapshot_multiple_file(&[
"ignored-file.ts",
"another_config/not-ignored-file.ts",
]);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/astro/debugger.astro
---
##########
file: fixtures/linter/astro/debugger.astro
----------

code: "eslint(no-debugger)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html"
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/cross_module/debugger.ts
---
##########
file: fixtures/linter/cross_module/debugger.ts
----------

code: "eslint(no-debugger)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html"
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/cross_module/dep-a.ts
---
##########
file: fixtures/linter/cross_module/dep-a.ts
----------

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: These paths form a cycle: \n-> ./dep-b.ts - fixtures/linter/cross_module/dep-b.ts\n-> ./dep-a.ts - fixtures/linter/cross_module/dep-a.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/cross_module_extended_config/dep-a.ts
---
##########
file: fixtures/linter/cross_module_extended_config/dep-a.ts
----------

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: These paths form a cycle: \n-> ./dep-b.ts - fixtures/linter/cross_module_extended_config/dep-b.ts\n-> ./dep-a.ts - fixtures/linter/cross_module_extended_config/dep-a.ts"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/cross_module_nested_config/folder/folder-dep-a.ts
---
##########
file: fixtures/linter/cross_module_nested_config/dep-a.ts
----------
No diagnostic reports
##########
file: fixtures/linter/cross_module_nested_config/folder/folder-dep-a.ts
----------

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: These paths form a cycle: \n-> ./folder-dep-b.ts - fixtures/linter/cross_module_nested_config/folder/folder-dep-b.ts\n-> ./folder-dep-a.ts - fixtures/linter/cross_module_nested_config/folder/folder-dep-a.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/deny_no_console/hello_world.js
---
##########
file: fixtures/linter/deny_no_console/hello_world.js
----------

code: "eslint(no-console)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html"
message: "Unexpected console statement.\nhelp: Delete this console statement."
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/ignore_patterns/another_config/not-ignored-file.ts
---
##########
file: fixtures/linter/ignore_patterns/ignored-file.ts
----------
File is ignored
##########
file: fixtures/linter/ignore_patterns/another_config/not-ignored-file.ts
----------

code: "eslint(no-debugger)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html"
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/invalid_syntax/debugger.ts
---
##########
file: fixtures/linter/invalid_syntax/debugger.ts
----------

code: ""
code_description.href: "None"
message: "Unexpected token"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/issue_9958/issue.ts
---
##########
file: fixtures/linter/issue_9958/issue.ts
----------

code: "eslint(no-extra-boolean-cast)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-extra-boolean-cast.html"
message: "Redundant double negation\nhelp: Remove the double negation as it will already be coerced to a boolean"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_save/on-save.ts
---
##########
file: fixtures/linter/lint_on_run/on_save/on-save.ts
----------

code: "typescript-eslint(no-floating-promises)"
code_description.href: "None"
message: "Promises must be awaited.\nhelp: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_save/on-type.ts
---
##########
file: fixtures/linter/lint_on_run/on_save/on-type.ts
----------
File is ignored
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts
---
##########
file: fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts
----------
File is ignored
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save.ts
---
##########
file: fixtures/linter/lint_on_run/on_type/on-save.ts
----------

code: "eslint(no-debugger)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html"
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-type.ts
---
##########
file: fixtures/linter/lint_on_run/on_type/on-type.ts
----------

code: "eslint(no-debugger)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html"
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/multiple_suggestions/forward_ref.ts
---
##########
file: fixtures/linter/multiple_suggestions/forward_ref.ts
----------

code: "eslint-plugin-react(forward-ref-uses-ref)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/react/forward-ref-uses-ref.html"
message: "Components wrapped with `forwardRef` must have a `ref` parameter\nhelp: Add a `ref` parameter, or remove `forwardRef`"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/no_errors/hello_world.js
---
##########
file: fixtures/linter/no_errors/hello_world.js
----------
No diagnostic reports
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/regexp_feature/index.ts
---
##########
file: fixtures/linter/regexp_feature/index.ts
----------

code: "eslint(no-control-regex)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-control-regex.html"
message: "Unexpected control character\nhelp: '\\u0000' is a control character."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/svelte/debugger.svelte
---
##########
file: fixtures/linter/svelte/debugger.svelte
----------

code: "eslint(no-unassigned-vars)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unassigned-vars.html"
message: "'title' is always 'undefined' because it's never assigned.\nhelp: Variable declared without assignment. Either assign a value or remove the declaration."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/ts_path_alias/deep/src/dep-a.ts
---
##########
file: fixtures/linter/ts_path_alias/deep/src/dep-a.ts
----------

code: "eslint-plugin-import(no-cycle)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html"
message: "Dependency cycle detected\nhelp: These paths form a cycle: \n-> @/dep-b - fixtures/linter/ts_path_alias/deep/src/dep-b.ts\n-> ./dep-a.ts - fixtures/linter/ts_path_alias/deep/src/dep-a.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/tsgolint/no-floating-promises/index.ts
---
##########
file: fixtures/linter/tsgolint/no-floating-promises/index.ts
----------

code: "typescript-eslint(no-floating-promises)"
code_description.href: "None"
message: "Promises must be awaited.\nhelp: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/unused_disabled_directives/test.js
---
##########
file: fixtures/linter/unused_disabled_directives/test.js
----------

code: "eslint(no-console)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html"
message: "Unexpected console statement.\nhelp: Delete this console statement."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
source: crates/oxc_language_server/src/tester.rs
input_file: crates/oxc_language_server/fixtures/linter/vue/debugger.vue
---
##########
file: fixtures/linter/vue/debugger.vue
----------

code: "eslint(no-debugger)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html"
message: "`debugger` statement is not allowed\nhelp: Remove the debugger statement"
Expand Down
78 changes: 50 additions & 28 deletions crates/oxc_language_server/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,68 @@ impl Tester<'_> {
);
}

#[expect(clippy::disallowed_methods)]
pub fn test_and_snapshot_multiple_file(&self, relative_file_paths: &[&str]) {
self.test_and_snapshot_multiple_file_with_run_type(
relative_file_paths,
self.options.as_ref().map_or(Run::default(), |o| o.run),
);
}

pub fn test_and_snapshot_single_file_with_run_type(
&self,
relative_file_path: &str,
run_type: Run,
) {
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,
match run_type {
Run::OnSave => ServerLinterRun::OnSave,
Run::OnType => ServerLinterRun::OnType,
},
)
.await
});
let snapshot = if let Some(reports) = reports {
if reports.is_empty() {
"No diagnostic reports".to_string()
self.test_and_snapshot_multiple_file_with_run_type(&[relative_file_path], run_type);
}

#[expect(clippy::disallowed_methods)]
pub fn test_and_snapshot_multiple_file_with_run_type(
&self,
relative_file_paths: &[&str],
run_type: Run,
) {
let mut snapshot_result = String::new();
for relative_file_path in relative_file_paths {
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,
match run_type {
Run::OnSave => ServerLinterRun::OnSave,
Run::OnType => ServerLinterRun::OnType,
},
)
.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")
}
} else {
"File is ignored".to_string()
};
"File is ignored".to_string()
};

let _ = write!(
snapshot_result,
"########## \nfile: {}/{relative_file_path}\n----------\n{snapshot}\n",
self.relative_root_dir
);
}

let snapshot_name = self.relative_root_dir.replace('/', "_");
let mut settings = insta::Settings::clone_current();
settings.set_prepend_module_to_snapshot(false);
settings.set_omit_expression(true);
if let Some(path) = uri.to_file_path() {
settings.set_input_file(path.as_ref());
}
settings.set_snapshot_suffix(relative_file_path.replace('/', "_"));
settings.set_snapshot_suffix(relative_file_paths.join("_").replace('\\', "/"));
settings.bind(|| {
insta::assert_snapshot!(snapshot_name, snapshot);
insta::assert_snapshot!(snapshot_name, snapshot_result);
});
}
}
Loading