Skip to content

Commit 7f3d735

Browse files
committed
fix(linter): error when --type-check is used without --type-aware (#20025)
fixes #20024
1 parent 9c9dc8d commit 7f3d735

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

apps/oxlint/src/lint.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ impl CliRunner {
341341
let config_store = ConfigStore::new(lint_config, nested_configs, external_plugin_store);
342342
let type_aware = self.options.type_aware || config_store.type_aware_enabled();
343343
let type_check = self.options.type_check || config_store.type_check_enabled();
344+
if type_check && !type_aware {
345+
print_and_flush_stdout(
346+
stdout,
347+
"The `--type-check` option requires type-aware linting.\nUse `--type-aware --type-check` or enable `options.typeAware` in your config.\n",
348+
);
349+
return CliRunResult::InvalidOptionTypeCheckWithoutTypeAware;
350+
}
344351
let deny_warnings = warning_options.deny_warnings || config_store.deny_warnings();
345352
let max_warnings = warning_options.max_warnings.or(config_store.max_warnings());
346353

@@ -1332,6 +1339,13 @@ mod test {
13321339
Tester::new().with_cwd("fixtures/tsgolint_type_error".into()).test_and_snapshot(args);
13331340
}
13341341

1342+
#[test]
1343+
#[cfg(not(target_endian = "big"))]
1344+
fn test_tsgolint_type_check_requires_type_aware() {
1345+
let args = &["--type-check"];
1346+
Tester::new().with_cwd("fixtures/tsgolint_type_error".into()).test_and_snapshot(args);
1347+
}
1348+
13351349
#[test]
13361350
#[cfg(not(target_endian = "big"))]
13371351
fn test_tsgolint_type_check_via_config_file() {

apps/oxlint/src/result.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub enum CliRunResult {
66
JsPluginWorkspaceSetupFailed,
77
InvalidOptionConfig,
88
InvalidOptionTsConfig,
9+
InvalidOptionTypeCheckWithoutTypeAware,
910
InvalidOptionSeverityWithoutFilter,
1011
InvalidOptionSeverityWithoutPluginName,
1112
InvalidOptionSeverityWithoutRuleName,
@@ -36,6 +37,7 @@ impl Termination for CliRunResult {
3637
| Self::LintMaxWarningsExceeded
3738
| Self::InvalidOptionConfig
3839
| Self::InvalidOptionTsConfig
40+
| Self::InvalidOptionTypeCheckWithoutTypeAware
3941
| Self::InvalidOptionSeverityWithoutFilter
4042
| Self::InvalidOptionSeverityWithoutPluginName
4143
| Self::InvalidOptionSeverityWithoutRuleName
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --type-check
6+
working directory: fixtures/tsgolint_type_error
7+
----------
8+
The `--type-check` option requires type-aware linting.
9+
Use `--type-aware --type-check` or enable `options.typeAware` in your config.
10+
----------
11+
CLI result: InvalidOptionTypeCheckWithoutTypeAware
12+
----------

0 commit comments

Comments
 (0)