trivago / prettier-plugin-twig-melody

Code formatting plugin for Prettier which can handle Twig/Melody templates
Apache License 2.0
155 stars 35 forks source link

How to prevent attribute wrapping? #67

Open kareljan opened 3 years ago

kareljan commented 3 years ago

How can I prevent the attributes to wrap to new lines?

<div class="fancy-stuff" id="element{{ loop.index }}"> gets

<div class="fancy-stuff"
          id="element{{ loop.index }}">

I don't want the ID to wrap to a new line.

kareljan commented 3 years ago

anyone?

mubaraqwahab commented 3 years ago

You can use {# prettier-ignore #} above that line.

kareljan commented 3 years ago

That's not an option. I want to disable it for the entire file. It puts every attribute of every line on new lines. If I put prettier-ignore on the entire file,the purpose of prettier is gone.

mubaraqwahab commented 3 years ago

I tried the snippet isolated and it didn't break (with the default proseWidth). When it's nested however:

<div>
  <div>
    <div>
      <div>
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div>
                      <div class="fancy-stuff" id="element{{ loop.index }}"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

It breaks like you have mentioned:

<div class="fancy-stuff"
  id="element{{ loop.index }}"></div>

I'm assuming you have something like this.

Prettier's own HTML formatter pretty prints it when it's nested deeply like so:

<div
  class="fancy-stuff"
  id="element{{ loop.index }}"
></div>

If you would prefer Prettier's own formatting, I wrote a plugin for this Twig plugin that you can check out: prettier-plugin-twig-enhancements

kareljan commented 3 years ago

No I just want to keep all attributes on one line like so

<div class="fancy-stuff" id="element{{ loop.index }}">

mubaraqwahab commented 3 years ago

Sorry I don't know how then.

kareljan commented 3 years ago

anyone?