prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

Setting the prettiet.printwidth property does not work #595

Closed wanghaooo closed 4 years ago

wanghaooo commented 5 years ago

I set the prettier.printWidth property to 500, but the line is still wrapped after formatting

2018-10-04 10 21 01 2018-10-04 10 21 28

I want the block of code to be a little bit longer and I'm going to wrap it, but do I need to set some places besides the printwidth property?

clamkong commented 5 years ago

Seems like this issue happens for any config greater than 100 at least

wanghaooo commented 5 years ago

Some are not used to code blocks so short line breaks

DavidHenri008 commented 5 years ago

In my case the wrap does not even work for small numbers. If I set "printWidth": 70 with code like const a = function afterAll(aaaaa, sssss, ddddd, fffff, ggggg, hhhhhh, jjjjj, kkkkk) {}; it never wraps.

CiGit commented 5 years ago

I see a tslintIntegration. Do you have anything in your tslint config which could cause printWidth to be smaller?

alvarodp commented 5 years ago

Same happening here. I have a project .prettierrc file with just one override: { "overrides": [ { "files": "*.ts", "options": { "singleQuote": true } } ] }

In addition, I have a workspace setting like this: "prettier.printWidth": 140

However, when formatting a .ts file, this workspace printWidth is not respected and uses the default one 80.

It only works if I put this configuration in the .prettierrc.

I also use tslint, but it's well configured as: "max-line-length": [ true, 140 ],

Any clue?

DavidHenri008 commented 5 years ago

@alvarodp which configuration do you put in .prettierrc to make it work (make it wraps the line after 140 char)? Thanks

alvarodp commented 5 years ago

To make it work I must include the "prettier.printWidth" property. { "overrides": [ { "files": "*.ts", "options": { "singleQuote": true, "prettier.printWidth": 140 } } ] } But I want to set this property in the workspace, not in the .prettierrc.

CiGit commented 5 years ago

If you have a prettier config file, we discard settings from VSCode. That's why you see default values for them. Explained: https://github.com/prettier/prettier-vscode#prettiers-settings.

You should set printWidth, not prettier.printWidth in your config file. Prefix are only for VSCode

alvarodp commented 5 years ago

True, without the prefix. So there's no "merge" with vscode settings and it's not planned.

DavidHenri008 commented 5 years ago

Here is the content of my .prettierrc file:

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "useTabs": false,
  "singleQuote": true,
  "printWidth": 100,
  "bracketSpacing": true,
}

My code never wraps when my line of code exceeds 100 characters.

DavidHenri008 commented 5 years ago

@alvarodp Unfortunately adding your override suggestion to my .prettierrc did not work for me.

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "useTabs": false,
  "singleQuote": true,
  "printWidth": 100,
  "bracketSpacing": true,
  "overrides": [
    {
      "files": "*.js*",
      "options": {
        "prettier.printWidth": 50
      }
    }
  ]
}

Is that the format you have been using?

CiGit commented 5 years ago

@alvarodp It was the case in older versions of this extension but was removed to stay consistent with prettier cli and other IDE which do not read from VSCode's settings. No settings means default ones.

@DavidHenri008 it's printWidth not prettier.printWidth. Check if you don't have any other extension formatting your given file and your config file is above your file (file path wise)

DavidHenri008 commented 5 years ago

@CiGit Unfortunately, even with printWidth only it still does not work. The syntax or the whole command is wrong.

ph55 commented 5 years ago

Same here. Only works if you set it in .prettierrc

DavidHenri008 commented 5 years ago

@ph55 if it works for you, could you post your complete .prettierrc file content.

ph55 commented 5 years ago

@DavidHenri008 sure, very simple:

{
  "singleQuote": true,
  "printWidth": 100
}
jakeleventhal commented 5 years ago

i have this same issue

jabacchetta commented 5 years ago

@CiGit I'm having the same issue as @DavidHenri008, where the formatting does not wrap at all.

The issue appears to happen for me only when the ESLint Integration option is enabled. However, all of my other ESLint rules appear to be working fine. It just does not seem to recognize any sort of printWidth at all (i.e. max-len rule).

Update This appears to be an ESLint bug.

Mulperi commented 4 years ago

The issue appears to happen for me only when the ESLint Integration option is enabled.

THANK YOU. Unchecked ESLint integration from VSCode options -> Works again.

rhefner commented 4 years ago

I have been wondering why VSCode is doing one thing and prettier CLI another.. I would expect that the prettier config file (in my case, .prettierrc.yaml) would be the end-all. Shouldn't the config override any workspace/user settings that are set?

I checked that I didn't have ESLint Integration set, but VSCode prettier was still wrapping a long line even though prettier CLI didn't. My .prettierrc.yaml file:

singleQuote: true
semi: true
tabWidth: 2
useTabs: false
proseWrap: 'never'
printWidth: 120
bracketSpacing: true
arrowParens: 'always'

But ... I had my "prettier.printWidth": 80 in my User settings. I made it 120 to match the prettier config file and voila -- It now works.

And, I didn't have anything set (directly) for printWidth in my tsconfig.json file, but I am extending ["tslint:latest", "tslint-plugin-prettier", "tslint-config-prettier"]

blackmad commented 4 years ago

I'm confused. I've been struggling to get this working for weeks. It seemed like vscode wasn't picking up my .prettierrc.

I just added "prettier.printWidth" to .vscode/settings.json and it finally worked correctly. Why isn't vscode picking up my .prettierrc?

here are my configs + their names and paths image

ntotten commented 4 years ago

@blackmad Please post a new issue about the prettierrc and include the log data and ideally a sample project that can be used to reproduce the issue.

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.