-
Notifications
You must be signed in to change notification settings - Fork 4
ESLint
Presentation : ESLint is a statuc code analysis tool for JS and TS.
Key benefits for this project are
- dev experience: early error catching before compilation
- code quality: more exhaustive than syntax checks. Can also point to runtime errors. Shared across the team.
- type safety: ensure along tsconfig that unsafe types are not too widely used.
npm install eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin --save-devNote
ESLint should not check format (risk of conflict with Prettier).
We can base our config on
{
"extends": ["plugin:prettier/recommended"]
}Important
Currently no shared configuration. We could try to have a root configuration .eslintrc.js extended within each service.
module.exports = {
extends: '../../.eslintrc.js', // root file
...
}-
'@typescript-eslint/no-explicit-any': 'warn'Using any defeats the purpose of using TypeScript : compiler won't stop us from accessing properties that don't exist, potentially causing crashes. -
'no-console': 'warn' In production, log statements clutter server logs and can leak sensitive info. We should use Fastify's logger which handles log levels (eg debug for temporary logs)
-
@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }]We can acknowledge that a var needed by function prototype is not used by prefixing it with_ -
eqeqeqStrict equality checks. We should use===over==to prevent natural JS type coercion (eg 0 == '0') -
@typescript-eslint/no-floating-promisesWe ensure that async functions are called withawait. Otherwise, it could create race conditions. -
@typescript-eslint/await-thenableEnsure that we only await Promises.
-
@typescript-eslint/naming-conventionEnforce consistent naming. For instance- classes in PascalCase
- boolean variables prefixed with
isorhas..
cf doc
-
no-shadowEnsure that two variables in embedded scopes don't share the same name -
@typescript-eslint/consistent-type-importsPerformance as it helps Vite optimize bundling.
Add a script in package.json and possibly a Makefile target
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"then npm run lint
cf Husky
- ESLint extension
- update
settings.json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}| โ Do | โ Don't |
|---|---|
| Run ESlint before pushing | Push code with linting errors (may cause a fail CI check) |
| Configure ESLint to work alongside Prettier | Use ESLint for stylistic formatting (indentation, max-len) as we use Prettier. |
| Type | Ressource | Notes |
|---|---|---|
| ๐ | Official doc | - |
| ๐ | TS ESLint | - |
Legend: ๐ Doc, ๐ Book, ๐ฅ Video, ๐ป GitHub, ๐ฆ Package, ๐ก Blog
- Gateway Service - API Gateway & JWT validation
- Auth Service - Authentication & 2FA/TOTP
- AI Service - AI opponent
- API Documentation - OpenAPI/Swagger
- DB Schema - Databases
- Fastify - Web framework
- Prisma - ORM
- WebSockets - Real-time communication
- Restful API - API standards
- React - UI library
- CSS - Styling
- Tailwind - CSS framework
- Accessibility - WCAG compliance
- TypeScript - Language
- Zod - Schema validation
- Nginx - Reverse proxy
- Logging and Error management - Observability
- OAuth 2.0 - Authentication flows
- Two-factor authentication - 2FA/TOTP
- Avalanche - Blockchain network
- Hardhat - Development framework
- Solidity - Smart contracts language
- Open Zeppelin - Security standards
- ESLint - Linting
- Vitest - Testing
- GitHub Actions - CI/CD
- Husky, Commit lints and git hooks - Git hooks
- ELK - Logging stack
๐ Page model