diff --git a/crates/ruff/src/diagnostics.rs b/crates/ruff/src/diagnostics.rs index feb16626f5fee..99fab940516ef 100644 --- a/crates/ruff/src/diagnostics.rs +++ b/crates/ruff/src/diagnostics.rs @@ -265,7 +265,7 @@ pub(crate) fn lint_path( let ( LinterResult { messages, - has_error, + has_syntax_error: has_error, }, transformed, fixed, diff --git a/crates/ruff_benchmark/benches/linter.rs b/crates/ruff_benchmark/benches/linter.rs index e3e70ed423be0..dc27674ade682 100644 --- a/crates/ruff_benchmark/benches/linter.rs +++ b/crates/ruff_benchmark/benches/linter.rs @@ -73,7 +73,7 @@ fn benchmark_linter(mut group: BenchmarkGroup, settings: &LinterSettings) { ); // Assert that file contains no parse errors - assert!(!result.has_error); + assert!(!result.has_syntax_error); }, criterion::BatchSize::SmallInput, ); diff --git a/crates/ruff_linter/src/linter.rs b/crates/ruff_linter/src/linter.rs index 5e48a24796e18..960743e3e751a 100644 --- a/crates/ruff_linter/src/linter.rs +++ b/crates/ruff_linter/src/linter.rs @@ -40,7 +40,7 @@ pub struct LinterResult { pub messages: Vec, /// A flag indicating the presence of syntax errors in the source file. /// If `true`, at least one syntax error was detected in the source file. - pub has_error: bool, + pub has_syntax_error: bool, } pub type FixTable = FxHashMap; @@ -421,7 +421,7 @@ pub fn lint_only( &locator, &directives, ), - has_error: !parsed.is_valid(), + has_syntax_error: !parsed.is_valid(), } } @@ -474,8 +474,8 @@ pub fn lint_fix<'a>( // As an escape hatch, bail after 100 iterations. let mut iterations = 0; - // Track whether the _initial_ source code was parseable. - let mut parseable = false; + // Track whether the _initial_ source code is valid syntax. + let mut is_valid_syntax = false; // Continuously fix until the source code stabilizes. loop { @@ -516,13 +516,13 @@ pub fn lint_fix<'a>( ); if iterations == 0 { - parseable = parsed.is_valid(); + is_valid_syntax = parsed.is_valid(); } else { // If the source code was parseable on the first pass, but is no // longer parseable on a subsequent pass, then we've introduced a // syntax error. Return the original code. - if parseable { - if let [error, ..] = parsed.errors() { + if is_valid_syntax { + if let Some(error) = parsed.errors().first() { report_fix_syntax_error( path, transformed.source_code(), @@ -568,7 +568,7 @@ pub fn lint_fix<'a>( &locator, &directives, ), - has_error: !parseable, + has_syntax_error: !is_valid_syntax, }, transformed, fixed, diff --git a/crates/ruff_server/src/fix.rs b/crates/ruff_server/src/fix.rs index 6992f692bc705..6690279da020a 100644 --- a/crates/ruff_server/src/fix.rs +++ b/crates/ruff_server/src/fix.rs @@ -68,7 +68,10 @@ pub(crate) fn fix_all( // which is inconsistent with how `ruff check --fix` works. let FixerResult { transformed, - result: LinterResult { has_error, .. }, + result: LinterResult { + has_syntax_error: has_error, + .. + }, .. } = ruff_linter::linter::lint_fix( &query.virtual_file_path(),