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
39 changes: 39 additions & 0 deletions apps/oxlint/fixtures/tsgolint_disable_directives/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Test file for disable directives with type-aware rules
const myPromise = new Promise(() => {})

// Test oxlint-disable-next-line
// oxlint-disable-next-line typescript/no-floating-promises
myPromise

// Test eslint-disable-next-line with @typescript-eslint prefix
// eslint-disable-next-line @typescript-eslint/no-floating-promises
myPromise

// Test oxlint-disable/enable block
/* oxlint-disable typescript/no-floating-promises */
myPromise
myPromise
/* oxlint-enable typescript/no-floating-promises */

// This should still report an error (no disable directive)
myPromise

// Test with different rule name formats
// oxlint-disable-next-line no-floating-promises
myPromise

// eslint-disable-next-line typescript-eslint/no-floating-promises
myPromise

// Test disable-line variant
myPromise // oxlint-disable-line typescript/no-floating-promises

// Multiple promises in one block
/* eslint-disable @typescript-eslint/no-floating-promises */
Promise.resolve(1)
Promise.resolve(2)
Promise.resolve(3)
/* eslint-enable @typescript-eslint/no-floating-promises */

// Should report error
Promise.resolve(4)
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/tsgolint_disable_directives/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
24 changes: 24 additions & 0 deletions apps/oxlint/fixtures/tsgolint_disable_directives/unused.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Test unused disable directives with type-aware rules
const myPromise = new Promise(() => {})

// This disable directive is USED (suppresses the error below)
// oxlint-disable-next-line typescript/no-floating-promises
myPromise

// This disable directive is UNUSED (no error to suppress)
// oxlint-disable-next-line typescript/no-floating-promises
console.log("hello")

// This disable directive is UNUSED (wrong rule name)
// oxlint-disable-next-line typescript/no-unsafe-assignment
myPromise

// This disable directive is USED
/* eslint-disable @typescript-eslint/no-floating-promises */
myPromise
/* eslint-enable @typescript-eslint/no-floating-promises */

// This disable directive is UNUSED (no floating promise here)
/* eslint-disable @typescript-eslint/no-floating-promises */
const x = 1 + 2
/* eslint-enable @typescript-eslint/no-floating-promises */
33 changes: 30 additions & 3 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,18 @@ impl CliRunner {
None
};

