Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Formatter] object/array variable whitespace is removed #370

Closed
3 tasks done
tomdavies opened this issue Sep 7, 2022 · 7 comments
Closed
3 tasks done

[BUG] [Formatter] object/array variable whitespace is removed #370

tomdavies opened this issue Sep 7, 2022 · 7 comments
Labels
🔍 linter 🦠 bug Something isn't working released

Comments

@tomdavies
Copy link

tomdavies commented Sep 7, 2022

System Info

  • OS: macOD 12.5.1
  • Python Version 3.10.6
  • djLint Version 1.12.2
  • template language: e.g. Twig

Issue

All whitespace is removed from multi-line {% set = {} %} statements (e.g when declaring a nested object), and also from object function parameters formatted in the same way.

How To Reproduce

Given the input:

{% set foo = {
  bar: {
    baz: {
      cux: 1
    }
  }
} %}

{% set fruit = [
  'Apples', 
  'Pears',
  'Bananas'
] %}

{{ myfunc({
  bar: {
    baz: {
      cux: 1
    }
  }
})

I get the output

{% set foo = {
bar: {
baz: {
cux: 1
}
}
} %}
{% set fruit = [
'Apples',
'Pears',
'Bananas'
] %}
{{ myfunc({
bar: {
baz: {
cux: 1
}
}
})

When I expect indentation to be applied to the keys/values in my variable declarations per my .djlintrc:

{
  "extension": "twig",
  "profile": "nunjucks"

}

Thanks so much for your work on djLint!

@tomdavies tomdavies added 🔍 linter 🦠 bug Something isn't working labels Sep 7, 2022
@christopherpickering
Copy link
Contributor

similar case as #287

@oliver-schulz
Copy link

Hello we have the same problem here when using djlint with the same configuration. Is there a way to exclude theses from linting through the config file?

Before:

<div class="w-full">
  {{
    sylius_template_event(
      'sylius.shop.cart.summary',
      {
        cart: cart
      }
    )
  }}
</div>

After:

<div class="w-full">
    {{
    sylius_template_event(
    'sylius.shop.cart.summary',
    {
    cart: cart
    }
    )
    }}
</div>

@christopherpickering
Copy link
Contributor

@oliver-schulz sorry I missed the question about excluding. If you didn't already find it, you can do it like:

<div class="w-full">
    {# djlint:off #}
    {{
    sylius_template_event(
        'sylius.shop.cart.summary',
        {
        cart: cart
        }
    )
    }}
    {# djlint:on #}
</div>

@christopherpickering
Copy link
Contributor

Link to twig expressions: https://twig.symfony.com/doc/3.x/templates.html#expressions

christopherpickering pushed a commit that referenced this issue May 8, 2023
## [1.25.1](v1.25.0...v1.25.1) (2023-05-08)

### Bug Fixes

* **js indent:** fixed an issue where literal strings were double indented ([b1e8ab2](b1e8ab2)), closes [#614](#614)
* **set:** added formatting of json/list style set contents ([85aca4c](85aca4c)), closes [#287](#287) [#518](#518) [#370](#370)
@christopherpickering
Copy link
Contributor

@tomdavies @oliver-schulz thanks for waiting on this, the next release will fix both examples you provide :)

Just noting in @tomdavies there was a typo, the closing }} were missing. I assumed it was an accident and made djlint format only full tags ;)

@tomdavies
Copy link
Author

Thanks @christopherpickering much appreciated! Will check this out. And yes, that was a typo in my crumby example code 😄

christopherpickering pushed a commit that referenced this issue May 18, 2023
# [1.28.0](v1.27.2...v1.28.0) (2023-05-18)

### Bug Fixes

* **formatter:** allow djlint:off to exluce the rest of a file ([17faf5f](17faf5f)), closes [#649](#649)
* **formatter:** don't add blank line to empty files ([8ea5fd2](8ea5fd2)), closes [#635](#635)

### Features

* **formatter:** added ability to format objects/arrays in function tags ([d446efc](d446efc)), closes [#370](#370)
* **formatter:** format set blocks ([d88371c](d88371c)), closes [#646](#646)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.28.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 linter 🦠 bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

3 participants