Reputation: 2197
I recently switched to a new computer, and am having difficulty with a prettier setting. (I think it's prettier, could be eslint).
This gif illustrates what's happening: http://g.recordit.co/H871hfT9Sv.gif
Anyone know what this setting is called? I would prefer all imports to be on a single line unless the length extends the printWidth
setting.
Here are my relevant User Settings from VS Code:
{
"prettier.printWidth": 100,
"prettier.semi": false,
"prettier.singleQuote": true,
"prettier.trailingComma": "all"
}
Thanks !
Edit: Visual depiction so you don't need to watch the gif.
Expected:
import React from 'react'
import { Dimensions, StyleSheet, View } from 'react-native'
import LinearGradient from 'react-native-linear-gradient'
import { isIphoneX } from 'react-native-iphone-x-helper'
Behavior: (unwanted)
import React from 'react'
import {
Dimensions,
StyleSheet,
View
} from 'react-native'
import LinearGradient from 'react-native-linear-gradient'
import {
isIphoneX
} from 'react-native-iphone-x-helper'
Upvotes: 65
Views: 255822
Reputation: 1
Open settings.json Change "prettier.printWidth": 50 to 300 or 400 Save
Before changing:
<div
class="w-1/2 p-8 flex flex-col justify-center"
>
<h5
class="text-xl font-semibold text-gray-700"
>
Masuk untuk memulai
</h5>
<h1
class="text-3xl font-bold text-gray-800 mt-2"
>
Selamat datang!
</h1>
</div>
After applying "prettier.printWidth": 400
:
<div class="w-1/2 p-8 flex flex-col justify-center">
<h5 class="text-xl font-semibold text-gray-700">Masuk untuk memulai</h5>
<h1 class="text-3xl font-bold text-gray-800 mt-2">Selamat datang!</h1>
</div>
Upvotes: 0
Reputation: 1865
In the settings.json for vscode
"prettier.configPath": "frontend/.prettierrc",
Or in the UI
This allows you to work from a root directory and still use prettier from a sub folder
Upvotes: 0
Reputation: 267
I had issue with formatting in VS Code. It was taking extension settings from prettier.
I did the following setting ins .vscode/settings.json
.prettierrc.json
file in root of the projectnpm install --save-dev prettier
These settings worked for me in VS Code.
.vscode/settings.json
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"prettier.useEditorConfig": false,
"prettier.useTabs": false,
"prettier.configPath": ".prettierrc.json",
}
.prettierrc.json
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
Upvotes: 18
Reputation: 3290
The new way to configure prettier settings:
.prettierrc.json
or just .prettierrc
){
"trailingComma": "none",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
I'd suggest doing this in each of your projects and including in any source control, that way every pull of the repo will automatically set some base settings for that developer's instance of prettier.
Upvotes: 52
Reputation: 2922
These two steps helped me to set up the .prettierrc
file correctly
1- Go to VsCode settings and check formate on save
2- Go to VsCode settings.json
and set the defaultFormatter
"editor.defaultFormatter": "esbenp.prettier-vscode"
Upvotes: 5
Reputation: 205
ctrl + ,
paste --> Prettier: Require Config
uncheck it, then all done.
Upvotes: 10
Reputation: 1
create .prettierrc file in the project dir, and use following code.
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
Upvotes: 0
Reputation: 153
If Prettier isn't showing up in your VS Code Settings, the extension may have silently crashed, which happens often when settings are changed in multiple places (i.e. tab size was changed in workspace as well as in settings).
Restart VS Code, and search for Prettier again, it should show up this time :)
Upvotes: 0
Reputation: 61
I had a similar issue. To fix this, go into your prettier extension settings and look for "Print Width". Mine was set to '80'. I changed it to '100' and it all fit on one line after I saved the file. You can change the width to whatever you would like.
Upvotes: 5
Reputation: 12182
For those trying to quickly change Prettier settings for VS Code. Here are the steps:
Upvotes: 99