Skip to content

Commit

Permalink
feat: add support for selena (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 12, 2025
1 parent b41d24b commit 614697b
Show file tree
Hide file tree
Showing 8 changed files with 1,363 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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 selena [`#607`](https://github.com/hougesen/mdsf/pull/607)

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

> 13 January 2025
Expand Down Expand Up @@ -58,6 +60,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- build: update cargo-dist to v0.26.1 [`#557`](https://github.com/hougesen/mdsf/pull/557)
- chore: update dev version to v0.3.3-dev [`#556`](https://github.com/hougesen/mdsf/pull/556)
- feat: nushell shell completion (#583) [`#382`](https://github.com/hougesen/mdsf/issues/382)
- chore: update changelog [`b41d24b`](https://github.com/hougesen/mdsf/commit/b41d24bd36524939122be7f7ed4655b71e4cff6f)

#### [v0.3.2](https://github.com/hougesen/mdsf/compare/v0.3.1...v0.3.2)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ brew install hougesen/tap/mdsf
<!-- START_SECTION:base-command-help -->

```
mdsf 0.4.0
mdsf 0.4.0-dev
Format markdown code snippets using your favorite code formatters
Mads Hougesen <[email protected]>
Expand Down Expand Up @@ -214,7 +214,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

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

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -398,6 +398,7 @@ mdsf init
| [salt-lint](https://github.com/warpnet/salt-lint) | A command-line utility that checks for best practices in SaltStack | `linter` | `salt` |
| [scalafmt](https://github.com/scalameta/scalafmt) | Code formatter for Scala | `formatter` | `scala` |
| [scalariform](https://github.com/scala-ide/scalariform) | Scala source code formatter | `formatter` | `scala` |
| [selene](https://github.com/Kampfkarren/selene) | A blazing-fast modern Lua linter written in Rust | `linter` | `lua` |
| [shellcheck](https://github.com/koalaman/shellcheck) | ShellCheck, a static analysis tool for shell scripts | `linter` | `bash`, `shell` |
| [shellharden](https://github.com/anordal/shellharden) | The corrective bash syntax highlighter | `linter` | `bash`, `shell` |
| [shfmt](https://github.com/mvdan/sh) | Shell script formatter | `formatter` | `shell` |
Expand Down
2 changes: 1 addition & 1 deletion mdsf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mdsf"
version = "0.4.0"
version = "0.4.0-dev"
edition.workspace = true
description = "Format markdown code snippets using your favorite code formatters"
authors.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub mod rustywind;
pub mod salt_lint;
pub mod scalafmt;
pub mod scalariform;
pub mod selene;
pub mod shellcheck;
pub mod shellharden;
pub mod shfmt;
Expand Down Expand Up @@ -1005,6 +1006,10 @@ pub enum Tooling {
/// `scalariform $PATH`
Scalariform,

#[serde(rename = "selene")]
/// `selene $PATH`
Selene,

#[serde(rename = "shellcheck")]
/// `shellcheck $PATH`
Shellcheck,
Expand Down Expand Up @@ -1431,6 +1436,7 @@ impl Tooling {
Self::SaltLint => salt_lint::run(snippet_path),
Self::Scalafmt => scalafmt::run(snippet_path),
Self::Scalariform => scalariform::run(snippet_path),
Self::Selene => selene::run(snippet_path),
Self::Shellcheck => shellcheck::run(snippet_path),
Self::Shellharden => shellharden::run(snippet_path),
Self::Shfmt => shfmt::run(snippet_path),
Expand Down Expand Up @@ -1686,6 +1692,7 @@ impl AsRef<str> for Tooling {
Self::SaltLint => "salt_lint",
Self::Scalafmt => "scalafmt",
Self::Scalariform => "scalariform",
Self::Selene => "selene",
Self::Shellcheck => "shellcheck",
Self::Shellharden => "shellharden",
Self::Shfmt => "shfmt",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/selene.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process::Command;

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

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

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

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_selene_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_selene {}
Loading

0 comments on commit 614697b

Please sign in to comment.