#typescript #tools #eslint #prettier

Day 28: Linting and Formatting

The Police and the Painter

Welcome to Day 28! Writing code is art, but it needs rules.

ESLint (The Police)

ESLint analyzes your code for problems (bugs, bad patterns). TypeScript has typescript-eslint.

npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin

Key Rule: no-explicit-any. It prevents you from using any (our Day 7 friend/enemy).

Prettier (The Painter)

Prettier formats your code (indentation, semicolons, etc.). It doesn’t care about bugs, only looks.

Making them friends

Use eslint-config-prettier to turn off ESLint rules that conflict with Prettier.

Husky (The Enforcer)

Use Husky to run these tools before you commit code (pre-commit hook). This ensures no bad code enters the repo.

Challenge for Today

  1. If you have a project, install Prettier.
  2. Run npx prettier --write ..
  3. Watch your code transform into a consistent style!

See you on Day 29 for our Capstone Project!