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 mago:lint:fix and mago:lint:fix:unsafe #825

Merged
merged 1 commit into from
Mar 10, 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
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.8.0...HEAD)

- refactor(tools): remove mago:fix command [`#824`](https://github.com/hougesen/mdsf/pull/824)
- test(tools): add tests for mago:lint and mago:format [`#823`](https://github.com/hougesen/mdsf/pull/823)
- test(runners): validate composer works [`#822`](https://github.com/hougesen/mdsf/pull/822)
- build(deps): bump serde from 1.0.218 to 1.0.219 [`#821`](https://github.com/hougesen/mdsf/pull/821)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ mdsf init

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

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

| Name | Command |
| ---------------------------- | --------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -836,6 +836,8 @@ mdsf init
| `luaformatter` | `lua-format -i $PATH` |
| `mado:check` | `mado check $PATH` |
| `mago:format` | `mago format $PATH` |
| `mago:lint:fix:unsafe` | `mago lint --fix --potentially-unsafe --unsafe $PATH` |
| `mago:lint:fix` | `mago lint --fix $PATH` |
| `mago:lint` | `mago lint $PATH` |
| `markdownfmt` | `markdownfmt -w $PATH` |
| `markdownlint-cli2` | `markdownlint-cli2 --fix $PATH` |
Expand Down
52 changes: 52 additions & 0 deletions mdsf/src/tools/mago_lint_fix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
///
/// 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("lint");
cmd.arg("--fix");
cmd.arg(file_path);
cmd
}

pub const COMMANDS: [CommandType; 2] =
[CommandType::PhpVendor("mago"), CommandType::Direct("mago")];

pub const IS_STDIN: bool = false;

#[cfg(test)]
mod test_mago_lint_fix {
#[test_with::executable(mago)]
fn test_mago_lint_fix_php_513b2cc3a1e145ed() {
let input = r#"<?php
echo 'Hello World!';
"#;

let output = r#"<?php
echo 'Hello World!';
"#;

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

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

let result = crate::tools::Tooling::MagoLintFix
.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);
}
}
54 changes: 54 additions & 0 deletions mdsf/src/tools/mago_lint_fix_unsafe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
///
/// 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("lint");
cmd.arg("--fix");
cmd.arg("--potentially-unsafe");
cmd.arg("--unsafe");
cmd.arg(file_path);
cmd
}

pub const COMMANDS: [CommandType; 2] =
[CommandType::PhpVendor("mago"), CommandType::Direct("mago")];

pub const IS_STDIN: bool = false;

#[cfg(test)]
mod test_mago_lint_fix_unsafe {
#[test_with::executable(mago)]
fn test_mago_lint_fix_unsafe_php_513b2cc3a1e145ed() {
let input = r#"<?php
echo 'Hello World!';
"#;

let output = r#"<?php
echo 'Hello World!';
"#;

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

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

let result = crate::tools::Tooling::MagoLintFixUnsafe
.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);
}
}
30 changes: 30 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ pub mod luaformatter;
pub mod mado_check;
pub mod mago_format;
pub mod mago_lint;
pub mod mago_lint_fix;
pub mod mago_lint_fix_unsafe;
pub mod markdownfmt;
pub mod markdownlint;
pub mod markdownlint_cli_2;
Expand Down Expand Up @@ -1529,6 +1531,22 @@ pub enum Tooling {
/// `mago lint $PATH`
MagoLint,

#[serde(rename = "mago:lint:fix")]
/// Fix linting errors found by mago lint
///
/// [https://mago.carthage.software/#/getting-started/cli?id=mago-lint](https://mago.carthage.software/#/getting-started/cli?id=mago-lint)
///
/// `mago lint --fix $PATH`
MagoLintFix,

#[serde(rename = "mago:lint:fix:unsafe")]
/// Fix unsafe linting errors found by mago lint
///
/// [https://mago.carthage.software/#/getting-started/cli?id=mago-lint](https://mago.carthage.software/#/getting-started/cli?id=mago-lint)
///
/// `mago lint --fix --potentially-unsafe --unsafe $PATH`
MagoLintFixUnsafe,

#[serde(rename = "markdownfmt")]
/// Like gofmt, but for Markdown
///
Expand Down Expand Up @@ -3277,6 +3295,16 @@ impl Tooling {
mago_lint::set_args,
mago_lint::IS_STDIN,
),
Self::MagoLintFix => (
&mago_lint_fix::COMMANDS,
mago_lint_fix::set_args,
mago_lint_fix::IS_STDIN,
),
Self::MagoLintFixUnsafe => (
&mago_lint_fix_unsafe::COMMANDS,
mago_lint_fix_unsafe::set_args,
mago_lint_fix_unsafe::IS_STDIN,
),
Self::Markdownfmt => (
&markdownfmt::COMMANDS,
markdownfmt::set_args,
Expand Down Expand Up @@ -3916,6 +3944,8 @@ impl AsRef<str> for Tooling {
Self::MadoCheck => "mado:check",
Self::MagoFormat => "mago:format",
Self::MagoLint => "mago:lint",
Self::MagoLintFix => "mago:lint:fix",
Self::MagoLintFixUnsafe => "mago:lint:fix:unsafe",
Self::Markdownfmt => "markdownfmt",
Self::Markdownlint => "markdownlint",
Self::MarkdownlintCli2 => "markdownlint-cli2",
Expand Down
10 changes: 10 additions & 0 deletions schemas/development/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,16 @@
"type": "string",
"enum": ["mago:lint"]
},
{
"description": "Fix linting errors found by mago lint\n\n[https://mago.carthage.software/#/getting-started/cli?id=mago-lint](https://mago.carthage.software/#/getting-started/cli?id=mago-lint)\n\n`mago lint --fix $PATH`",
"type": "string",
"enum": ["mago:lint:fix"]
},
{
"description": "Fix unsafe linting errors found by mago lint\n\n[https://mago.carthage.software/#/getting-started/cli?id=mago-lint](https://mago.carthage.software/#/getting-started/cli?id=mago-lint)\n\n`mago lint --fix --potentially-unsafe --unsafe $PATH`",
"type": "string",
"enum": ["mago:lint:fix:unsafe"]
},
{
"description": "Like gofmt, but for Markdown\n\n[https://github.com/shurcool/markdownfmt](https://github.com/shurcool/markdownfmt)\n\n`markdownfmt -w $PATH`",
"type": "string",
Expand Down
10 changes: 10 additions & 0 deletions schemas/v0.8.0-next/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,16 @@
"type": "string",
"enum": ["mago:lint"]
},
{
"description": "Fix linting errors found by mago lint\n\n[https://mago.carthage.software/#/getting-started/cli?id=mago-lint](https://mago.carthage.software/#/getting-started/cli?id=mago-lint)\n\n`mago lint --fix $PATH`",
"type": "string",
"enum": ["mago:lint:fix"]
},
{
"description": "Fix unsafe linting errors found by mago lint\n\n[https://mago.carthage.software/#/getting-started/cli?id=mago-lint](https://mago.carthage.software/#/getting-started/cli?id=mago-lint)\n\n`mago lint --fix --potentially-unsafe --unsafe $PATH`",
"type": "string",
"enum": ["mago:lint:fix:unsafe"]
},
{
"description": "Like gofmt, but for Markdown\n\n[https://github.com/shurcool/markdownfmt](https://github.com/shurcool/markdownfmt)\n\n`markdownfmt -w $PATH`",
"type": "string",
Expand Down
30 changes: 30 additions & 0 deletions tools/mago/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@
"test_output": "<?php\necho 'Hello World!';\n"
}
]
},
"lint:fix": {
"arguments": ["lint", "--fix", "$PATH"],
"description": "Fix linting errors found by mago lint",
"homepage": "https://mago.carthage.software/#/getting-started/cli?id=mago-lint",
"tests": [
{
"language": "php",
"test_input": "<?php\necho 'Hello World!';\n",
"test_output": "<?php\necho 'Hello World!';\n"
}
]
},
"lint:fix:unsafe": {
"arguments": [
"lint",
"--fix",
"--potentially-unsafe",
"--unsafe",
"$PATH"
],
"description": "Fix unsafe linting errors found by mago lint",
"homepage": "https://mago.carthage.software/#/getting-started/cli?id=mago-lint",
"tests": [
{
"language": "php",
"test_input": "<?php\necho 'Hello World!';\n",
"test_output": "<?php\necho 'Hello World!';\n"
}
]
}
},
"description": "A fast linter and formatter for PHP",
Expand Down
Loading