Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jun 27, 2024
1 parent d479a4f commit e04b401
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/ruff/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub(crate) fn lint_path(
let (
LinterResult {
messages,
has_error,
has_syntax_error: has_error,
},
transformed,
fixed,
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
16 changes: 8 additions & 8 deletions crates/ruff_linter/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct LinterResult {
pub messages: Vec<Message>,
/// 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<Rule, usize>;
Expand Down Expand Up @@ -421,7 +421,7 @@ pub fn lint_only(
&locator,
&directives,
),
has_error: !parsed.is_valid(),
has_syntax_error: !parsed.is_valid(),
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -568,7 +568,7 @@ pub fn lint_fix<'a>(
&locator,
&directives,
),
has_error: !parseable,
has_syntax_error: !is_valid_syntax,
},
transformed,
fixed,
Expand Down
5 changes: 4 additions & 1 deletion crates/ruff_server/src/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e04b401

Please sign in to comment.