Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tools): add support for perflint #869

Merged
merged 1 commit into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ jobs:
run: ( ( which ormolu ) || ( ( which brew && brew install ormolu ) || ( which apt-get && sudo apt-get install -y ormolu ) || ( which stack && stack install ormolu ) || ( which cabal && cabal install ormolu ) ) || ( echo "Unable to install tool" ) )
- name: oxlint
run: ( ( which oxlint ) || ( ( which npm && npm i -g oxlint ) ) || ( echo "Unable to install tool" ) )
- name: perflint
run: ( ( which perflint ) || ( ( which pipx && pipx install perflint ) ) || ( echo "Unable to install tool" ) )
- name: prettier
run: ( ( which prettier ) || ( ( which npm && npm i -g prettier ) ) || ( echo "Unable to install tool" ) )
- name: prisma
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. Dates are d

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.8.2...HEAD)

- test(tools): validate js-beautify [`#868`](https://github.com/hougesen/mdsf/pull/868)
- test(tools): validate jsonlint [`#867`](https://github.com/hougesen/mdsf/pull/867)
- test(tools): validate vhdl-style-guide [`#866`](https://github.com/hougesen/mdsf/pull/866)
- refactor: add empty tests array if not set [`#865`](https://github.com/hougesen/mdsf/pull/865)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ mdsf init

<!-- START_SECTION:supported-tools -->

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

| Name | Description | Categories | Languages |
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -566,6 +566,7 @@ mdsf init
| [oxlint](https://oxc.rs/docs/guide/usage/linter.html) | Oxlint is designed to catch erroneous or useless code without requiring any configurations by default | `linter` | `javascript`, `typescript` |
| [packer](https://developer.hashicorp.com/packer/docs/commands) | Packer is used to format HCL2 configuration files | `formatter` | `hcl` |
| [pasfmt](https://github.com/integrated-application-development/pasfmt) | Delphi code formatter | `formatter` | `delphi`, `pascal` |
| [perflint](https://github.com/tonybaloney/perflint) | Python Linter for performance anti patterns | `linter` | `python` |
| [perltidy](https://github.com/perltidy/perltidy) | Perl::Tidy, a source code formatter for Perl | `formatter` | `perl` |
| [pg_format](https://github.com/darold/pgformatter) | A PostgreSQL SQL syntax beautifier | `formatter` | `sql` |
| [php-cs-fixer](https://github.com/php-cs-fixer/php-cs-fixer) | A tool to automatically fix PHP Coding Standards issues | `formatter`, `linter` | `php` |
Expand Down Expand Up @@ -683,7 +684,7 @@ mdsf init

<!-- START_SECTION:supported-commands -->

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

| Name | Command |
| ---------------------------- | --------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -881,6 +882,7 @@ mdsf init
| `packer:fmt` | `packer fmt $PATH` |
| `packer:validate` | `packer validate $PATH` |
| `pasfmt` | `pasfmt $PATH` |
| `perflint` | `perflint $PATH` |
| `perltidy` | `perltidy -b $PATH` |
| `pg_format` | `pg_format --inplace $PATH` |
| `php-cs-fixer:fix` | `php-cs-fixer fix $PATH` |
Expand Down
12 changes: 12 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub mod packer_fix;
pub mod packer_fmt;
pub mod packer_validate;
pub mod pasfmt;
pub mod perflint;
pub mod perltidy;
pub mod pg_format;
pub mod php_cs_fixer_fix;
Expand Down Expand Up @@ -1869,6 +1870,14 @@ pub enum Tooling {
/// `pasfmt $PATH`
Pasfmt,

#[serde(rename = "perflint")]
/// Python Linter for performance anti patterns
///
/// [https://github.com/tonybaloney/perflint](https://github.com/tonybaloney/perflint)
///
/// `perflint $PATH`
Perflint,

#[serde(rename = "perltidy")]
/// Perl::Tidy, a source code formatter for Perl
///
Expand Down Expand Up @@ -3455,6 +3464,7 @@ impl Tooling {
packer_validate::IS_STDIN,
),
Self::Pasfmt => (&pasfmt::COMMANDS, pasfmt::set_args, pasfmt::IS_STDIN),
Self::Perflint => (&perflint::COMMANDS, perflint::set_args, perflint::IS_STDIN),
Self::Perltidy => (&perltidy::COMMANDS, perltidy::set_args, perltidy::IS_STDIN),
Self::PgFormat => (
&pg_format::COMMANDS,
Expand Down Expand Up @@ -4006,6 +4016,7 @@ impl AsRef<str> for Tooling {
Self::PackerFmt => "packer:fmt",
Self::PackerValidate => "packer:validate",
Self::Pasfmt => "pasfmt",
Self::Perflint => "perflint",
Self::Perltidy => "perltidy",
Self::PgFormat => "pg_format",
Self::PhpCsFixerFix => "php-cs-fixer:fix",
Expand Down Expand Up @@ -4366,6 +4377,7 @@ mod test_tooling {
assert_eq!(Tooling::PackerFmt, reverse(Tooling::PackerFmt)?);
assert_eq!(Tooling::PackerValidate, reverse(Tooling::PackerValidate)?);
assert_eq!(Tooling::Pasfmt, reverse(Tooling::Pasfmt)?);
assert_eq!(Tooling::Perflint, reverse(Tooling::Perflint)?);
assert_eq!(Tooling::Perltidy, reverse(Tooling::Perltidy)?);
assert_eq!(Tooling::PgFormat, reverse(Tooling::PgFormat)?);
assert_eq!(Tooling::PhpCsFixerFix, reverse(Tooling::PhpCsFixerFix)?);
Expand Down
49 changes: 49 additions & 0 deletions mdsf/src/tools/perflint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
///
/// THIS FILE IS GENERATED USING CODE - DO NOT EDIT MANUALLY
///
use crate::runners::CommandType;

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

pub const COMMANDS: [CommandType; 3] = [
CommandType::Direct("perflint"),
CommandType::Uv("perflint", "perflint"),
CommandType::Pipx("perflint"),
];

pub const IS_STDIN: bool = false;

#[cfg(test)]
mod test_perflint {
#[test_with::executable(perflint || pipx || uv)]
fn test_perflint_python_2a683a1c25614024() {
let input = r#"def add(a, b): return a + b"#;

let output = r#"def add(a, b): return a + b"#;

let file_ext = crate::fttype::get_file_extension("python");

let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");

let result = crate::tools::Tooling::Perflint
.format_snippet(
snippet.path(),
crate::testing::DEFAULT_TEST_FORMATTER_TIMEOUT,
crate::testing::DEFAULT_TEST_DEBUG_ENABLED,
&crate::config::MdsfConfigRunners::all(),
)
.expect("it to be successful")
.1
.expect("it to be some");

assert_eq!(result, output);
}
}
5 changes: 5 additions & 0 deletions schemas/development/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,11 @@
"type": "string",
"enum": ["pasfmt"]
},
{
"description": "Python Linter for performance anti patterns\n\n[https://github.com/tonybaloney/perflint](https://github.com/tonybaloney/perflint)\n\n`perflint $PATH`",
"type": "string",
"enum": ["perflint"]
},
{
"description": "Perl::Tidy, a source code formatter for Perl\n\n[https://github.com/perltidy/perltidy](https://github.com/perltidy/perltidy)\n\n`perltidy -b $PATH`",
"type": "string",
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.8.2-next/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,11 @@
"type": "string",
"enum": ["pasfmt"]
},
{
"description": "Python Linter for performance anti patterns\n\n[https://github.com/tonybaloney/perflint](https://github.com/tonybaloney/perflint)\n\n`perflint $PATH`",
"type": "string",
"enum": ["perflint"]
},
{
"description": "Perl::Tidy, a source code formatter for Perl\n\n[https://github.com/perltidy/perltidy](https://github.com/perltidy/perltidy)\n\n`perltidy -b $PATH`",
"type": "string",
Expand Down
25 changes: 25 additions & 0 deletions tools/perflint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "../tool.schema.json",
"binary": "perflint",
"categories": ["linter"],
"commands": {
"": {
"arguments": ["$PATH"],
"tests": [
{
"language": "python",
"test_input": "def add(a, b): return a + b",
"test_output": "def add(a, b): return a + b"
}
]
}
},
"description": "Python Linter for performance anti patterns",
"homepage": "https://github.com/tonybaloney/perflint",
"languages": ["python"],
"packages": {
"pip": {
"package": "perflint"
}
}
}
Loading