ESLint catches bugs and enforces consistency in TypeScript projects. Here's how to set it up.
Basic Setup#
Flat Config (ESLint 9+)#
Legacy Config (.eslintrc)#
React Projects#
Essential Rules#
Custom Rule Configuration#
Disabling Rules#
Override Patterns#
Prettier Integration#
Import Sorting#
IDE Integration#
Package.json Scripts#
Pre-commit Hooks#
CI Configuration#
Monorepo Setup#
Debugging ESLint#
Best Practices#
Configuration:
✓ Use flat config for new projects
✓ Enable type-checked rules
✓ Integrate with Prettier
✓ Set up pre-commit hooks
Rules:
✓ Start with recommended, customize as needed
✓ Use consistent-type-imports
✓ Enable no-floating-promises
✓ Allow underscore for unused vars
Performance:
✓ Cache results in CI
✓ Use project references for monorepos
✓ Ignore generated files
✓ Run in parallel when possible
Conclusion#
ESLint with TypeScript catches type-related bugs and enforces consistency. Use flat config for new projects, enable strict type checking, and integrate with Prettier for formatting. Pre-commit hooks ensure code quality before commits reach the repository.