NiklasPor / prettier-plugin-organize-attributes

Organize your HTML attributes automatically with Prettier 🧼
MIT License
197 stars 12 forks source link

Add support for Lit's `html` template literals #23

Closed JulianCataldo closed 8 months ago

JulianCataldo commented 8 months ago

Hello, thanks for making this neat plugin :) Tested it on bare HTML, works awesome!

I'd like to know if there is anyway to format attributes inside html templates literals, from Lit Custom Elements specifically.

Prettier is already taking effect for me here, without additional configuration (AFAIK), following the .prettierrc

Sample of what can be sorted:

render() {
        return html`
            <sl-card>
                <sl-button-group>
                    <sl-button
                        class=${classMap({
                            'stop-button': true,
                            'is-stopped': kl.currentTime === 0,
                        })}
                        pill
                        size="large"
                        @click=${() => kl.stop()}
                    >
                        <sl-icon name=${'stop-fill'}></sl-icon>

// ...

Not strictly related, but this: https://github.com/43081j/postcss-lit is allowing Stylelint to handle css template literals, useful for CSS-in-JS folks too, I guess.

JulianCataldo commented 8 months ago

Mhhh, nevermind. I can confirm it works inside html template literals with VS Code.

However, I'll try to build a Lit preset which can prove to be useful when using, e.g. .href versus href, @mousedown, etc. A bit like the Angular one., with ideas from the Code Guide.

Thanks again. Cya