Day 3 – Linting Testing and Tooling
Today's Focus
Set up ESLint, Prettier, and a test runner; write unit tests for your TypeScript domain logic.
Tasks
- Install and configure ESLint for TypeScript:
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin. Create.eslintrc.jsonwith@typescript-eslint/recommendedrules. Run it and fix every reported error and warning. - Install Prettier:
npm install --save-dev prettier. Create.prettierrcwith your preferences. Add a.prettierignorefordist/. Addnpm run format(write) andnpm run format:check(ci check) scripts. - Set up a test runner: install
vitest(orjestwithts-jest). Write at least 8 unit tests for your domain models and theResulttype from Tuesday. Test both the happy path and error branches. - Add
npm run lint,npm run test, andnpm run test:coveragescripts. Configure vitest to generate a coverage report and aim for 80% line coverage. - Add a
.editorconfigfile to enforce consistent indentation and line endings across editors. Verify VS Code respects it. - Create a
pre-commithook usinghuskyandlint-stagedthat runseslintandprettier --checkon staged.tsfiles only. Commit a deliberately malformed file to confirm the hook blocks it.
Reading / Reference
- typescript-eslint getting started.
- Vitest documentation — Getting Started and Features.
- Prettier documentation — Installation and Integrating with Linters.