File tree 4 files changed +30
-12
lines changed
4 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -727,15 +727,32 @@ fn stdin_format_jupyter() {
727
727
fn stdin_parse_error ( ) {
728
728
let mut cmd = RuffCheck :: default ( ) . build ( ) ;
729
729
assert_cmd_snapshot ! ( cmd
730
- . pass_stdin( "from foo import = \n " ) , @r###"
730
+ . pass_stdin( "from foo import\n " ) , @r###"
731
731
success: false
732
732
exit_code: 1
733
733
----- stdout -----
734
- -:1:17 : E999 SyntaxError: Expected an import name
734
+ -:1:16 : E999 SyntaxError: Expected one or more symbol names after import
735
735
Found 1 error.
736
736
737
737
----- stderr -----
738
- error: Failed to parse at 1:17: Expected an import name
738
+ error: Failed to parse at 1:16: Expected one or more symbol names after import
739
+ "### ) ;
740
+ }
741
+
742
+ #[ test]
743
+ fn stdin_multiple_parse_error ( ) {
744
+ let mut cmd = RuffCheck :: default ( ) . build ( ) ;
745
+ assert_cmd_snapshot ! ( cmd
746
+ . pass_stdin( "from foo import\n bar =\n " ) , @r###"
747
+ success: false
748
+ exit_code: 1
749
+ ----- stdout -----
750
+ -:1:16: E999 SyntaxError: Expected one or more symbol names after import
751
+ -:2:6: E999 SyntaxError: Expected an expression
752
+ Found 2 errors.
753
+
754
+ ----- stderr -----
755
+ error: Failed to parse at 1:16: Expected one or more symbol names after import
739
756
"### ) ;
740
757
}
741
758
Original file line number Diff line number Diff line change @@ -192,15 +192,17 @@ pub fn check_path(
192
192
doc_lines. extend ( doc_lines_from_ast ( parsed. suite ( ) , locator) ) ;
193
193
}
194
194
}
195
- Err ( parse_error ) => {
195
+ Err ( parse_errors ) => {
196
196
// Always add a diagnostic for the syntax error, regardless of whether
197
197
// `Rule::SyntaxError` is enabled. We avoid propagating the syntax error
198
198
// if it's disabled via any of the usual mechanisms (e.g., `noqa`,
199
199
// `per-file-ignores`), and the easiest way to detect that suppression is
200
200
// to see if the diagnostic persists to the end of the function.
201
- pycodestyle:: rules:: syntax_error ( & mut diagnostics, parse_error, locator) ;
201
+ for parse_error in parse_errors {
202
+ pycodestyle:: rules:: syntax_error ( & mut diagnostics, parse_error, locator) ;
203
+ }
202
204
// TODO(dhruvmanila): Remove this clone
203
- error = Some ( parse_error . clone ( ) ) ;
205
+ error = parse_errors . iter ( ) . next ( ) . cloned ( ) ;
204
206
}
205
207
}
206
208
}
Original file line number Diff line number Diff line change @@ -274,11 +274,11 @@ impl<T> Parsed<T> {
274
274
275
275
/// Returns the [`Parsed`] output as a [`Result`], returning [`Ok`] if it has no syntax errors,
276
276
/// or [`Err`] containing the first [`ParseError`] encountered.
277
- pub fn as_result ( & self ) -> Result < & Parsed < T > , & ParseError > {
278
- if let [ error, ..] = self . errors ( ) {
279
- Err ( error)
280
- } else {
277
+ pub fn as_result ( & self ) -> Result < & Parsed < T > , & [ ParseError ] > {
278
+ if self . is_valid ( ) {
281
279
Ok ( self )
280
+ } else {
281
+ Err ( & self . errors )
282
282
}
283
283
}
284
284
Original file line number Diff line number Diff line change @@ -126,8 +126,7 @@ fn test_invalid_syntax(input_path: &Path) {
126
126
#[ allow( clippy:: print_stdout) ]
127
127
fn parser_quick_test ( ) {
128
128
let source = "\
129
- def foo()
130
- pass
129
+ from foo import
131
130
" ;
132
131
133
132
let parsed = parse_unchecked ( source, Mode :: Module ) ;
You can’t perform that action at this time.
0 commit comments