Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Prettier to place inner text on new line without trailing >

I am using VScode for Vue development using Prettier and Eslint.

Currently, Prettier is formatting my code like this:

enter image description here

What I'd like is to force the following

enter image description here

If I manually change it to my wanted format it won't mark it as incorrect, but it also doesn't do this format by default.

Is there a way to accomplish this by default?

My relevant VScode Settings.json

"prettier.disableLanguages": ["json"],
  "[scss, css]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "vetur.validation.template": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.formatOnSave": true,
  "html.format.wrapAttributes": "force-aligned",
  "sync.gist": "30b867ce7d7d1360ee7bad0cf5599fc3",
  "sync.autoDownload": true,
  "sync.autoUpload": true,
  "sync.forceUpload": false,
  "sync.removeExtensions": false,
  "sync.quietSync": true,
  "[javascript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },

My .prettierrc settings

{
  "trailingComma": "none",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true
}

My eslintrc.js settings

extends: [
    'plugin:vue/recommended',
    'eslint:recommended',
    'prettier/vue',
    'plugin:prettier/recommended'
  ],
  plugins: ['vue', 'prettier'],
like image 902
Tim Titus Avatar asked May 23 '20 23:05

Tim Titus


People also ask

How can I prevent Prettier from taking multi line array to a single line?

Set the option in settings. Appending this line to the end of your settings. json file means Prettier will only wrap the line when it exceeds 1000 characters (essentially never). You can change this number to preference, for reference the default is 80 . Just make sure to save changes to the file and you are done!

Does Prettier use tabs or spaces?

(Tabs will be used for indentation but Prettier uses spaces to align things, such as in ternaries.)

How do I fix Prettier errors?

Try running npx prettier --write . on your project's directory. This command will tell prettier to fix simple errors (such as this one) when found. To prevent this error from happening again you can either set "end-of-line" to auto on your .


1 Answers

Adding this to the .prettierrc or .prettierrc.json file seems to fix this kind of issue:

"htmlWhitespaceSensitivity": "ignore"

Yours would look like this:

{
  "trailingComma": "none",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "htmlWhitespaceSensitivity": "ignore"
}

To understand better if this is a good solution for you, you can read about this topic: Whitespace-sensitive formatting

like image 71
Sam S Avatar answered Oct 02 '22 16:10

Sam S