Skip to content

Commit

Permalink
feat: add support for pycodestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jan 14, 2025
1 parent c850693 commit c3d0f8e
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.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)
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 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 |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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` |
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 @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1695,6 +1701,7 @@ impl AsRef<str> for Tooling {
Self::PursTidy => "purs_tidy",
Self::Purty => "purty",
Self::Pycln => "pycln",
Self::Pycodestyle => "pycodestyle",
Self::Pyink => "pyink",
Self::Pyment => "pyment",
Self::Qmlfmt => "qmlfmt",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/pycodestyle.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_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<String>), 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 {}
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 @@ -898,6 +898,11 @@
"type": "string",
"enum": ["pycln"]
},
{
"description": "`pycodestyle $PATH`",
"type": "string",
"enum": ["pycodestyle"]
},
{
"description": "`pyink --quiet $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/pycodestyle/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit c3d0f8e

Please sign in to comment.