Skip to content

Commit 4e40a3f

Browse files
committed
feat(check): reject --fix --no-lint when typeCheck is enabled
1 parent 7338259 commit 4e40a3f

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

  • packages/cli/binding/src/check

packages/cli/binding/src/check/mod.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use vite_task::ExitStatus;
1010

1111
use self::analysis::{
1212
LintMessageKind, analyze_fmt_check_output, analyze_lint_output, format_count, format_elapsed,
13-
print_error_block, print_pass_line, print_stdout_block, print_summary_line,
13+
lint_config_type_check_enabled, print_error_block, print_pass_line, print_stdout_block,
14+
print_summary_line,
1415
};
1516
use crate::cli::{
1617
CapturedCommandOutput, SubcommandResolver, SynthesizableSubcommand, resolve_and_capture_output,
@@ -22,7 +23,7 @@ pub(crate) async fn execute_check(
2223
fix: bool,
2324
no_fmt: bool,
2425
no_lint: bool,
25-
_no_type_check: bool,
26+
no_type_check: bool,
2627
no_error_on_unmatched_pattern: bool,
2728
paths: Vec<String>,
2829
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
@@ -47,6 +48,31 @@ pub(crate) async fn execute_check(
4748
let mut deferred_lint_pass: Option<(String, String)> = None;
4849
let resolved_vite_config = resolver.resolve_universal_vite_config().await?;
4950

51+
// Per-phase enabled booleans derived from the raw flags plus the resolved
52+
// config's `typeCheck` setting. Currently only the guard immediately below
53+
// reads these; the fmt/lint phase conditions further down still consult the
54+
// raw `no_fmt`/`no_lint` flags.
55+
let config_type_check_enabled =
56+
lint_config_type_check_enabled(resolved_vite_config.lint.as_ref());
57+
let type_check_enabled = !no_type_check && config_type_check_enabled;
58+
let lint_enabled = !no_lint;
59+
60+
// Reject `--fix --no-lint` when the project enables type-check. With lint
61+
// rules skipped, oxlint would take the type-check-only path which it
62+
// itself refuses to combine with `--fix`. Running fmt first and then
63+
// hitting that rejection would leave the working tree partially formatted
64+
// (a real hazard inside lint-staged). Failing up-front keeps the
65+
// invocation transactional.
66+
if fix && !lint_enabled && type_check_enabled {
67+
output::error(
68+
"`vp check --fix --no-lint` cannot be combined with type-check enabled in config",
69+
);
70+
print_summary_line(
71+
"type-check diagnostics are read-only and cannot be auto-fixed. Add `--no-type-check` to format-only fix, or drop `--no-lint` to run lint fixes.",
72+
);
73+
return Ok(ExitStatus(1));
74+
}
75+
5076
if !no_fmt {
5177
let mut args = if fix { vec![] } else { vec!["--check".to_string()] };
5278
if suppress_unmatched {

0 commit comments

Comments
 (0)