@@ -40,11 +40,48 @@ use crate::{directives, fs, Locator};
40
40
pub struct LinterResult {
41
41
/// A collection of diagnostic messages generated by the linter.
42
42
pub messages : Vec < Message > ,
43
- /// A flag indicating the presence of syntax errors in the source file.
44
- /// If `true`, at least one syntax error was detected in the source file.
43
+ /// Flag indicating that the parsed source code does not contain any
44
+ /// [`ParseError`]s
45
+ has_valid_syntax : bool ,
46
+ /// Flag indicating that the parsed source code does not contain any
47
+ /// [`UnsupportedSyntaxError`]s
48
+ has_no_unsupported_syntax_errors : bool ,
49
+ }
50
+
51
+ impl LinterResult {
52
+ /// Returns `true` if the parsed source code contains any [`ParseError`]s *or*
53
+ /// [`UnsupportedSyntaxError`]s.
54
+ ///
55
+ /// See [`LinterResult::has_invalid_syntax`] for a version specific to [`ParseError`]s.
56
+ pub fn has_syntax_errors ( & self ) -> bool {
57
+ !self . has_no_syntax_errors ( )
58
+ }
59
+
60
+ /// Returns `true` if the parsed source code does not contain any [`ParseError`]s *or*
61
+ /// [`UnsupportedSyntaxError`]s.
62
+ ///
63
+ /// See [`LinterResult::has_valid_syntax`] for a version specific to [`ParseError`]s.
64
+ pub fn has_no_syntax_errors ( & self ) -> bool {
65
+ self . has_valid_syntax ( ) && self . has_no_unsupported_syntax_errors
66
+ }
67
+
68
+ /// Returns `true` if the parsed source code is valid i.e., it has no [`ParseError`]s.
45
69
///
46
- /// This includes both [`ParseError`]s and [`UnsupportedSyntaxError`]s.
47
- pub has_syntax_error : bool ,
70
+ /// Note that this does not include version-related [`UnsupportedSyntaxError`]s.
71
+ ///
72
+ /// See [`LinterResult::has_no_syntax_errors`] for a version that takes these into account.
73
+ pub fn has_valid_syntax ( & self ) -> bool {
74
+ self . has_valid_syntax
75
+ }
76
+
77
+ /// Returns `true` if the parsed source code is invalid i.e., it has [`ParseError`]s.
78
+ ///
79
+ /// Note that this does not include version-related [`UnsupportedSyntaxError`]s.
80
+ ///
81
+ /// See [`LinterResult::has_no_syntax_errors`] for a version that takes these into account.
82
+ pub fn has_invalid_syntax ( & self ) -> bool {
83
+ !self . has_valid_syntax ( )
84
+ }
48
85
}
49
86
50
87
pub type FixTable = FxHashMap < Rule , usize > ;
@@ -446,7 +483,8 @@ pub fn lint_only(
446
483
447
484
LinterResult {
448
485
messages,
449
- has_syntax_error : parsed. has_syntax_errors ( ) ,
486
+ has_valid_syntax : parsed. has_valid_syntax ( ) ,
487
+ has_no_unsupported_syntax_errors : parsed. unsupported_syntax_errors ( ) . is_empty ( ) ,
450
488
}
451
489
}
452
490
@@ -503,8 +541,11 @@ pub fn lint_fix<'a>(
503
541
// As an escape hatch, bail after 100 iterations.
504
542
let mut iterations = 0 ;
505
543
506
- // Track whether the _initial_ source code is valid syntax.
507
- let mut is_valid_syntax = false ;
544
+ // Track whether the _initial_ source code has valid syntax.
545
+ let mut has_valid_syntax = false ;
546
+
547
+ // Track whether the _initial_ source code has no unsupported syntax errors.
548
+ let mut has_no_unsupported_syntax_errors = false ;
508
549
509
550
let target_version = settings. resolve_target_version ( path) ;
510
551
@@ -547,12 +588,13 @@ pub fn lint_fix<'a>(
547
588
) ;
548
589
549
590
if iterations == 0 {
550
- is_valid_syntax = parsed. has_no_syntax_errors ( ) ;
591
+ has_valid_syntax = parsed. has_valid_syntax ( ) ;
592
+ has_no_unsupported_syntax_errors = parsed. unsupported_syntax_errors ( ) . is_empty ( ) ;
551
593
} else {
552
- // If the source code was parseable on the first pass, but is no
553
- // longer parseable on a subsequent pass, then we've introduced a
594
+ // If the source code had no syntax errors on the first pass, but
595
+ // does on a subsequent pass, then we've introduced a
554
596
// syntax error. Return the original code.
555
- if is_valid_syntax {
597
+ if has_valid_syntax && has_no_unsupported_syntax_errors {
556
598
if let Some ( error) = parsed. errors ( ) . first ( ) {
557
599
report_fix_syntax_error (
558
600
path,
@@ -593,7 +635,8 @@ pub fn lint_fix<'a>(
593
635
return Ok ( FixerResult {
594
636
result : LinterResult {
595
637
messages,
596
- has_syntax_error : !is_valid_syntax,
638
+ has_valid_syntax,
639
+ has_no_unsupported_syntax_errors,
597
640
} ,
598
641
transformed,
599
642
fixed,
0 commit comments