Skip to content
Open
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
9 changes: 9 additions & 0 deletions apps/oxlint/fixtures/tsgolint_type_error/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"categories": {
"correctness": "off"
},
"rules": {
"typescript/no-floating-promises": "error",
"no-debugger": "error"
}
}
2 changes: 2 additions & 0 deletions apps/oxlint/fixtures/tsgolint_type_error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
const foo = "42";
1 change: 1 addition & 0 deletions apps/oxlint/fixtures/tsgolint_type_error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo: number = "42";
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/tsgolint_type_error/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2016",
"lib": ["ES2024"],
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
12 changes: 12 additions & 0 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub struct LintCommand {
#[bpaf(switch, hide_usage)]
pub type_aware: bool,

/// Enable experimental type checking (includes TypeScript compiler diagnostics)
#[bpaf(switch, hide_usage)]
pub experimental_type_check: bool,

#[bpaf(external)]
pub inline_config_options: InlineConfigOptions,

Expand Down Expand Up @@ -618,6 +622,14 @@ mod lint_options {
let options = get_lint_options(".");
assert!(!options.type_aware);
}

#[test]
fn experimental_type_check() {
let options = get_lint_options("--experimental-type-check");
assert!(options.experimental_type_check);
let options = get_lint_options(".");
assert!(!options.experimental_type_check);
}
}

#[cfg(test)]
Expand Down
8 changes: 8 additions & 0 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ impl CliRunner {
// TODO: Add a warning message if `tsgolint` cannot be found, but type-aware rules are enabled
let lint_runner = match LintRunner::builder(options, linter)
.with_type_aware(self.options.type_aware)
.with_experimental_type_check(self.options.experimental_type_check)
.with_silent(misc_options.silent)
.with_fix_kind(fix_options.fix_kind())
.build()
Expand Down Expand Up @@ -1361,6 +1362,13 @@ mod test {
Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_tsgolint_type_error() {
let args = &["--type-aware", "--experimental-type-check"];
Tester::new().with_cwd("fixtures/tsgolint_type_error".into()).test_and_snapshot(args);
}

#[test]
#[cfg(not(target_endian = "big"))]
fn test_tsgolint_no_typescript_files() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --type-aware --experimental-type-check
working directory: fixtures/tsgolint_type_error
----------

x typescript(TS2322): Type 'string' is not assignable to type 'number'.
,-[index.ts:1:7]
1 | const foo: number = "42";
: ^^^
`----

Found 0 warnings and 1 error.
Finished in <variable>ms on 2 files using 1 threads.
----------
CLI result: LintFoundErrors
----------
12 changes: 12 additions & 0 deletions apps/oxlint/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --type-aware
working directory: fixtures/tsgolint_type_error
----------
Found 0 warnings and 0 errors.
Finished in <variable>ms on 2 files using 1 threads.
----------
CLI result: LintSucceeded
----------
14 changes: 13 additions & 1 deletion crates/oxc_linter/src/lint_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl Default for DirectivesStore {
pub struct LintRunnerBuilder {
regular_linter: Linter,
type_aware_enabled: bool,
experimental_type_check: bool,
lint_service_options: LintServiceOptions,
silent: bool,
fix_kind: FixKind,
Expand All @@ -136,6 +137,7 @@ impl LintRunnerBuilder {
Self {
regular_linter: linter,
type_aware_enabled: false,
experimental_type_check: false,
lint_service_options,
silent: false,
fix_kind: FixKind::None,
Expand All @@ -148,6 +150,12 @@ impl LintRunnerBuilder {
self
}

#[must_use]
pub fn with_experimental_type_check(mut self, enabled: bool) -> Self {
self.experimental_type_check = enabled;
self
}

#[must_use]
pub fn with_silent(mut self, silent: bool) -> Self {
self.silent = silent;
Expand All @@ -171,7 +179,11 @@ impl LintRunnerBuilder {
self.regular_linter.config.clone(),
self.fix_kind,
) {
Ok(state) => Some(state.with_silent(self.silent)),
Ok(state) => Some(
state
.with_silent(self.silent)
.with_experimental_type_check(self.experimental_type_check),
),
Err(e) => return Err(e),
}
} else {
Expand Down
17 changes: 17 additions & 0 deletions crates/oxc_linter/src/tsgolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct TsGoLintState {
fix: bool,
/// If `true`, request that suggestions be returned from `tsgolint`.
fix_suggestions: bool,
/// If `true`, include TypeScript compiler syntactic and semantic diagnostics.
experimental_type_check: bool,
}

impl TsGoLintState {
Expand All @@ -46,6 +48,7 @@ impl TsGoLintState {
silent: false,
fix: fix_kind.contains(FixKind::Fix),
fix_suggestions: fix_kind.contains(FixKind::Suggestion),
experimental_type_check: false,
}
}

Expand All @@ -67,6 +70,7 @@ impl TsGoLintState {
silent: false,
fix: fix_kind.contains(FixKind::Fix),
fix_suggestions: fix_kind.contains(FixKind::Suggestion),
experimental_type_check: false,
})
}

Expand All @@ -80,6 +84,15 @@ impl TsGoLintState {
self
}

/// Set to `true` to include TypeScript compiler syntactic and semantic diagnostics.
///
/// Default is `false`.
#[must_use]
pub fn with_experimental_type_check(mut self, yes: bool) -> Self {
self.experimental_type_check = yes;
self
}

/// # Panics
/// - when `stdin` of subprocess cannot be opened
/// - when `stdout` of subprocess cannot be opened
Expand Down Expand Up @@ -548,6 +561,8 @@ impl TsGoLintState {
})
.collect(),
source_overrides,
report_syntactic: self.experimental_type_check,
report_semantic: self.experimental_type_check,
}
}
}
Expand All @@ -573,6 +588,8 @@ pub struct Payload {
pub version: i32,
pub configs: Vec<Config>,
pub source_overrides: Option<FxHashMap<String, String>>,
pub report_syntactic: bool,
pub report_semantic: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions tasks/website/src/linter/snapshots/cli.snap
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Arguments:
Disable the automatic loading of nested configuration files
- **` --type-aware`** &mdash;
Enable rules that require type information
- **` --experimental-type-check`** &mdash;
Enable experimental type checking (includes TypeScript compiler diagnostics)
- **`-h`**, **`--help`** &mdash;
Prints help information
- **`-V`**, **`--version`** &mdash;
Expand Down
2 changes: 2 additions & 0 deletions tasks/website/src/linter/snapshots/cli_terminal.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,7 @@ Available options:
--lsp Start the language server
--disable-nested-config Disable the automatic loading of nested configuration files
--type-aware Enable rules that require type information
--experimental-type-check Enable experimental type checking (includes TypeScript compiler
diagnostics)
-h, --help Prints help information
-V, --version Prints version information
Loading