mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +00:00
Update E999
to show all syntax errors (#11900)
## Summary This PR updates the linter to show all the parse errors as diagnostics instead of just the first one. Note that this doesn't affect the parse error displayed as error log message. This will be removed in a follow-up PR. ### Breaking? I don't think this is a breaking change even though this might give more diagnostics. The main reason is that this shouldn't affect any users because it'll only give additional diagnostics in the case of multiple syntax errors. ## Test Plan Add an integration test case which would raise more than one parse error.
This commit is contained in:
parent
cdc7c71449
commit
b617d90651
4 changed files with 30 additions and 12 deletions
|
@ -274,11 +274,11 @@ impl<T> Parsed<T> {
|
|||
|
||||
/// Returns the [`Parsed`] output as a [`Result`], returning [`Ok`] if it has no syntax errors,
|
||||
/// or [`Err`] containing the first [`ParseError`] encountered.
|
||||
pub fn as_result(&self) -> Result<&Parsed<T>, &ParseError> {
|
||||
if let [error, ..] = self.errors() {
|
||||
Err(error)
|
||||
} else {
|
||||
pub fn as_result(&self) -> Result<&Parsed<T>, &[ParseError]> {
|
||||
if self.is_valid() {
|
||||
Ok(self)
|
||||
} else {
|
||||
Err(&self.errors)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,8 +126,7 @@ fn test_invalid_syntax(input_path: &Path) {
|
|||
#[allow(clippy::print_stdout)]
|
||||
fn parser_quick_test() {
|
||||
let source = "\
|
||||
def foo()
|
||||
pass
|
||||
from foo import
|
||||
";
|
||||
|
||||
let parsed = parse_unchecked(source, Mode::Module);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue