Prettier Setup for Code Formatting

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Setting Up Prettier for Code Formatting

Prettier is a formatter, not a linter. It doesn't search for errors — it rewrites code in a unified style. Key feature: it cannot be configured on how to format — only on line width, quotes, and a few other parameters. Style debates stop automatically.

Installation

npm install --save-dev prettier

For integration with ESLint (so they don't conflict):

npm install --save-dev eslint-config-prettier

.prettierrc

{
  "semi": true,
  "singleQuote": true,
  "jsxSingleQuote": false,
  "trailingComma": "all",
  "printWidth": 100,
  "tabWidth": 2,
  "useTabs": false,
  "bracketSpacing": true,
  "bracketSameLine": false,
  "arrowParens": "always",
  "endOfLine": "lf"
}

"endOfLine": "lf" — critical when working with Windows and macOS developers. Otherwise, git diff shows changes in every line of the file.

.prettierignore

node_modules/
dist/
build/
.next/
coverage/
*.min.js
*.min.css
package-lock.json
yarn.lock
pnpm-lock.yaml

scripts in package.json

{
  "scripts": {
    "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,css,json,md}\"",
    "format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,css,json,md}\""
  }
}

--check for CI — exits with a non-zero code if there are unformatted files.

ESLint Integration

Add eslint-config-prettier last in eslint.config.mjs — it disables all ESLint rules that conflict with Prettier:

import prettier from 'eslint-config-prettier';

export default [
  // ... other configs
  prettier,  // must be last
];

No need to install eslint-plugin-prettier — it runs Prettier as an ESLint rule and slows down linting. Better to run them separately.

Prettier for Different File Types

Prettier supports different parsers. Use overrides to set different options for different files:

{
  "semi": true,
  "singleQuote": true,
  "overrides": [
    {
      "files": "*.json",
      "options": {
        "printWidth": 80
      }
    },
    {
      "files": "*.md",
      "options": {
        "proseWrap": "always",
        "printWidth": 80
      }
    },
    {
      "files": "*.{yaml,yml}",
      "options": {
        "tabWidth": 2,
        "singleQuote": false
      }
    }
  ]
}

Prettier API for Custom Scripts

import prettier from 'prettier';
import fs from 'node:fs/promises';

async function formatFile(filepath: string) {
  const content = await fs.readFile(filepath, 'utf8');
  const config = await prettier.resolveConfig(filepath);

  const formatted = await prettier.format(content, {
    ...config,
    filepath, // to determine parser by extension
  });

  if (formatted !== content) {
    await fs.writeFile(filepath, formatted);
    console.log(`Formatted: ${filepath}`);
  }
}

VS Code

.vscode/settings.json:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
  "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
  "[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
}

.vscode/extensions.json — recommendations for the team:

{
  "recommendations": ["esbenp.prettier-vscode"]
}

Timeline

Adding Prettier to an existing project: 30–60 minutes for setup. Additionally 1–4 hours for initial formatting of the entire codebase and resolving conflicts with ESLint rules.