Run the following command in the terminal:
npm install --save-dev prettier
// now a create a file of this=> .prettierrc.json
{
"semi": false,
"singleQuote": true
}
Next, we are going to start formatting our code using Prettier in the command line:
npx prettier --write src/app.ts
# src/index.ts 37ms
// package.json
{
// ...
"scripts": {
// ...others code..
"prettier": "prettier --ignore-path .gitignore --write \"./src/**/*.+(js|ts|json)\"",
},
// ...
}
//to run prettier
npm run prettier
// settings.json =>tthis is vscode setting then paste
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
...
}
=>install direct extesnion app
*Avoiding conflicts when working with ESLint and Prettier
*
npm install --save-dev eslint-config-prettier
// .eslintrc
{
// HERE and relace with previous estends
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
}
"scripts": {
"prettier": "prettier --ignore-path .gitignore --write \"./src/**/*.+(js|ts|json)\"",
"prettier:fix": "npx prettier --write src",
},
npm run prettier:fix
Top comments (0)