Add Mago as task#1216
Conversation
veewee
left a comment
There was a problem hiding this comment.
Thanks for the PR.
I think this task in current state is not in line with other tasks. I've added some remarks inline in the code. Feel free to stat a discussion.
|
Hey @veewee, Thanks for taking the time to review the PR and share your feedback. To be fully transparent, after opening the PR I had already started reworking it to introduce 4 commands. I’ll update the PR this week with those changes; it should end up closer to how the SecurityChecker tasks are structured, which should resolve the three threads. If you have any additional feedback, feel free to share it so I can address everything at once. |
|
Hey, I just pushed a refactor splitting the The Happy to hear any feedback — whether on the option coverage, naming, documentation, or anything else that could be improved. |
|
Thanks for the changes. |
|
No worries |
| /** | ||
| * @extends AbstractExternalTask<ProcessFormatterInterface> | ||
| */ | ||
| class Mago extends AbstractExternalTask |
There was a problem hiding this comment.
Maybe better to have it abstract as wel? There is no such thing as a mago task
| class Mago extends AbstractExternalTask | ||
| { | ||
|
|
||
| public static function getConfigurableOptions(): ConfigOptionsResolver |
| return $context instanceof GitPreCommitContext || $context instanceof RunContext; | ||
| } | ||
|
|
||
| public function run(ContextInterface $context): TaskResultInterface |
| $resolver->setDefaults([ | ||
| 'retain-codes' => [], | ||
| 'ignore-baseline' => null, | ||
| 'fix' => null, |
There was a problem hiding this comment.
lets not add the fix option.
Rather use something like this:
grumphp/src/Task/PhpCsFixer.php
Lines 107 to 116 in 732a228
By default grumphp does dry-run.
When failed, it asks if you want it to be fixed or not (meaning it 'll run the fix command)
| 'reporting-target' => null, | ||
| 'minimum-report-level' => null, | ||
| 'minimum-fail-level' => null, | ||
| 'dry-run' => null, |
| $resolver = new OptionsResolver(); | ||
| $resolver->setDefaults([ | ||
| 'no-stubs' => null, | ||
| 'staged' => null, |
There was a problem hiding this comment.
does it make sense to have staged here?
We could possibly automatically do this during pre-commit and dont do it during run context?
That way we don't have to pass files ever.. Otherwise we'dd need to pass files during pre-commit.
| ]); | ||
|
|
||
| $resolver->addAllowedTypes('type', ['string']); | ||
| $resolver->addAllowedValues('type', ['default', 'dry-run', 'check', 'staged']); |
There was a problem hiding this comment.
lets not hide options behind a custom 'type'
|
|
||
| $resolver->addAllowedTypes('no-stubs', ['null', 'bool']); | ||
| $resolver->addAllowedTypes('checks', ['string']); | ||
| $resolver->addAllowedValues('checks', ['all', 'structural', 'perimeter']); |
There was a problem hiding this comment.
lets not hide options behind a custom 'checks'. make them bools.
| 'semantics' => null, | ||
| 'pedantic' => null, | ||
| 'only' => [], | ||
| 'staged' => null, |
There was a problem hiding this comment.
see previous feedback: lets make staged or not dependant of the context.
| ); | ||
| } | ||
|
|
||
| protected static function configureSharedOptions(OptionsResolver $resolver): void |
There was a problem hiding this comment.
are those options actually shared across all the commands in mago as well?
Because this could bite us if not. For example: see formatter tasks, which is not using the shared options.
This PR adds a Mago task
Mago is a recent tool that includes a formatter (like phpcs), a linter (like phpmd), and a static analyzer (like phpstan).
It is known for its performance and is starting to be increasingly adopted (for example, in Drupal).
Its integration into GrumPHP seems valuable.
New Task Checklist:
run()method readable?run()method using the configuration correctly?