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: svelte pug formatting #201

Closed
basaran opened this issue Apr 21, 2021 · 5 comments · Fixed by #204
Closed

Bug: svelte pug formatting #201

basaran opened this issue Apr 21, 2021 · 5 comments · Fixed by #204
Assignees
Labels
framework: Svelte Related to the framework Svelte type: bug Functionality that does not work as intended/expected

Comments

@basaran
Copy link
Collaborator

basaran commented Apr 21, 2021

Info

Tool Version
Plugin v1.13.5
Prettier v2.2.1
Framework svelte
Node v15.4
OS wsl

Additional Context

In reference to sveltejs/language-tools#951 please find the basic repository below.

https://github.com/basaran/svelte-pug

Additional information has been provided in the readme.md for setting up the environment.

@Shinigami92 Shinigami92 self-assigned this Apr 21, 2021
@Shinigami92 Shinigami92 added framework: Svelte Related to the framework Svelte type: bug Functionality that does not work as intended/expected labels Apr 21, 2021
@dummdidumm
Copy link

dummdidumm commented Apr 21, 2021

This reproduction will not work for Svelte files because right now prettier-plugin-svelte which formats Svelte files completely skips formatting the pug template part. I will play around with removing that limitation in the next few days. Until then, for reproduction, it is best to focus on the parts inside <template lang="pug">. You might copy the stuff inside out of there and see how it is formatted with prettier-pug.

The eslint problem is unrelated, more info here sveltejs/prettier-plugin-svelte#57

@Shinigami92
Copy link
Member

Thanks, I already saw that it seems that svelte uses single braces, e.g. {name}

This may currently not work in my plugin and I will need to fix that

@basaran
Copy link
Collaborator Author

basaran commented Apr 21, 2021

It seems the language functions are prefixed with + when inside the pug template. You can replace the App.svelte with this.

Things appear to formatting just fine.

<script>
export let name;
export let cats = [
    {id: 'J---aiyznGQ', name: 'Keyboard Cat'},
    {id: 'z_AbfPXTKms', name: 'Maru'},
    {id: 'OUtn3pvWmpg', name: 'Henri The Existential Cat'},
];
export let user = {
    loggedIn: false,
};
export let toggle = () => {
    console.log('toggled');
};
</script>

<template lang="pug">
main
    h1 Hello {name}!
    p
        | Visit the
        a(href='https://svelte.dev/tutorial')
            | Svelte tutorial
            | to learn how to build Svelte
            | apps.
    p
        +each('cats as cat')
            a(href='{cat.id}') {cat.name}
            | !{' '}

    p
        +if('!user.loggedIn')
            button(on:click='{toggle}')
                | Log out
</template>

@Shinigami92
Copy link
Member

The + prefixed tags will be just recognized as pug-mixins https://pugjs.org/language/mixins.html

I don't know if I will have time today, tomorrow or at very least over weekend

@basaran
Copy link
Collaborator Author

basaran commented Apr 21, 2021

Sure thing. Meanwhile, I will keep reading the docs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework: Svelte Related to the framework Svelte type: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants