Skip to content

Commit

Permalink
feat: log if formatter error
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Apr 5, 2024
1 parent 0df4c30 commit 807d6cd
Show file tree
Hide file tree
Showing 126 changed files with 494 additions and 252 deletions.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub enum MdsfError {
Fmt(core::fmt::Error),
ConfigParse(std::path::PathBuf),
FileNotFound(std::path::PathBuf),
FormatterError,
}

impl core::fmt::Display for MdsfError {
Expand All @@ -20,6 +21,7 @@ impl core::fmt::Display for MdsfError {
"No file or directory with the name '{}' found",
path.display()
)),
Self::FormatterError => f.write_str("Error formatting"),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/alejandra.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_alejandra(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("alejandra");

cmd.arg("--quiet").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/autopep8.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_autopep8(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("autopep8");

cmd.arg("--in-place").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/beautysh.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_beautysh(
file_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("beautysh");

cmd.arg(file_path);
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/biome.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::execute_command;
use crate::runners::setup_npm_script;
use crate::{error::MdsfError, runners::setup_npm_script};

#[inline]
pub fn format_using_biome(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
// NOTE: the biome docs recommend running biome using npx, and not directly
let mut cmd = setup_npm_script("@biomejs/biome");

Expand Down
3 changes: 2 additions & 1 deletion src/formatters/black.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_black(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("black");

cmd.arg("--quiet").arg(snippet_path);
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/blade_formatter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::execute_command;
use crate::runners::setup_npm_script;
use crate::{error::MdsfError, runners::setup_npm_script};

#[inline]
fn set_blade_formatter_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) {
Expand All @@ -10,7 +10,7 @@ fn set_blade_formatter_args(cmd: &mut std::process::Command, snippet_path: &std:
fn invote_blade_formatter(
mut cmd: std::process::Command,
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
set_blade_formatter_args(&mut cmd, snippet_path);

execute_command(&mut cmd, snippet_path)
Expand All @@ -19,7 +19,7 @@ fn invote_blade_formatter(
#[inline]
pub fn format_using_blade_formatter(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
invote_blade_formatter(setup_npm_script("blade-formatter"), snippet_path)
}

Expand Down
3 changes: 2 additions & 1 deletion src/formatters/blue.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_blue(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("blue");

cmd.arg("--quiet").arg(snippet_path);
Expand Down
5 changes: 4 additions & 1 deletion src/formatters/buf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_buf(snippet_path: &std::path::Path) -> std::io::Result<(bool, Option<String>)> {
pub fn format_using_buf(
snippet_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("buf");

cmd.arg("format").arg("--write").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/cabal_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_cabal_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("cabal");

cmd.arg("format").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/clang_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_clang_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("clang-format");

cmd.arg("-i").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/cljstyle.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_cljstyle(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("cljstyle");

cmd.arg("fix").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/crystal_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_crystal_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("crystal");

cmd.arg("tool").arg("format").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/csharpier.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_csharpier(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("dotnet");

cmd.arg("csharpier").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/dart_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_dart_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("dart");

cmd.arg("format").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/deno_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_deno_fmt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("deno");

cmd.arg("fmt").arg("--quiet").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/efmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_efmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option<String>)> {
pub fn format_using_efmt(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("efmt");

cmd.arg("-w").arg(file_path);
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/elm_format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::execute_command;
use crate::runners::setup_npm_script;
use crate::{error::MdsfError, runners::setup_npm_script};

#[inline]
fn set_elm_format_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) {
Expand All @@ -10,7 +10,7 @@ fn set_elm_format_args(cmd: &mut std::process::Command, snippet_path: &std::path
fn invoke_elm_format(
mut cmd: std::process::Command,
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
set_elm_format_args(&mut cmd, snippet_path);

execute_command(&mut cmd, snippet_path)
Expand All @@ -19,7 +19,7 @@ fn invoke_elm_format(
#[inline]
pub fn format_using_elm_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
invoke_elm_format(setup_npm_script("elm-format"), snippet_path)
}

Expand Down
5 changes: 4 additions & 1 deletion src/formatters/erlfmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_erlfmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option<String>)> {
pub fn format_using_erlfmt(
file_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("erlfmt");

cmd.arg("-w")
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/fantomas.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_fantomas(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("fantomas");

cmd.arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/fourmolu.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_fourmolu(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("fourmolu");

cmd.arg("-i").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/gleam_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_gleam_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("gleam");

cmd.arg("format").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/gofmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_gofmt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("gofmt");

cmd.arg("-w").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/gofumpt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_gofumpt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("gofumpt");

cmd.arg("-w").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/goimports.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_goimports(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("goimports");

cmd.arg("-w").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/google_java_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_google_java_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("google-java-format");

cmd.arg("-i").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/hindent.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_hindent(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("hindent");

cmd.arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/isort.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_isort(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("isort");

cmd.arg("--quiet").arg(snippet_path);
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/juliaformatter_jl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_juliaformatter_jl(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("julia");

cmd.arg("-E").arg(format!(
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/just_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::execute_command;
use crate::error::MdsfError;

#[inline]
pub fn format_using_just_fmt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("just");

cmd.arg("--fmt")
Expand Down
Loading

0 comments on commit 807d6cd

Please sign in to comment.