Skip to content

Commit

Permalink
feat(toml): add support for taplo (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Mar 7, 2024
1 parent c8229fd commit 09a8156
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ use crate::languages::Language;

use self::{
biome::format_using_biome, nimpretty::format_using_nimpretty, ruff::format_using_ruff,
rustfmt::format_using_rustfmt, stylua::format_using_stylua, zigfmt::format_using_zigfmt,
rustfmt::format_using_rustfmt, stylua::format_using_stylua, taplo::format_using_taplo,
zigfmt::format_using_zigfmt,
};

mod biome;
mod nimpretty;
mod ruff;
mod rustfmt;
mod stylua;
mod taplo;
mod zigfmt;

pub fn setup_snippet(code: &str, file_ext: &str) -> std::io::Result<NamedTempFile> {
Expand Down Expand Up @@ -51,6 +53,7 @@ pub fn format_snippet(language: &str, code: String) -> String {
Language::Nim => format_using_nimpretty(snippet_path),
Language::Python => format_using_ruff(snippet_path),
Language::Rust => format_using_rustfmt(snippet_path),
Language::Toml => format_using_taplo(snippet_path),
Language::TypeScript => format_using_biome(snippet_path),
Language::Zig => format_using_zigfmt(snippet_path),
} {
Expand Down
14 changes: 14 additions & 0 deletions src/formatters/taplo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use super::{execute_command, read_snippet};

pub fn format_using_taplo(file_path: &std::path::Path) -> std::io::Result<Option<String>> {
let mut cmd = std::process::Command::new("taplo");

cmd.arg("fmt");
cmd.arg(file_path);

if execute_command(&mut cmd)? {
return read_snippet(file_path).map(Some);
}

Ok(None)
}
4 changes: 3 additions & 1 deletion src/languages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub enum Language {
Nim,
Python,
Rust,
Toml,
TypeScript,
Zig,
}
Expand All @@ -18,9 +19,9 @@ impl Language {
"nim" => Some(Self::Nim),
"python" => Some(Self::Python),
"rust" => Some(Self::Rust),
"toml" => Some(Self::Toml),
"ts" | "tsx" | "typescript" => Some(Self::TypeScript),
"zig" => Some(Self::Zig),

_ => None,
}
}
Expand All @@ -33,6 +34,7 @@ impl Language {
Self::Nim => ".nim",
Self::Python => ".py",
Self::Rust => ".rs",
Self::Toml => ".toml",
Self::TypeScript => ".ts",
Self::Zig => ".zig",
}
Expand Down
9 changes: 9 additions & 0 deletions test/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,12 @@ function add(
"b": ["1",23,null]}
}
```

```toml


name = "mdsf"
author = "Mads Hougesen"


```

0 comments on commit 09a8156

Please sign in to comment.