Stillat / blade-parser-typescript

A Laravel Blade parser, compiler, and static analyzer written in TypeScript.
https://stillat.com
MIT License
82 stars 2 forks source link

Space after directives with laravel Pint #98

Open devinvb opened 4 months ago

devinvb commented 4 months ago

Hi,

I'm running into a problem with formatting blade directives (space after), when using config "useLaravelPint": true,. If I run prettier on a single file it works, but if I run it for an entire folder it doesn't.

My .prettierrc config

{
    "singleQuote": true,
    "printWidth": 120,
    "tabWidth": 4,
    "plugins": ["prettier-plugin-blade", "prettier-plugin-tailwindcss"],
    "overrides": [
        {
            "files": ["*.blade.php"],
            "options": {
                "parser": "blade"
            }
        }
    ]
}

My .blade.format.json config

{
    "useLaravelPint": true,
    "spacesAfterDirective": 1,
    "spacesAfterControlDirective": 1,
    "phpOptions": {
        "singleQuote": true,
        "phpVersion": "8.2"
    },
    "attributeJsOptions": {
        "semi": true,
        "printWidth": 120
    }
}

My pint.json config

{
    "preset": "laravel",
    "rules": {
        "method_argument_space": true,
        "concat_space": {
            "spacing": "one"
        },
        "single_trait_insert_per_statement": true,
        "types_spaces": {
            "space": "single"
        }
    }
}

I have a test.blade.php file that looks like this:

@isset ($error)
    <p class="text-sm font-medium text-red-500">{{ $error }}</p>
@endisset

I want to keep the space after my blade directives.

Now when I run prettier on only the file: npx prettier resources/views/compontents/input/test.blade.php the space is there.

When I run prettier on the folder: npx prettier resources/views/components/input --write the space is removed.

When I set "useLaravelPint": false, the space is there when running prettier on either the file or the folder.

So the problem seems to be Laravel Pint removing the space, but only when running prettier on multiple files at once.

JohnathonKoster commented 4 months ago

Very interesting! I'll dig in later this week and see what I can find out 🤔