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

Support custom fixers #290

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

Riley19280
Copy link

@Riley19280 Riley19280 commented Aug 1, 2024

Many times the community has asked for custom rules to be supported (#23, #26, #55, #161, #239, #286).
With so many people persistently asking for this feature, I believe that it should finally be adopted.

The entire purpose of Pint is to be extremely opinionated with minimal configuration.
Originally posted by taylorotwell in #161 (comment)

While Pint does a great job at being extremely opinionated, it doesn't close off the ability for those opinions to be customized, allowing for presets to be extended, and also including presets for other frameworks such as Symfony.

Support for custom fixers is similar to providing support for customizing rules, letting the end user fine tune their configuration to their needs and opinions.

Many of us Laravel Enthusiasts would like to use the benefits that Pint and the Laravel ecosystem provides, without having to fork the package or use the underlying dependency just to make a configuration change.

I am happy to PR the docs update as well if this moves forward 🙂

(Also thanks to @devatreides for all the hard work in #161, which this heavily borrows from)

@Jubeki
Copy link
Contributor

Jubeki commented Aug 4, 2024

What would happen if the custom fixer uses a class outside the imported custom fixer file?

I think currently it would only be possible if the Custom Fixer only relies on PHP-CS-Fixer Classes and doesn't import any other class that is not compiled in the Pint.

I would like to try confirm that, but that is only possible after the binary is build.

@Riley19280
Copy link
Author

Riley19280 commented Aug 5, 2024

What would happen if the custom fixer uses a class outside the imported custom fixer file?

I think currently it would only be possible if the Custom Fixer only relies on PHP-CS-Fixer Classes and doesn't import any other class that is not compiled in the Pint.

I would like to try confirm that, but that is only possible after the binary is build.

In order to reference additional classes that are not the fixer (Ex. utilities), you would have to manually require_once that file

Additionally, if you just wanted to load everything that normally gets autoloaded you could do this in the custom fixer:

public function __construct() {
    require_once "vendor/autoload.php";
}

@Aferz
Copy link

Aferz commented Oct 5, 2024

Hey, any progress on this? I saw it was marked as draft by Taylor.

Anything we can do to move this forward?

@yusufkandemir
Copy link

yusufkandemir commented Oct 26, 2024

One use case I've needed was Prettier. Laravel Pint VS Code extension (and PHP CS Fixer one) is structured as a formatter. It's not possible to use multiple formatters for a single file type in VS Code. So, one solution I could find is creating a custom fixer that executes Prettier. This way, the default formatter for PHP files will be Pint, which will then execute Prettier as part of PHP CS Fixer: https://github.com/prettier/plugin-php/tree/main/docs/recipes/php-cs-fixer

I think Prettier support can even be a new feature that can be implemented from the Prettier logic in #256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants