- GH-131 Improve formatting for
propstags, feature of twig component anonymous component
- GH-127 Fix missing
ignore missingpart of include statement
- GH-125 Add missing
xorbinary operator
- GH-123 Fix parsing negative number
- GH-61 Add support for twig comment as html element attribute
- GH-116 Add possibility to register any custom Twig test expression
- Fix broken embed statement with
onlymodifier
- Stringify ast object to make it easier to inspect when debugging on test setup
- GH-110 Fix regression when parsing concatenation expression inside html attribute value
- DX: Don't use alias to export print function to make it easier to identify when debugging call stack
- GH-90 Properly implement
bracketSameLineoptions 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
- 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
- Add support for empty coalesce operator, a CraftCMS extension
- 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>- Remove unused dependencies
resolve
Important
Yet another breaking changes. See release notes or changelog before upgrading.
- Option
twigPrintWidthhas 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- 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']) }}- Make sure that empty block statement will have empty line in between for consistency
- Fix handling empty string as default value on macros declaration
Important
Twig coding standard has been updated to version 3.x. This contains 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
twigFollowOfficialCodingStandardsto false (your code style might become inconsistent)
- BREAKING CHANGES: Update twig coding standard to follow version 3.x
- 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
- Test with Node.js 22, current active lts version
- Add smoke test to make sure that the plugin can be loaded properly
- Fix importing lodash function syntax
- Fix import template function from
@babel/template
- Add support for three-way-comparison operator (spaceship operator)
- Fix handling mapping that omit key part
- Fix documentation about
twigAlwaysBreakObjectsoption to reflect actual default value - Fix autoescape block which allow boolean value (
trueandfalse) as a valid escape type
- Make
keypart ofObjectPropertytype optional to support object declaration that omit key part
- Add support for arrow function inside
filter, map, reducefilter
- Optimize test runner by defining where to look for test files
- NPM script alias to run
prettierhas been removed
- 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
melodyintotwig
- Add support attribute names according to html5 specs
- Remove npm script to publish
- Integrate devenv into nix flakes
- Incorporate
switch-plugininto core functionality - Replace
jestwithvitestas test runner
- BREAKING: Change package name
prettier-plugin-twig-melody->@zackad/prettier-plugin-twig-melody
- Publish package as
@zackad/prettier-plugin-twig-melodyinto npm registry
- BREAKING: Drop compatibility with prettier lower than 2.3.0. Use version 0.4.6 if you need to use prettier older than 2.3.0
- Fix compatibility with prettier 3
- Add CI configuration for github actions
- Add support for devenv.sh, nix based tools to manage development environment
- Explicitly declare prettier configuration as yaml file
- Fix eslint configuration to support ECMAScript 2017, allowing
asyncfunction - Fix license name to use valid SPDX
- Remove deprecated function usage of
concatfromprettier.doc.builders. Enforce this policy with eslint plugineslint-plugin-prettier-docusingprettier-doc/no-concatrule. - Upgrade devDependencies to latest compatible version
- Bug fix: Leave parentheses in place in
'classA' ~ (not needsB ? ' classB')
- Bug fix (Melody): Whitespace trimming information was lost when using a conditional expression
- Bug fix: Expand the list of HTML tags treated as "inline"
- Bug fix: Filter expression was not correctly interpolated in a string
- Bug fix: Remove hard-coded space at the beginning of Twig comments
- Bug fix: Preserve leading (non-newline) whitespace in inline IF statement body
- Fix issue #1: Non-standard (custom) Twig tags don't make the parser crash any more, and receive at least some default printing. Complex tags can be configured using the
twigMultiTagsoption.
- Fix issue #32: Curly braces around a binary expression were lost when they were in fact needed.
- Bug fix/optimization: ArrayExpression was causing too many newlines
- Bug fix: Filter target was losing parentheses, which was altering the meaning (e.g., conditional expression)
- Bug fix: Expressions like
not (a and b)lost the parentheses, thus changing the meaning of the expression.
- Bug fix: Optimize group structure when using
SetStatement,VariableDeclarationStatement, and logical binary expressions. Previously, the group created bySetStatementhad only one breaking point (before the closing%}), which led to some undesirable results.
- Fix:
twigMelodyPluginsoption is finally an array, not a string separated by|any more.
- Fix: Stylistic improvements
- Bug fix: Mount statement of the form
mount ... from ...were dropping the source. Fixed now.
- Bug fix: No breaking point before closing
%}forfor,if,set.
- Issue #24: Take the string contents into account when choosing the quote characters surrounding a string literal.
- Issue #22: Add
twigOutputEndblockNameoption so that you can choose whether to print the name in the{% endblock %}tag or not.
- Issue #21: Always use double quotes around interpolated strings
- Improve printing of HTML and Twig comments
- Introduction of
prettier-ignorefunctionality - Better adherence to Twig coding standards
- Avoid dropping of backslash in string literal: trivago#11
- Not crashing when facing declarations (
<!DOCTYPE html>) any more
- Avoid extraneous line breaks for zero-argument call expressions: trivago#10
- "If" statements can be in one line now, under certain circumstances
- New option
twigAlwaysBreakObjects - New option
twigPrintWidth - All util functions are public now (available to plugins)
- Optimizations: Fewer line breaks in a lot of cases, less indentation
- Long HTML comments are re-wrapped now
- Respect operator precedence in binary expressions (especially boolean)
Various small bug fixes and cosmetic optimizations
- Empty block was causing an error. Does not an more.
- Uses Melody 1.5.0
- Trim left and trim right marks are preserved for Twig tags
{%- ... -%}
- Uses Melody 1.4.0
- Whitespace trimming is now suppressed
- Trim left and trim right marks are preserved for expressions
{{- ... -}}
- MacroDeclarationStatement: There was an extraneous space after the opening parenthesis
- Plugin loading: project root path was not always correctly determined
- Make use of new
melody-parsercapabilities:- Add comment printing
- Pass parser option to leave character entities undecoded
- Preserve HTML comments
- Fix issue #2, where all final newlines in a file were skipped. Now, there will be one final newline.
- Fix attribute printing in objects. Computed attributes are now surrounded by
(...). Keys that don't need quotes will not be quoted.