Prettier in VS Code formatting (new lines before arguments)
Asked Answered
P

1

10

I'm using Angular Essentials by John Papa - in particular, Tslint and Prettier. For some reason, it transforms this code

this.rM.hA = this.rM.startHA + 2 * diffX * 360 / size;
this.rM.vA = Math.max(Math.min(this.rM.startVA + 2 * diffY * 180 / size, 90), -90);

into this

this.rM.hA =
  this.rM.startHA + 2 * diffX * 360 / size;
this.rM.vA = Math.max(
  Math.min(
    this.rM.startVA + 2 * diffY * 180 / size,
    90
  ),
  -90
);

How can i avoid it? I've tried to play with tslint.json settings:

"max-line-length": [true, 165]

But that one does not affect in my case.

EDIT: as following the similar issue I've tried to set both "prettier.printWidth" and "editor.wordWrap", but none of them helped. I've removed max-line-length, as suggested by @ConnorsFan, and my current Workspace Settings (which should override Users Settings, right?) is

{
"prettier.printWidth": 180,
"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 180 }

EDIT2: it appears, problem is caused by Prettier extension (comes as dependency for Angular Essentials). Now the problem is narrowed to realize, why "prettier.printWidth": 180 is not working. I've opened an issue https://github.com/prettier/prettier/issues/3228

PS: The names have been changed to protect the innocent. (c)

Pain answered 9/11, 2017 at 19:2 Comment(9)
Possible duplicate of #46939618 The prettier extension might be the problem. There is a solution there: "prettier.printWidth": 160Ethnic
@Ethnic Hm.. cant make it works for me. I've checked the default settings, and it says "editor.wordWrap": "off" - but still i face the same behavior. I've tried to override that setting as said in the link you mentioned - but it seems to have zero effect on the settings, i'm still receiving those weird newlines.Pain
Did you try disabling max-line-length completely, and then restarting Visual Studio Code?Bantustan
@ConnorsFan Just tried that - still the same. Its behavior is kinda weird: some of the lines are fine, but others are still "blown". All of them are less than 180 characters (i've set "prettier.printWidth": 180 in the settings).Pain
Are you sure that it is caused by tslint? Can you disabled it?Bantustan
@ConnorsFan very nice suggestion! I've disabled whole John Papa's package - now Alt+Shift+F (hotkey for formatting) is not doing anything. Will play with tslint package separately... Nah, cant do that - its a dependency of the Angular Essentials itself.Pain
@ConnorsFan Dammit, you're right! I've disabled AE (Angular Essentials) and enabled Tslint - not formatting works fine!Pain
@ConnorsFan Oh, so its a Prettier extension who is blowing the lines! However, i'm wondering why "prettier.printWidth": 180 is not doing its job.Pain
Funny thing, both Prettier and Tslint are AE dependencies.Pain
J
15

"prettier.printWidth": 120 worked for me with only having two javascript format extensions 'Prettier' & 'ESlint' in my vscode.

Johnnie answered 18/3, 2018 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.