Skip to content

Commit

Permalink
Revert "Use diagnostic severity in cairo formatter (#986)"
Browse files Browse the repository at this point in the history
This reverts commit 6241257.
  • Loading branch information
maciektr committed Dec 21, 2023
1 parent 03dd363 commit 87e0373
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
30 changes: 9 additions & 21 deletions scarb/src/ops/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};

use anyhow::Result;
use cairo_lang_diagnostics::Severity;
use cairo_lang_formatter::cairo_formatter::FormattingError;
use cairo_lang_formatter::{CairoFormatter, FormatOutcome, FormatterConfig};
use clap::ValueEnum;
use ignore::WalkState::{Continue, Skip};
Expand Down Expand Up @@ -110,25 +108,15 @@ fn print_diff(ws: &Workspace<'_>, path: &Path, diff: impl Display) {
.print(format!("Diff in file {}:\n {}", path.display(), diff));
}

fn print_error(ws: &Workspace<'_>, path: &Path, error: FormattingError) {
match error {
FormattingError::ParsingError(error) => {
for entry in error.iter() {
let msg = entry
.message()
.strip_suffix('\n')
.unwrap_or(entry.message());
match entry.severity() {
Severity::Error => ws.config().ui().error(msg),
Severity::Warning => ws.config().ui().warn(msg),
};
}
}
FormattingError::Error(error) => {
let error = error.context(format!("cannot format file {}", path.display()));
ws.config().ui().error(error.to_string());
}
}
fn print_error(ws: &Workspace<'_>, path: &Path, error: anyhow::Error) {
let error_msg = error.to_string();
ws.config().ui().error(format!(
"{}Error writing files: cannot parse {}",
// TODO(maciektr): Fix this with proper upstream changes.
// The slice is a hacky way of avoiding duplicated "error: " prefix.
&error_msg[7..],
path.display()
));
}

fn check_file_formatting(
Expand Down
1 change: 1 addition & 0 deletions scarb/tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn simple_format_with_parsing_error() {
fn main() -> { 42 }
^
Error writing files: cannot parse [..]lib.cairo
"#});
}

Expand Down

0 comments on commit 87e0373

Please sign in to comment.