Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 5, 2022
1 parent 7eef70c commit 77139d7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
21 changes: 17 additions & 4 deletions crates/rome_service/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ impl Diagnostic for RomeError {
)
}
}
RomeError::FormatError(err) => err.message(f),
RomeError::FormatError(err) => {
f.write_markup(markup! {
"the formatter encountered an error while formatting the file: "
})?;
err.message(f)
},
RomeError::FormatWithErrorsDisabled => f.write_markup(
markup!{ "The file could not be formatted since it has syntax errors and "<Emphasis>"formatWithErrors"</Emphasis>" is disabled" }
),
Expand Down Expand Up @@ -195,10 +200,9 @@ impl Diagnostic for RomeError {
write!(f, "The file {} was ignored", path)
},
RomeError::FileTooLarge { path, size, limit } => {
let path = format!("{}", path.display());
f.write_markup(
markup!{
"Size of "{{path}}" is "{{Bytes(*size)}}" which exceeds configured maximum of "{{Bytes(*limit)}}" for this project. The file size limit exists to prevent us inadvertently slowing down and loading large files that we shouldn't."
"Size of "{{path.display().to_string()}}" is "{{Bytes(*size)}}" which exceeds configured maximum of "{{Bytes(*limit)}}" for this project. The file size limit exists to prevent us inadvertently slowing down and loading large files that we shouldn't."
}
)
},
Expand Down Expand Up @@ -433,6 +437,7 @@ mod test {
use crate::file_handlers::Language;
use crate::{RomeError, TransportError};
use rome_diagnostics::{print_diagnostic_to_string, DiagnosticExt, Error, FileId};
use rome_formatter::FormatError;
use rome_fs::RomePath;
use std::path::PathBuf;

Expand Down Expand Up @@ -464,7 +469,7 @@ mod test {
fn cant_read_directory() {
snap_diagnostic(
"cant_read_directory",
RomeError::CantReadDirectory("example/".to_string()).with_file_path("example.js"),
RomeError::CantReadDirectory("example/".to_string()).with_file_path("example/"),
)
}

Expand Down Expand Up @@ -538,4 +543,12 @@ mod test {
.into(),
)
}

#[test]
fn formatter_syntax_error() {
snap_diagnostic(
"formatter_syntax_error",
RomeError::FormatError(FormatError::SyntaxError).with_file_path("example.js"),
)
}
}
9 changes: 2 additions & 7 deletions crates/rome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,8 @@ impl std::fmt::Display for Mime {
}

impl rome_console::fmt::Display for Mime {
fn fmt(&self, f: &mut rome_console::fmt::Formatter<'_>) -> std::io::Result<()> {
match self {
Mime::Css => f.write_markup(markup! { "text/css"}),
Mime::Json => f.write_markup(markup! { "application/json"}),
Mime::Javascript => f.write_markup(markup! { "application/javascript"}),
Mime::Text => f.write_markup(markup! { "text/plain"}),
}
fn fmt(&self, f: &mut Formatter<'_>) -> std::io::Result<()> {
write!(f, "{self}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rome_service/src/snapshots/cant_read_directory.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/rome_service/src/diagnostics.rs
expression: content
---
example.js internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
example/ internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Rome couldn't read the following directory, maybe for permissions reasons or it doesn't exists: example/

Expand Down
10 changes: 10 additions & 0 deletions crates/rome_service/src/snapshots/formatter_syntax_error.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/rome_service/src/diagnostics.rs
expression: content
---
example.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× the formatter encountered an error while formatting the file: Syntax error.



0 comments on commit 77139d7

Please sign in to comment.