Skip to content

Prettier formatting issues with blade templates #122

@anirbantegit

Description

@anirbantegit

When using prettier-plugin-blade to format Blade templates (.blade.php files), the following issues occur:

  1. JavaScript inside Blade templates gets incorrectly formatted

    • Inline JavaScript with Blade directives (e.g., @lang()) gets broken.
    • Prettier introduces unwanted line breaks or removes quotes, causing syntax errors.
  2. Trailing commas and indentation issues

    • Arrays, function arguments, and parameters do not respect the "trailingComma": "all" setting.
    • Indentation inside Blade @foreach, @if, and @section structures sometimes gets inconsistent.
  3. Prettier conflicts with ESLint in Blade files

    • Running eslint --fix on Blade templates causes additional unintended formatting.
    • eslint-plugin-html does not recognize Blade directives, leading to parsing errors.

================

.prettierrc.json

{
"trailingComma": "all",
"singleQuote": true,
"semi": true,
"tabWidth": 4,
"plugins": ["prettier-plugin-blade"],
"overrides": [
{
"files": "*.blade.php",
"options": {
"parser": "blade"
}
}
]
}

Sample blade -

<script> let a = "@lang('global.resend_available_in')"; var b = 60; </script>

===================

Expected Behavior
Inline JavaScript inside Blade templates should remain correctly formatted.
Blade directives should not be broken or reformatted incorrectly.
The trailingComma rule should apply consistently across Blade files.

Actual Behavior
Prettier introduces syntax-breaking changes to inline JavaScript.
Some Blade directives get incorrectly modified or removed.
Prettier and ESLint conflict, leading to unwanted formatting changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions