This project configures ESLint and Prettier to work together with TypeScript. The setup follows best practices for linting, formatting, and code quality while ensuring smooth integration into VSCode with automatic formatting on save.
Prerequisites
- Node.js v18.18.0 or above for ESLint 9 Support
npm run lint
npm run lint:fix // Will check for linting errors and attempt to automatically fix
- Install TypeScript and necessary packages
npm install typescript ts-node @types/node @tsconfig/node20 @typescript-eslint/eslint-plugin @typescript-eslint/parser --save-dev
-
Create tsconfig.json and copy config from Repo.
-
Initialize ESLint configuration and plugins
npm init @eslint/config@latest
// Select options according to your project
// Install additional Security Plugins
npm install eslint-plugin-security eslint-plugin-sonarjs --save-dev
// add ESLint Jest Plugins
npm install eslint-plugin-jest --save-dev
-
It will create eslint.config.mjs file, add additional config from this Repo.
-
Install Prettier and its ESLint configurations
npm install prettier eslint-config-prettier eslint-plugin-prettier --save-dev
-
Create .prettierrc.json file add config from this Repo.
-
Configure VSCode Auto Formatting
In your project’s .vscode/settings.json file, configure auto-format on save:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}
- VSCode Extensions
Install these VSCode extensions to ensure proper integration of ESLint and Prettier
- Additional Resources
Awesome ESLint for finding useful ESLint plugins and configurations.