@@ -430,96 +430,95 @@ pub fn check(args: CheckCommand, global_options: GlobalConfigArgs) -> Result<Exi
430430 ) ?;
431431 printer. write_continuously ( & mut writer, & diagnostics, preview, prefer_rule_codes) ?;
432432 }
433+ }
434+ // Generate lint violations.
435+ let diagnostics = if is_stdin {
436+ commands:: check_stdin:: check_stdin (
437+ cli. stdin_filename . map ( fs:: normalize_path) . as_deref ( ) ,
438+ & pyproject_config,
439+ & config_arguments,
440+ noqa. into ( ) ,
441+ fix_mode,
442+ ) ?
433443 } else {
434- // Generate lint violations.
435- let diagnostics = if is_stdin {
436- commands:: check_stdin:: check_stdin (
437- cli. stdin_filename . map ( fs:: normalize_path) . as_deref ( ) ,
438- & pyproject_config,
439- & config_arguments,
440- noqa. into ( ) ,
441- fix_mode,
442- ) ?
443- } else {
444- commands:: check:: check (
445- & files,
446- & pyproject_config,
447- & config_arguments,
448- cache. into ( ) ,
449- noqa. into ( ) ,
450- fix_mode,
451- unsafe_fixes,
452- ) ?
453- } ;
454-
455- // Always try to print violations (though the printer itself may suppress output)
456- // If we're writing fixes via stdin, the transformed source code goes to the writer
457- // so send the summary to stderr instead
458- let mut summary_writer = if is_stdin && matches ! ( fix_mode, FixMode :: Apply | FixMode :: Diff ) {
459- stderr_writer
460- } else {
461- writer
462- } ;
463- if cli. statistics {
464- printer. write_statistics ( & diagnostics, & mut summary_writer) ?;
465- } else {
466- printer. write_once (
467- & diagnostics,
468- & mut summary_writer,
469- preview,
470- prefer_rule_codes,
471- ) ?;
472- }
444+ commands:: check:: check (
445+ & files,
446+ & pyproject_config,
447+ & config_arguments,
448+ cache. into ( ) ,
449+ noqa. into ( ) ,
450+ fix_mode,
451+ unsafe_fixes,
452+ ) ?
453+ } ;
454+
455+ // Always try to print violations (though the printer itself may suppress output)
456+ // If we're writing fixes via stdin, the transformed source code goes to the writer
457+ // so send the summary to stderr instead
458+ let mut summary_writer = if is_stdin && matches ! ( fix_mode, FixMode :: Apply | FixMode :: Diff ) {
459+ stderr_writer
460+ } else {
461+ writer
462+ } ;
463+ if cli. statistics {
464+ printer. write_statistics ( & diagnostics, & mut summary_writer) ?;
465+ } else {
466+ printer. write_once (
467+ & diagnostics,
468+ & mut summary_writer,
469+ preview,
470+ prefer_rule_codes,
471+ ) ?;
472+ }
473473
474- if !cli. exit_zero {
475- let max_severity = diagnostics
476- . inner
477- . iter ( )
478- . map ( Diagnostic :: severity)
479- . max ( )
480- . unwrap_or ( Severity :: Info ) ;
481- if max_severity. is_fatal ( ) {
482- // When a panic/fatal error is reported, prompt the user to open an issue on github.
483- // Diagnostics with severity `fatal` will be sorted to the bottom, and printing the
484- // message here instead of attaching it to the diagnostic ensures that we only print
485- // it once instead of repeating it for each diagnostic. Prints to stderr to prevent
486- // the message from being captured by tools parsing the normal output.
487- let message = "Panic during linting indicates a bug in Ruff. If you could open an issue at:
474+ if !cli. exit_zero {
475+ let max_severity = diagnostics
476+ . inner
477+ . iter ( )
478+ . map ( Diagnostic :: severity)
479+ . max ( )
480+ . unwrap_or ( Severity :: Info ) ;
481+ if max_severity. is_fatal ( ) {
482+ // When a panic/fatal error is reported, prompt the user to open an issue on github.
483+ // Diagnostics with severity `fatal` will be sorted to the bottom, and printing the
484+ // message here instead of attaching it to the diagnostic ensures that we only print
485+ // it once instead of repeating it for each diagnostic. Prints to stderr to prevent
486+ // the message from being captured by tools parsing the normal output.
487+ let message = "Panic during linting indicates a bug in Ruff. If you could open an issue at:
488488
489489https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D
490490
491491...with the relevant file contents, the `pyproject.toml` settings, and the stack trace above, we'd be very appreciative!
492492" ;
493- error ! ( "{message}" ) ;
494- return Ok ( ExitStatus :: Error ) ;
493+ error ! ( "{message}" ) ;
494+ return Ok ( ExitStatus :: Error ) ;
495+ }
496+ if cli. diff {
497+ // If we're printing a diff, we always want to exit non-zero if there are
498+ // any fixable violations (since we've printed the diff, but not applied the
499+ // fixes).
500+ if !diagnostics. fixed . is_empty ( ) {
501+ return Ok ( ExitStatus :: Failure ) ;
495502 }
496- if cli . diff {
497- // If we're printing a diff , we always want to exit non- zero if there are
498- // any fixable violations (since we've printed the diff, but not applied the
499- // fixes).
503+ } else if fix_only {
504+ // If we're only fixing , we want to exit zero (since we've fixed all fixable
505+ // violations), unless we're explicitly asked to exit non-zero on fix.
506+ if cli . exit_non_zero_on_fix {
500507 if !diagnostics. fixed . is_empty ( ) {
501508 return Ok ( ExitStatus :: Failure ) ;
502509 }
503- } else if fix_only {
504- // If we're only fixing, we want to exit zero (since we've fixed all fixable
505- // violations), unless we're explicitly asked to exit non-zero on fix.
506- if cli. exit_non_zero_on_fix {
507- if !diagnostics. fixed . is_empty ( ) {
508- return Ok ( ExitStatus :: Failure ) ;
509- }
510+ }
511+ } else {
512+ // If we're running the linter (not just fixing), we want to exit non-zero if
513+ // there are any violations, unless we're explicitly asked to exit zero on
514+ // fix.
515+ if cli. exit_non_zero_on_fix {
516+ if !diagnostics. fixed . is_empty ( ) || !diagnostics. inner . is_empty ( ) {
517+ return Ok ( ExitStatus :: Failure ) ;
510518 }
511519 } else {
512- // If we're running the linter (not just fixing), we want to exit non-zero if
513- // there are any violations, unless we're explicitly asked to exit zero on
514- // fix.
515- if cli. exit_non_zero_on_fix {
516- if !diagnostics. fixed . is_empty ( ) || !diagnostics. inner . is_empty ( ) {
517- return Ok ( ExitStatus :: Failure ) ;
518- }
519- } else {
520- if !diagnostics. inner . is_empty ( ) {
521- return Ok ( ExitStatus :: Failure ) ;
522- }
520+ if !diagnostics. inner . is_empty ( ) {
521+ return Ok ( ExitStatus :: Failure ) ;
523522 }
524523 }
525524 }
0 commit comments