Skip to content

Commit

Permalink
feat: add support for mypy (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 12, 2025
1 parent bfcb5cd commit 792333f
Show file tree
Hide file tree
Showing 6 changed files with 64 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.3.2...HEAD)

- feat: add support for mypy [`#597`](https://github.com/hougesen/mdsf/pull/597)
- feat: add support for luacheck [`#596`](https://github.com/hougesen/mdsf/pull/596)
- feat: add support for htmlhint [`#595`](https://github.com/hougesen/mdsf/pull/595)
- feat: add support for vacuum [`#594`](https://github.com/hougesen/mdsf/pull/594)
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 228 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 229 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -341,6 +341,7 @@ mdsf init
| [misspell](https://github.com/client9/misspell/) | Correct commonly misspelled English words in source files | `autocorrection` | |
| [mix](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) | Code formatter for Elixir | `formatter` | `elixir` |
| [mojo](https://docs.modular.com/mojo/cli/format) | Formats Mojo source files | `formatter` | `mojo` |
| [mypy](https://github.com/python/mypy) | Optional static typing for Python | `linter` | `python` |
| [nginxbeautifier](https://github.com/vasilevich/nginxbeautifier) | Format and beautify nginx config files | `formatter` | `nginx` |
| [nginxfmt](https://github.com/slomkowski/nginx-config-formatter) | nginx config file formatter/beautifier written in Python with no additional dependencies | `formatter` | `nginx` |
| [nickel](https://nickel-lang.org/) | Better configuration for less | `formatter` | `nickel` |
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 @@ -127,6 +127,7 @@ pub mod meson_fmt;
pub mod misspell;
pub mod mix_format;
pub mod mojo_format;
pub mod mypy;
pub mod nginxbeautifier;
pub mod nginxfmt;
pub mod nickel_format;
Expand Down Expand Up @@ -757,6 +758,10 @@ pub enum Tooling {
/// `mojo format -q $PATH`
MojoFormat,

#[serde(rename = "mypy")]
/// `mypy $PATH`
Mypy,

#[serde(rename = "nginxbeautifier")]
/// `nginxbeautifier $PATH`
Nginxbeautifier,
Expand Down Expand Up @@ -1331,6 +1336,7 @@ impl Tooling {
Self::Misspell => misspell::run(snippet_path),
Self::MixFormat => mix_format::run(snippet_path),
Self::MojoFormat => mojo_format::run(snippet_path),
Self::Mypy => mypy::run(snippet_path),
Self::Nginxbeautifier => nginxbeautifier::run(snippet_path),
Self::Nginxfmt => nginxfmt::run(snippet_path),
Self::NickelFormat => nickel_format::run(snippet_path),
Expand Down Expand Up @@ -1578,6 +1584,7 @@ impl AsRef<str> for Tooling {
Self::Misspell => "misspell",
Self::MixFormat => "mix_format",
Self::MojoFormat => "mojo_format",
Self::Mypy => "mypy",
Self::Nginxbeautifier => "nginxbeautifier",
Self::Nginxfmt => "nginxfmt",
Self::NickelFormat => "nickel_format",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/mypy.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_mypy_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("mypy")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_mypy_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_mypy {}
5 changes: 5 additions & 0 deletions schemas/v0.3.3-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@
"type": "string",
"enum": ["mojo:format"]
},
{
"description": "`mypy $PATH`",
"type": "string",
"enum": ["mypy"]
},
{
"description": "`nginxbeautifier $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/mypy/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "mypy",
"categories": ["linter"],
"commands": {
"": ["$PATH"]
},
"description": "Optional static typing for Python",
"homepage": "https://github.com/python/mypy",
"languages": ["python"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 792333f

Please sign in to comment.