DEV Community

Kazi Abdur Rakib
Kazi Abdur Rakib

Posted on

Typescript Integrating Prettier VsCode

Run the following command in the terminal:

npm install --save-dev prettier
Enter fullscreen mode Exit fullscreen mode

// now a create a file of this=> .prettierrc.json
{
  "semi": false,
  "singleQuote": true

}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

// package.json

{
  // ...
  "scripts": {
  // ...others code..
    "prettier": "prettier --ignore-path .gitignore --write \"./src/**/*.+(js|ts|json)\"",
  },
  // ...
}

Enter fullscreen mode Exit fullscreen mode
//to run prettier
npm run prettier

Enter fullscreen mode Exit fullscreen mode
// settings.json =>tthis is vscode setting then paste
{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  ...
}

Enter fullscreen mode Exit fullscreen mode

=>install direct extesnion app

Image description

Image description

*Avoiding conflicts when working with ESLint and Prettier
*

npm install --save-dev eslint-config-prettier
Enter fullscreen mode Exit fullscreen mode
// .eslintrc
{
  // HERE and relace with previous estends
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier"
  ],
}

Enter fullscreen mode Exit fullscreen mode
  "scripts": {
    "prettier": "prettier --ignore-path .gitignore --write \"./src/**/*.+(js|ts|json)\"",
    "prettier:fix": "npx prettier --write src",
  },

Enter fullscreen mode Exit fullscreen mode
npm run prettier:fix
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)