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

htmlWhitespaceSensitivity is not being taken into account #93

Open luveqz opened 7 months ago

luveqz commented 7 months ago

Problem

Even when I set the htmlWhitespaceSensitivity rule to strict, the plugin keeps turning this:

<p>
  me@example.com.
</p>

into this:

<p>
  me
  @example.com.
</p>

Or even this:

<img
  @class([
    // This is valid a comment.
    $coverUrl ? "object-center" :"object-left-top",
  ])
/>

into this:

<img
  @class([
    //Thisisvalidacomment.$coverUrl?"object-center":"object-left-top",
  ])
/>

Demo

Open this minimal StackBlitz demo and run:

npm run lint app.blade.php
JohnathonKoster commented 7 months ago

The plugin currently overrides this setting for a variety of reasons, and is a non-trivial thing to take into account at this time (https://github.com/Stillat/blade-parser-typescript/pull/91#issuecomment-1937077408).

The array directive item is a separate issue, not related to whitespace sensitivity that I'd look at separately (the Laravel Pint integration works correctly for this scenario, however).

JohnathonKoster commented 7 months ago

@luveqz

I've released v2.1.2 to help prevent the issue that wrecked your array input. If you're curious, it was caused by an internal workaround that prevents items like the following from being shoved to a single-line by prettier:

@props([
    'value',
    'value',
    'value',
    'value',
    'value',
])

This internal workaround was a bit too aggressive with what it was doing so I added a few checks to stop it from going into this logic.

Re. the htmlWhitespaceSensitivity setting, unfortunately this isn't available just yet. This does come up quite a bit though so I will start digging into it sometime this weekend (but may be a bit before its ready). Hope the array fix helps in the meantime!

claytonrcarter commented 7 months ago

I will start digging into it sometime this weekend

@JohnathonKoster ❤️ and if you would like some additional eyes or help, I would be happy to chip in. We have a number of templates that are mostly HTML w/ just a little Blade sprinkled here and there, so support for htmlWhitespaceSensitivity will be big improvement. I'm happy to help with testing your changes, once you have some! 😄

JohnathonKoster commented 5 months ago

Just an update that this is currently slated for the next major release of the plugin. Hopefully within the next few weeks 👍