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

How to achieve proper indentation for Twig method chaining? #87

Open
tsiatka opened this issue Nov 27, 2024 · 1 comment · May be fixed by #88
Open

How to achieve proper indentation for Twig method chaining? #87

tsiatka opened this issue Nov 27, 2024 · 1 comment · May be fixed by #88
Labels
Feature: Request Printer Logic related on how to print the output

Comments

@tsiatka
Copy link

tsiatka commented Nov 27, 2024

When formatting Twig files using Prettier with the prettier-plugin-twig, I'm having trouble achieving the desired indentation for method chaining within a href attribute. Currently, the methods are not placed on new lines in a way that I find readable.

Here is the formatting result I get after using Prettier:

<a class="task-edit"
    href="{{
        ea_url().setDashboard(
            'App\\Controller\\Dashboard\\DashboardController'
        ).setController(
            'App\\Controller\\Dashboard\\CRUD\\TacheCrudController'
        ).setAction(
            'edit'
        ).setEntityId(
            tache.id
        ).set(
            'sort',
            null
        )
    }}">
    <i class="fa-solid fa-edit"></i>
</a>

Expected Behavior :
I would like the formatter to break lines properly, with each method in the chain starting on a new line for better readability, as shown below:

<a class="task-edit"
    href="{{
        ea_url()
            .setDashboard('App\\Controller\\Dashboard\\DashboardController')
            .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController')
            .setAction('edit')
            .setEntityId(tache.id)
            .set('sort', null)
    }}">
    <i class="fa-solid fa-edit"></i>
</a>

Here is my current Prettier configuration:

{
  "plugins": ["prettier-plugin-twig"],
  "twigAlwaysBreakObjects": true,
  "twigMultiLineObjects": true,
  "printWidth": 80,
  "tabWidth": 4,
  "useTabs": false
}

Is this the expected behavior or am I misusing the plugin or Prettier's configuration? I suspect I may not fully understand how to configure Prettier or the plugin correctly to achieve my desired result.

I really appreciate the work you've done on this plugin! Thank you for your time! 😊

@zackad
Copy link
Owner

zackad commented Nov 27, 2024

I don't think there's option to configure this plugin to achive your desired result. We have limited option to configure this plugin, and I want to keep it that way.

Fixing function argument to print in a single line might be easy. But I'm not sure how to achive subsequent method chain to be indented and on different line. Need time to investigate.

Maybe I can add some "experimental" feature or option that people can try and then gradually implement it as "official" style for this plugin.

@zackad zackad added the Printer Logic related on how to print the output label Nov 27, 2024
@zackad zackad linked a pull request Nov 28, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Request Printer Logic related on how to print the output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants