Skip to content

Commit

Permalink
feat: add support for inko fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jan 14, 2025
1 parent 26bd035 commit 3cc7831
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.4.0...HEAD)

- feat: add support for inko fmt [`#610`](https://github.com/hougesen/mdsf/pull/610)
- feat: add support for futhark fmt [`#609`](https://github.com/hougesen/mdsf/pull/609)
- feat: add support for wa fmt [`#608`](https://github.com/hougesen/mdsf/pull/608)
- feat: add support for selena [`#607`](https://github.com/hougesen/mdsf/pull/607)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 238 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 239 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -312,6 +312,7 @@ mdsf init
| [htmlbeautifier](https://github.com/threedaymonk/htmlbeautifier) | A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates | `formatter` | `erb`, `html`, `ruby` |
| [htmlhint](https://github.com/HTMLHint/HTMLHint) | The static code analysis tool you need for your HTML | `linter` | `html` |
| [imba](https://imba.io/) | A formatter for Imba | `formatter` | `imba` |
| [inko](https://github.com/inko-lang/inko) | Code formatter for the inko programming language | `formatter` | `inko` |
| [isort](https://github.com/timothycrosley/isort) | A Python utility to sort imports | `formatter` | `python` |
| [joker](https://github.com/candid82/joker) | Small Clojure interpreter, linter and formatter | `formatter`, `linter` | `clojure` |
| [js-beautify](https://github.com/beautifier/js-beautify) | A JavaScript formatter | `formatter` | `javascript` |
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/inko_fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::process::Command;

use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_inko_fmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("fmt");
cmd.arg(file_path);
cmd
}

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let commands = [CommandType::Direct("inko")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_inko_fmt_args(cmd.build(), file_path);
let execution_result = execute_command(cmd, file_path);

if index == commands.len() - 1 {
return execution_result;
}

if let Ok(r) = execution_result {
if !r.0 {
return Ok(r);
}
}
}

Ok((true, None))
}

#[cfg(test)]
mod test_inko_fmt {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub mod html_beautify;
pub mod htmlbeautifier;
pub mod htmlhint;
pub mod imba_fmt;
pub mod inko_fmt;
pub mod isort;
pub mod joker;
pub mod js_beautify;
Expand Down Expand Up @@ -648,6 +649,10 @@ pub enum Tooling {
/// `imba fmt -f $PATH`
ImbaFmt,

#[serde(rename = "inko:fmt")]
/// `inko fmt $PATH`
InkoFmt,

#[serde(rename = "isort")]
/// `isort --quiet $PATH`
Isort,
Expand Down Expand Up @@ -1356,6 +1361,7 @@ impl Tooling {
Self::Htmlbeautifier => htmlbeautifier::run(snippet_path),
Self::Htmlhint => htmlhint::run(snippet_path),
Self::ImbaFmt => imba_fmt::run(snippet_path),
Self::InkoFmt => inko_fmt::run(snippet_path),
Self::Isort => isort::run(snippet_path),
Self::Joker => joker::run(snippet_path),
Self::JsBeautify => js_beautify::run(snippet_path),
Expand Down Expand Up @@ -1614,6 +1620,7 @@ impl AsRef<str> for Tooling {
Self::Htmlbeautifier => "htmlbeautifier",
Self::Htmlhint => "htmlhint",
Self::ImbaFmt => "imba_fmt",
Self::InkoFmt => "inko_fmt",
Self::Isort => "isort",
Self::Joker => "joker",
Self::JsBeautify => "js_beautify",
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.4.0-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@
"type": "string",
"enum": ["imba:fmt"]
},
{
"description": "`inko fmt $PATH`",
"type": "string",
"enum": ["inko:fmt"]
},
{
"description": "`isort --quiet $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/inko/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "inko",
"categories": ["formatter"],
"commands": {
"fmt": ["fmt", "$PATH"]
},
"description": "Code formatter for the inko programming language",
"homepage": "https://github.com/inko-lang/inko",
"languages": ["inko"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 3cc7831

Please sign in to comment.