diff --git a/CHANGELOG.md b/CHANGELOG.md index eded37f..5afe8be 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.4.0...HEAD) +- feat: add support for pycodestyle [`#612`](https://github.com/hougesen/mdsf/pull/612) - feat: add support for csslint [`#611`](https://github.com/hougesen/mdsf/pull/611) - 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) diff --git a/README.md b/README.md index 47673a1..4a84485 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 240 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 241 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -379,6 +379,7 @@ mdsf init | [purs-tidy](https://github.com/natefaubion/purescript-tidy) | PureScript code formatter | `formatter` | `purescript` | | [purty](https://gitlab.com/joneshf/purty) | PureScript pretty-printer | `formatter` | `purescript` | | [pycln](https://github.com/hadialqattan/pycln) | A formatter for finding and removing unused import statements | `formatter` | `python` | +| [pycodestyle](https://github.com/PyCQA/pycodestyle) | Simple Python style checker in one Python file | `linter` | `python` | | [pyink](https://github.com/google/pyink) | Pyink is a Python formatter, forked from Black with a few different formatting behaviors | `formatter` | `python` | | [pyment](https://github.com/dadadel/pyment) | Format and convert Python docstrings and generates patches | `formatter` | `python` | | [qmlfmt](https://github.com/jesperhh/qmlfmt) | qmlfmt - command line application that formats QML files | `formatter` | `qml` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index d88b37a..d9d96e5 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -166,6 +166,7 @@ pub mod puppet_lint; pub mod purs_tidy; pub mod purty; pub mod pycln; +pub mod pycodestyle; pub mod pyink; pub mod pyment; pub mod qmlfmt; @@ -926,6 +927,10 @@ pub enum Tooling { /// `pycln --no-gitignore --quiet $PATH` Pycln, + #[serde(rename = "pycodestyle")] + /// `pycodestyle $PATH` + Pycodestyle, + #[serde(rename = "pyink")] /// `pyink --quiet $PATH` Pyink, @@ -1435,6 +1440,7 @@ impl Tooling { Self::PursTidy => purs_tidy::run(snippet_path), Self::Purty => purty::run(snippet_path), Self::Pycln => pycln::run(snippet_path), + Self::Pycodestyle => pycodestyle::run(snippet_path), Self::Pyink => pyink::run(snippet_path), Self::Pyment => pyment::run(snippet_path), Self::Qmlfmt => qmlfmt::run(snippet_path), @@ -1695,6 +1701,7 @@ impl AsRef for Tooling { Self::PursTidy => "purs_tidy", Self::Purty => "purty", Self::Pycln => "pycln", + Self::Pycodestyle => "pycodestyle", Self::Pyink => "pyink", Self::Pyment => "pyment", Self::Qmlfmt => "qmlfmt", diff --git a/mdsf/src/tools/pycodestyle.rs b/mdsf/src/tools/pycodestyle.rs new file mode 100644 index 0000000..12b6cef --- /dev/null +++ b/mdsf/src/tools/pycodestyle.rs @@ -0,0 +1,34 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_pycodestyle_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("pycodestyle")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_pycodestyle_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_pycodestyle {} diff --git a/schemas/v0.4.0-dev/mdsf.schema.json b/schemas/v0.4.0-dev/mdsf.schema.json index 97d5e8e..c34579f 100644 --- a/schemas/v0.4.0-dev/mdsf.schema.json +++ b/schemas/v0.4.0-dev/mdsf.schema.json @@ -898,6 +898,11 @@ "type": "string", "enum": ["pycln"] }, + { + "description": "`pycodestyle $PATH`", + "type": "string", + "enum": ["pycodestyle"] + }, { "description": "`pyink --quiet $PATH`", "type": "string", diff --git a/tools/pycodestyle/plugin.json b/tools/pycodestyle/plugin.json new file mode 100644 index 0000000..a1595fc --- /dev/null +++ b/tools/pycodestyle/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "pycodestyle", + "categories": ["linter"], + "commands": { + "": ["$PATH"] + }, + "description": "Simple Python style checker in one Python file", + "homepage": "https://github.com/PyCQA/pycodestyle", + "languages": ["python"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}