if let Err(err) = lint_runner.lint_files(&files_to_lint, tx_error, file_system) {
print_and_flush_stdout(stdout, &err);
return CliRunResult::TsGoLintError;
match lint_runner.lint_files(&files_to_lint, tx_error.clone(), file_system) {
Ok(lint_runner) => {
lint_runner.report_unused_directives(report_unused_directives, &tx_error);
}
Err(err) => {
print_and_flush_stdout(stdout, &err);
return CliRunResult::TsGoLintError;
}
}

drop(tx_error);

let diagnostic_result = diagnostic_service.run(stdout);

if let Some(end) = output_formatter.lint_command_info(&LintCommandInfo {
Expand Down Expand Up @@ -1298,4 +1305,24 @@ mod test {
let args = &["--type-aware", "test.svelte"];
Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args);
}

#[cfg(not(target_endian = "big"))]
#[test]
fn test_tsgolint_unused_disable_directives() {
// Test that unused disable directives are reported with type-aware rules
let args = &["--type-aware", "--report-unused-disable-directives", "unused.ts"];
Tester::new()
.with_cwd("fixtures/tsgolint_disable_directives".into())
.test_and_snapshot(args);
}

#[cfg(not(target_endian = "big"))]
#[test]
fn test_tsgolint_disable_directives() {
// Test that disable directives work with type-aware rules
let args = &["--type-aware", "test.ts"];
Tester::new()
.with_cwd("fixtures/tsgolint_disable_directives".into())
.test_and_snapshot(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --type-aware --report-unused-disable-directives unused.ts
working directory: fixtures/tsgolint_disable_directives
----------

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[unused.ts:6:1]
5 | // oxlint-disable-next-line typescript/no-floating-promises
6 | myPromise
: ^^^^^^^^^
7 |
`----
help: Consider using this expression or removing it

! Unused eslint-disable directive (no problems were reported).
,-[unused.ts:9:3]
8 | // This disable directive is UNUSED (no error to suppress)
9 | // oxlint-disable-next-line typescript/no-floating-promises
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 | console.log("hello")
`----

! Unused eslint-disable directive (no problems were reported).
,-[unused.ts:13:3]
12 | // This disable directive is UNUSED (wrong rule name)
13 | // oxlint-disable-next-line typescript/no-unsafe-assignment
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 | myPromise
`----

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[unused.ts:14:1]
13 | // oxlint-disable-next-line typescript/no-unsafe-assignment
14 | myPromise
: ^^^^^^^^^
15 |
`----
help: Consider using this expression or removing it

! typescript-eslint(no-floating-promises): Promises must be awaited.
,-[unused.ts:14:1]
13 | // oxlint-disable-next-line typescript/no-unsafe-assignment
14 | myPromise
: ^^^^^^^^^
15 |
`----
help: 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.

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[unused.ts:18:1]
17 | /* eslint-disable @typescript-eslint/no-floating-promises */
18 | myPromise
: ^^^^^^^^^
19 | /* eslint-enable @typescript-eslint/no-floating-promises */
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Variable 'x' is declared but never used. Unused variables should start with a '_'.
,-[unused.ts:23:7]
22 | /* eslint-disable @typescript-eslint/no-floating-promises */
23 | const x = 1 + 2
: |
: `-- 'x' is declared here
24 | /* eslint-enable @typescript-eslint/no-floating-promises */
`----
help: Consider removing this declaration.

! Unused eslint-disable directive (no problems were reported).
,-[unused.ts:24:3]
23 | const x = 1 + 2
24 | /* eslint-enable @typescript-eslint/no-floating-promises */
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

Found 8 warnings and 0 errors.
Finished in <variable>ms on 1 file with 103 rules using 1 threads.
----------
CLI result: LintSucceeded
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --type-aware test.ts
working directory: fixtures/tsgolint_disable_directives
----------

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:6:1]
5 | // oxlint-disable-next-line typescript/no-floating-promises
6 | myPromise
: ^^^^^^^^^
7 |
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:10:1]
9 | // eslint-disable-next-line @typescript-eslint/no-floating-promises
10 | myPromise
: ^^^^^^^^^
11 |
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:14:1]
13 | /* oxlint-disable typescript/no-floating-promises */
14 | myPromise
: ^^^^^^^^^
15 | myPromise
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:15:1]
14 | myPromise
15 | myPromise
: ^^^^^^^^^
16 | /* oxlint-enable typescript/no-floating-promises */
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:19:1]
18 | // This should still report an error (no disable directive)
19 | myPromise
: ^^^^^^^^^
20 |
`----
help: Consider using this expression or removing it

! typescript-eslint(no-floating-promises): Promises must be awaited.
,-[test.ts:19:1]
18 | // This should still report an error (no disable directive)
19 | myPromise
: ^^^^^^^^^
20 |
`----
help: 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.

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:23:1]
22 | // oxlint-disable-next-line no-floating-promises
23 | myPromise
: ^^^^^^^^^
24 |
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:26:1]
25 | // eslint-disable-next-line typescript-eslint/no-floating-promises
26 | myPromise
: ^^^^^^^^^
27 |
`----
help: Consider using this expression or removing it

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html\eslint(no-unused-expressions)]8;;\: Expected expression to be used
,-[test.ts:29:1]
28 | // Test disable-line variant
29 | myPromise // oxlint-disable-line typescript/no-floating-promises
: ^^^^^^^^^
30 |
`----
help: Consider using this expression or removing it

! typescript-eslint(no-floating-promises): Promises must be awaited.
,-[test.ts:39:1]
38 | // Should report error
39 | Promise.resolve(4)
: ^^^^^^^^^^^^^^^^^^
`----
help: 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.

Found 10 warnings and 0 errors.
Finished in <variable>ms on 1 file with 103 rules using 1 threads.
----------
CLI result: LintSucceeded
----------
Loading
Loading