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

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay