DynamoKat21's avatar

Weird formating with laravel 12 and pint

I'm creating a simple app with laravel 12, and I was writing the first tests, and I relized the pint does a weird formating.

it('Requires authentication ', function () {
get(route('dashboard'))->assertRedirect(route('login'));
    });

In my previous app with laravel 11 app, pint formats the same code like this. Wich I personally find way better.

it('requires authentication', function () {
    get(route('posts.create'))->assertRedirect(route('login'));
});

Is this a bug, or just a change on the default style?

1 like
2 replies
LaryAI's avatar
Level 58

In Laravel 12, the behavior you're observing with Pint is likely due to changes in the default code style configuration. Pint is a code formatting tool that adheres to a set of predefined rules, and these rules can change between versions to align with evolving best practices or community preferences.

To address your issue, you have a couple of options:

  1. Customize Pint Configuration: You can customize the Pint configuration to match your preferred style. Pint uses a .pint.json file to define its rules. You can create or modify this file in the root of your project to specify your desired formatting rules.

    Here's an example of how you might configure Pint to adjust the formatting:

    {
        "preset": "laravel",
        "rules": {
            "method_argument_space": {
                "on_multiline": "ensure_fully_multiline"
            },
            "single_quote": true,
            "lowercase_keywords": true
        }
    }
    

    Adjust the rules as needed to achieve the formatting style you prefer.

  2. Check for Updates or Changes: Review the release notes or documentation for Laravel 12 and Pint to see if there are any mentions of changes to the default formatting rules. This can provide insight into why the formatting behavior has changed.

  3. Revert to Previous Version: If the new formatting style is not acceptable and you prefer the previous behavior, you could consider reverting to the version of Pint used in Laravel 11. However, this is generally not recommended as it may lead to compatibility issues with other tools or libraries.

By customizing the Pint configuration, you can regain control over the formatting style to better suit your preferences.

1 like
ChrisToxz-28065282's avatar

Having the same issue, but just found out a issue is open for this matter. #354

1 like

Please or to participate in this conversation.