Skip to content

Releases: zackad/prettier-plugin-twig

v0.14.0

18 Dec 04:00
v0.14.0
Compare
Choose a tag to compare

Bugfixes

  • GH-90 Properly implement bracketSameLine options for html element tag

Input

<iframe class=""
        src="https://www.google.com/maps/embed"
        frameborder="0"
        allowfullscreen></iframe>

<img src="/public/logo.png" alt="some description that should be enough to break this into multiline" class="block bg-white border radius-lg"/>
<img src="/public/logo.png" class="block bg-white border radius-lg"/>
<a href="/homepage" class="block bg-white border radius-lg" aria-label="some text label">some text</a>

<br />

bracketSameLine: true

<iframe
    class=""
    src="https://www.google.com/maps/embed"
    frameborder="0"
    allowfullscreen></iframe>

<img
    src="/public/logo.png"
    alt="some description that should be enough to break this into multiline"
    class="block bg-white border radius-lg" />
<img src="/public/logo.png" class="block bg-white border radius-lg" />
<a
    href="/homepage"
    class="block bg-white border radius-lg"
    aria-label="some text label">
    some text
</a>

<br />

bracketSameLine: false

<iframe
    class=""
    src="https://www.google.com/maps/embed"
    frameborder="0"
    allowfullscreen
></iframe>

<img
    src="/public/logo.png"
    alt="some description that should be enough to break this into multiline"
    class="block bg-white border radius-lg"
/>
<img src="/public/logo.png" class="block bg-white border radius-lg" />
<a
    href="/homepage"
    class="block bg-white border radius-lg"
    aria-label="some text label"
>
    some text
</a>

<br />
  • GH-101 Fix printing some html tags to be on their own line (heading and table cell)
  • GH-106 Fix handling string literal when using block shortcut syntax

Internals

  • Add option to add prefix/suffix for test snapshot output. This will allow to reuse single input file to produce several snapshot output with different configuration

Full Changelog: v0.13.0...v0.14.0

v0.13.0

09 Dec 04:02
v0.13.0
Compare
Choose a tag to compare

Features

Bugfixes

  • Fix indentation for html attribute when printed on multiline. All attribute will be indented on each line.

Input

<iframe class=""
    src="https://www.google.com/maps/embed"
    frameborder="0"
    allowfullscreen></iframe>

Output

- <iframe class=""
+ <iframe
+     class=""
      src="https://www.google.com/maps/embed"
      frameborder="0"
      allowfullscreen></iframe>

Internals

  • Remove unused dependencies resolve

Full Changelog: v0.12.0...v0.13.0

v0.12.0

22 Nov 07:11
v0.12.0
Compare
Choose a tag to compare

Important

Yet another breaking changes. See release notes or changelog before upgrading.

BREAKING CHANGES

  • Option twigPrintWidth has been removed

I don't see any reason why we should keep the option twigPrintWidth. Prettier provide mechanism to use different printWidth for different file types by using override (see example below).

What to do?

Remove twigPrintWidth from your prettier config and use override instead.

Example

  # .prettierrc.yaml
- twigPrintWidth: 120
+ overrides:
+   - files: "*.twig"
+     options:
+       printWidth: 120

Features

  • Add support for spread operator

Example

<twig:Component {{ ...vars }} />

{% set numbers = [1, 2, ...moreNumbers] %}
{% set ratings = {'q1': 10, 'q2': 5, ...moreRatings} %}

{{ 'Hello %s %s!'|format(...['Fabien', 'Potencier']) }}

Bugfixes

  • Make sure that empty block statement will have empty line in between for consistency

Full Changelog: v0.11.1...v0.12.0

v0.11.1

12 Nov 22:56
v0.11.1
Compare
Choose a tag to compare

Bugfixes

  • Fix handling empty string as default value on macros declaration

Full Changelog: v0.11.0...v0.11.1

v0.11.0

12 Nov 07:01
v0.11.0
Compare
Choose a tag to compare

Important

Twig coding standard has been updated to version 3.x. This contains BREAKING CHANGES.

BREAKING CHANGES

This release contains breaking changes, check your setup before upgrading.
Option twigFollowOfficialCodingStandards is set to true by default. If you're
using twig version 3.11 or older it will break your setup. Notable changes on
twig coding standard on version 3.x is added support for using colon : as separator
for argument names and values (which is enabled by default with this plugin).

Example

{# Input #}
{{ data|convert_encoding(from= 'iso-2022-jp', to: 'UTF-8') }}

{# Before #}
{{ data|convert_encoding(from = 'iso-2022-jp', to = 'UTF-8') }}

{# After #}
{{ data|convert_encoding(from: 'iso-2022-jp', to: 'UTF-8') }}

What to do?

  • If you want to upgrade this plugin, make sure that you're using twig version 3.12 or later
  • If you want to keep using older version of twig, you can set option twigFollowOfficialCodingStandards to false (your code style might become inconsistent)

Features

  • BREAKING CHANGES: Update twig coding standard to follow version 3.x

Full Changelog: v0.10.0...v0.11.0

v0.10.0

11 Nov 04:27
v0.10.0
Compare
Choose a tag to compare

Features

  • Add support for default value on macros
  • Add support for test expression instance of, feature of Craft CMS
  • Add support for colon as separators between argument names and values

Internals

  • Test with Node.js 22, current active lts version
  • Add smoke test to make sure that the plugin can be loaded properly

Full Changelog: v0.9.1...v0.10.0

v0.9.1

10 Oct 07:22
v0.9.1
Compare
Choose a tag to compare

Bugfixes

  • Fix importing lodash function syntax
  • Fix import template function from @babel/template

Full Changelog: v0.9.0...v0.9.1

v0.9.0

03 Oct 02:53
v0.9.0
Compare
Choose a tag to compare

Features

  • Add support for three-way-comparison operator (spaceship operator)

Bugfixes

  • Fix handling mapping that omit key part
  • Fix documentation about twigAlwaysBreakObjects option to reflect actual default value
  • Fix autoescape block which allow boolean value (true and false) as a valid escape type

Internals

  • Make key part of ObjectProperty type optional to support object declaration that omit key part

Full Changelog: v0.8.0...v0.9.0

v0.8.0

09 Aug 02:59
v0.8.0
Compare
Choose a tag to compare

Features

  • Add support for arrow function inside filter, map, reduce filter by @jannisborgers in #42

Internals

  • Optimize test runner by defining where to look for test files by @zackad in #46
  • NPM script alias to run prettier has been removed by @zackad in #47

New Contributors

Full Changelog: v0.7.0...v0.8.0

v0.7.0

01 Aug 04:08
v0.7.0
Compare
Choose a tag to compare

BREAKING CHANGES

  • Drop compatibility support for prettier 2
  • Plugin system has been removed from this project
  • Package has been renamed @zackad/prettier-plugin-twig-melody -> @zackad/prettier-plugin-twig
  • The parser has been renamed from melody into twig

Features

  • Add support attribute names according to html5 specs

Internals

  • Remove npm script to publish
  • Integrate devenv into nix flakes
  • Incorporate switch-plugin into core functionality
  • Replace jest with vitest as test runner

New Contributors

Full Changelog: v0.6.0...v0.7.0