From 9391f78bfb59aff8971a60d8aaed6f54d7d8303f Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 12 Jan 2025 19:12:14 +0100 Subject: [PATCH] feat: add support for mypy --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/mod.rs | 7 ++++++ mdsf/src/tools/mypy.rs | 34 +++++++++++++++++++++++++++++ schemas/v0.3.3-dev/mdsf.schema.json | 5 +++++ tools/mypy/plugin.json | 15 +++++++++++++ 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 mdsf/src/tools/mypy.rs create mode 100644 tools/mypy/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index e49c4e7..6fe0acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 4c5567c..b682347 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`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 | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -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` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 9bcab67..bc677a0 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -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; @@ -757,6 +758,10 @@ pub enum Tooling { /// `mojo format -q $PATH` MojoFormat, + #[serde(rename = "mypy")] + /// `mypy $PATH` + Mypy, + #[serde(rename = "nginxbeautifier")] /// `nginxbeautifier $PATH` Nginxbeautifier, @@ -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), @@ -1578,6 +1584,7 @@ impl AsRef 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", diff --git a/mdsf/src/tools/mypy.rs b/mdsf/src/tools/mypy.rs new file mode 100644 index 0000000..5cdd2ab --- /dev/null +++ b/mdsf/src/tools/mypy.rs @@ -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), 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 {} diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index d500752..3408860 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -703,6 +703,11 @@ "type": "string", "enum": ["mojo:format"] }, + { + "description": "`mypy $PATH`", + "type": "string", + "enum": ["mypy"] + }, { "description": "`nginxbeautifier $PATH`", "type": "string", diff --git a/tools/mypy/plugin.json b/tools/mypy/plugin.json new file mode 100644 index 0000000..78a90aa --- /dev/null +++ b/tools/mypy/plugin.json @@ -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": [] +}