Prettier

Prettier is an opinionated code formatter. It automatically formats your code so that it follows consistent style rules. It supports many programming languages, including:

  • JavaScript / TypeScript
  • HTML / CSS / SCSS
  • JSON / YAML / Markdown
  • Python (via plugins)
  • And more

It does not check for errors or bugs—it just makes your code look clean and consistent.


Why People Use Prettier

  1. Consistency: Everyone on the team uses the same formatting, so code looks uniform.
  2. Saves time: No more arguing over tabs vs. spaces, quotes, or line breaks.
  3. Integration: Works with editors like VS Code, Sublime Text, and tools like ESLint.
  4. Reduces diffs: Git diffs are cleaner because formatting differences are removed.

How It Works

  1. You install it via npm:
npm install --save-dev prettier
  1. You can format files manually:
npx prettier --write .
  1. Or integrate it with your editor so it formats code automatically on save.

Example

Before Prettier:

function hello(name){console.log("Hello, "+name)}

After Prettier:

function hello(name) {
  console.log("Hello, " + name);
}

Notice the consistent spacing, indentation, and line breaks.

Leave a Reply