collective / zpretty

A tool to format in a very opinionated way HTML, XML and text containing XML snippets.
https://pypi.org/project/zpretty/
Other
9 stars 5 forks source link

Why this one line tag with multiple attributes was changed? #12

Open idgserpro opened 5 years ago

idgserpro commented 5 years ago

From https://zopetoolkit.readthedocs.io/en/latest/codingstyle/zcml-style.html#attributes:

If all the attributes fit on one line with the tag name, do that:
<class class=".foo.Foo">

But as shown in https://github.com/plone/plone.api/issues/219#issuecomment-507805012:

 <!-- Set overrides folder for Just-a-Bunch-Of-Templates product -->
  <include package="z3c.jbot" file="meta.zcml" />

was changed to:

  <!-- Set overrides folder for Just-a-Bunch-Of-Templates product -->
  <include
      package="z3c.jbot"
      file="meta.zcml"
      />

Since "If all the attributes fit on one line with the tag name, do that" is already met, why the line was changed? I'm not sure if this is really a bug...

ale-rt commented 5 years ago

zpretty does always write one attribute per line which is in contrast with the zcml style. Probably having generally all the attributes on one line if they fit some reasonable length is a good idea, but for the moment I have no spare time to provide a patch for that.

idgserpro commented 5 years ago

Probably having generally all the attributes on one line if they fit some reasonable length is a good idea,

I think the length could follow zcml style itself:

If all the attributes fit on one line with the tag name, do that:

The ZCML style guide has been developed with the following qualities in mind:

Lines under 80 characters wherever possible
jensens commented 3 years ago

Given to have easy diffing support, I would keep them on single lines.

goyalyashpal commented 11 months ago

Given to have easy diffing support, I would keep them on single lines.

i was of similar opinions, unless i saw that it quickly becomes very difficult to read in an example like below. also, the opinionated black-formatter (aimed at easy diffing) for python does the same; till long-line if possible, else one per line

      <div class="collapse navbar-collapse" id="navbar">
          {% if session["user_id"] %}
          <ul class="navbar-nav me-auto mt-2">
            <li class="nav-item">
              <a class="nav-link" href="/quote">Quote</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/buy">Buy</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/sell">Sell</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/history">History</a>
            </li>
          </ul>
          <ul class="navbar-nav ms-auto mt-2">
            <li class="nav-item">
              <a class="nav-link" href="/logout">Log Out</a>
            </li>
          </ul>
          {% else %}
          <ul class="navbar-nav ms-auto mt-2">
            <li class="nav-item">
              <a class="nav-link" href="/register">Register</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/login">Log In</a>
            </li>
          </ul>
          {% endif %}
        </div>
jensens commented 11 months ago

Black allows some control here, the magic trailing comma: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#the-magic-trailing-comma