Skip to content

Single Line Per Attribute not working properly in svelte files #318

@PeytonHanel

Description

@PeytonHanel

Problem
Single line per attribute is set to true in my project, but prettier only formats multi-attribute html lines when they are past the printWidth length. Prettier seems to work properly because I copied the exact same code into a normal HTML file and it worked as expected there.

Expected Behavior
When Single Line Per Attribute is true it should work exactly the same in svelte files as it does in normal html files.

Steps to Reproduce*
Copy this code into two files, one ending in .svelte and the other ending in .html

<div class="flex flex-col justify-center py-2 lg:h-[var(--hd)] lg:py-0">
    <button on:click="{toggleMenu}" class="btn btn-primary text-lg normal-case">
        Request a Quote
    </button>
</div>

Copy this code into your .prettierrc file

{
  "useTabs": false,
  "tabWidth": 2,
  "singleQuote": true,
  "trailingComma": "none",
  "printWidth": 100,
  "proseWrap": "preserve",
  "pluginSearchDirs": ["."],
  "semi": false,
  "singleAttributePerLine": true,
  "plugins": ["prettier-plugin-tailwindcss"],

  "overrides": [
    {
      "files": "*.svelte",
      "options": {
        "parser": "svelte",
        "svelteSortOrder": "options-scripts-styles-markup",
        "singleAttributePerLine": true
      }
    }
  ]
}

Put this in your package.json
"format": "prettier --write ."

I use yarn, so I run yarn run format from the command line. I get different results in the html and svelte files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions