Skip to content

Commit

Permalink
feat: log debug formatter info
Browse files Browse the repository at this point in the history
Closes #146
  • Loading branch information
hougesen committed Apr 2, 2024
1 parent 6901966 commit 34a966e
Show file tree
Hide file tree
Showing 61 changed files with 423 additions and 69 deletions.
4 changes: 4 additions & 0 deletions src/formatters/autopep8.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_autopep8(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("autopep8");

let mut cmd = std::process::Command::new("autopep8");

cmd.arg("--in-place").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/beautysh.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_beautysh(
file_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("beautysh");

let mut cmd = std::process::Command::new("beautysh");

cmd.arg(file_path);
Expand Down
7 changes: 6 additions & 1 deletion src/formatters/biome.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::runners::{setup_npm_script, JavaScriptRuntime};
use crate::{
runners::{setup_npm_script, JavaScriptRuntime},
terminal::print_debug_formatter_info,
};

use super::execute_command;

#[inline]
pub fn format_using_biome(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("biome");

// NOTE: the biome docs recommend running biome using npx, and not directly
let mut cmd = setup_npm_script(JavaScriptRuntime::default(), "@biomejs/biome");

Expand Down
4 changes: 4 additions & 0 deletions src/formatters/black.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_black(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("black");

let mut cmd = std::process::Command::new("black");

cmd.arg("--quiet").arg(snippet_path);
Expand Down
7 changes: 6 additions & 1 deletion src/formatters/blade_formatter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::runners::{setup_npm_script, JavaScriptRuntime};
use crate::{
runners::{setup_npm_script, JavaScriptRuntime},
terminal::print_debug_formatter_info,
};

use super::execute_command;

Expand All @@ -21,6 +24,8 @@ fn invote_blade_formatter(
pub fn format_using_blade_formatter(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("blade-formatter");

invote_blade_formatter(
setup_npm_script(JavaScriptRuntime::default(), "blade-formatter"),
snippet_path,
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/blue.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_blue(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("blue");

let mut cmd = std::process::Command::new("blue");

cmd.arg("--quiet").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/buf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_buf(snippet_path: &std::path::Path) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("buf");

let mut cmd = std::process::Command::new("buf");

cmd.arg("format").arg("--write").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/clang_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_clang_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("clang-format");

let mut cmd = std::process::Command::new("clang-format");

cmd.arg("-i").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/cljstyle.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_cljstyle(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("cljstyle");

let mut cmd = std::process::Command::new("cljstyle");

cmd.arg("fix").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/crystal_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_crystal_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("crystal");

let mut cmd = std::process::Command::new("crystal");

cmd.arg("tool").arg("format").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/csharpier.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_csharpier(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("csharpier");

let mut cmd = std::process::Command::new("dotnet");

cmd.arg("csharpier").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/dart_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_dart_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("dart_format");

let mut cmd = std::process::Command::new("dart");

cmd.arg("format").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/deno_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_deno_fmt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("deno_fmt");

let mut cmd = std::process::Command::new("deno");

cmd.arg("fmt").arg("--quiet").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/efmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_efmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("efmt");

let mut cmd = std::process::Command::new("efmt");

cmd.arg("-w").arg(file_path);
Expand Down
7 changes: 6 additions & 1 deletion src/formatters/elm_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use crate::runners::{setup_npm_script, JavaScriptRuntime};
use crate::{
runners::{setup_npm_script, JavaScriptRuntime},
terminal::print_debug_formatter_info,
};

use super::execute_command;

#[inline]
fn set_elm_format_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) {
print_debug_formatter_info("elm_format");

cmd.arg("--elm-version=0.19").arg("--yes").arg(snippet_path);
}

Expand Down
4 changes: 4 additions & 0 deletions src/formatters/erlfmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_erlfmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("erlfmt");

let mut cmd = std::process::Command::new("erlfmt");

cmd.arg("-w")
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/fantomas.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_fantomas(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("fantomas");

let mut cmd = std::process::Command::new("fantomas");

cmd.arg(snippet_path);
Expand Down
8 changes: 6 additions & 2 deletions src/formatters/fourmolu.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_fourmolu(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("fourmolu");

let mut cmd = std::process::Command::new("fourmolu");

cmd.arg("-i").arg(snippet_path);
Expand All @@ -22,8 +26,8 @@ mod test_fourmolu {
fn it_should_format_haskell() {
let input = "
addNumbers::Int->Int->Int
addNumbers a b = do
a + b
addNumbers a b = do
a + b
";

let expected_output = "addNumbers :: Int -> Int -> Int
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/gleam_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_gleam_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("gleam_format");

let mut cmd = std::process::Command::new("gleam");

cmd.arg("format").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/gofmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_gofmt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("gofmt");

let mut cmd = std::process::Command::new("gofmt");

cmd.arg("-w").arg(snippet_path);
Expand Down
8 changes: 6 additions & 2 deletions src/formatters/gofumpt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_gofumpt(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("gofumpt");

let mut cmd = std::process::Command::new("gofumpt");

cmd.arg("-w").arg(snippet_path);
Expand All @@ -18,10 +22,10 @@ mod test_gofumpt {
#[test_with::executable(gofumpt)]
#[test]
fn it_should_format_go() {
let input = "package main
let input = "package main
func add(a int , b int ) int {
return a + b
return a + b
}
";
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/goimports.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_goimports(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("goimports");

let mut cmd = std::process::Command::new("goimports");

cmd.arg("-w").arg(snippet_path);
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/google_java_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_google_java_format(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("google-java-format");

let mut cmd = std::process::Command::new("google-java-format");

cmd.arg("-i").arg(snippet_path);
Expand Down
8 changes: 6 additions & 2 deletions src/formatters/hindent.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_hindent(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("hindent");

let mut cmd = std::process::Command::new("hindent");

cmd.arg(snippet_path);
Expand All @@ -22,8 +26,8 @@ mod test_hindent {
fn it_should_format_haskell() {
let input = "
addNumbers::Int->Int->Int
addNumbers a b = do
a + b
addNumbers a b = do
a + b
";

let expected_output = "addNumbers :: Int -> Int -> Int
Expand Down
8 changes: 6 additions & 2 deletions src/formatters/isort.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::terminal::print_debug_formatter_info;

use super::execute_command;

#[inline]
pub fn format_using_isort(
snippet_path: &std::path::Path,
) -> std::io::Result<(bool, Option<String>)> {
print_debug_formatter_info("isort");

let mut cmd = std::process::Command::new("isort");

cmd.arg("--quiet").arg(snippet_path);
Expand All @@ -22,8 +26,8 @@ mod test_isort {
fn it_should_format_python() {
let input = "from q import d
import b
import a
import c
import a
import c
def add(a: int, b: int) -> int:
Expand Down
Loading

0 comments on commit 34a966e

Please sign in to comment.