linters: Rewrite check-templates.

I rewrote most of tools/lib/pretty-printer.py, which
was fairly easy due to being able to crib some
important details from the previous implementation.

The main motivation for the rewrite was that we weren't
handling else/elif blocks correctly, and it was difficult
to modify the previous code. The else/elif shortcomings
were somewhat historical in nature--the original parser
didn't recognize them (since they weren't in any Zulip
templates at the time), and then the pretty printer was
mostly able to hack around that due to the "nudge"
strategy. Eventually the nudge strategy became too
brittle.

The "nudge" strategy was that we would mostly trust
the existing templates, and we would just nudge over
some lines in cases of obviously faulty indentation.

Now we are bit more opinionated and rigorous, and
we basically set the indentation explicitly for any
line that is not in a code/script block. This leads
to this diff touching several templates for mostly
minor fix-ups.

We aren't completely opinionated, as we respect the
author's line wrapping decisions in many cases, and
we also allow authors not to indent blocks within
the template language's block constructs.
This commit is contained in:
Steve Howell
2021-11-20 12:25:41 +00:00
committed by Tim Abbott
parent 4792af5682
commit fdd63546b2
27 changed files with 389 additions and 306 deletions

View File

@@ -192,12 +192,12 @@ BAD_HTML8 = """
GOOD_HTML8 = """
{{#each test}}
{{#with this}}
{{#if foobar}}
{{#if foobar}}
<div class="anything">{{{test}}}</div>
{{/if}}
{{#if foobar2}}
{{> teststuff}}
{{/if}}
{{/if}}
{{#if foobar2}}
{{> teststuff}}
{{/if}}
{{/with}}
{{/each}}
"""
@@ -325,9 +325,9 @@ GOOD_HTML13 = """
<div>&nbsp:{{this.name}}:</div>
{{else}}
{{#if this.is_realm_emoji}}
<img src="{{this.url}}" class="emoji" />
<img src="{{this.url}}" class="emoji" />
{{else}}
<br />
<br />
{{/if}}
{{/if}}
<div>{{this.count}}</div>
@@ -354,12 +354,12 @@ GOOD_HTML14 = """
{{#if this.code}}
<pre>Here goes some cool code.</pre>
{{else}}
<div>
content of first div
<div>
content of second div.
content of first div
<div>
content of second div.
</div>
</div>
</div>
{{/if}}
</div>
"""