This project uses ESLint and Prettier to maintain code quality and consistency.
- Purpose: Catches bugs, enforces best practices, and maintains code quality
- Config:
eslint.config.js - Plugins:
@angular-eslint- Angular-specific rules@typescript-eslint- TypeScript rules- Template linting for HTML files
- Purpose: Automatic code formatting
- Config:
.prettierrc.json - Formats: TypeScript, HTML, SCSS, JSON
# Check for linting errors
npm run lint
# Auto-fix linting errors where possible
npm run lint:fix# Format all files
npm run format
# Check if files are formatted correctly (useful for CI)
npm run format:check- Component selector: Must use
app-prefix with kebab-case - Directive selector: Must use
appprefix with camelCase - Template accessibility: Warns about accessibility issues
- No explicit any: Warns when using
anytype - No unused vars: Warns about unused variables (except those starting with
_) - Prefer const: Enforces using
constoverletwhen possible - No var: Disallows
varkeyword
- No console: Warns about console.log (allows console.warn and console.error)
The project includes .vscode/settings.json with:
- Format on save: Automatically formats files when you save
- ESLint auto-fix: Fixes linting issues on save
- Prettier as default formatter: Uses Prettier for all file types
Install these extensions for the best experience:
- ESLint (
dbaeumer.vscode-eslint) - Prettier (
esbenp.prettier-vscode) - Angular Language Service (
Angular.ng-template)
To enforce linting before commits, you can add Husky and lint-staged:
npm install --save-dev husky lint-staged
npx husky initThen add to package.json:
{
"lint-staged": {
"*.{ts,html}": ["eslint --fix", "prettier --write"],
"*.{scss,json}": ["prettier --write"]
}
}Add these commands to your CI pipeline:
# Example GitHub Actions
- name: Lint
run: npm run lint
- name: Check formatting
run: npm run format:checkSolution: Make sure you're using the Angular template parser for HTML files.
Solution: The project uses eslint-config-prettier to disable conflicting rules.
Solution: ESLint caches results. Delete .eslintcache if you encounter issues.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data: any = response;/* eslint-disable @typescript-eslint/no-explicit-any */
// File contentrules: {
'@typescript-eslint/no-explicit-any': 'off', // Turn off
'@typescript-eslint/no-unused-vars': 'error', // Make it an error
}- Run linting before committing:
npm run lint:fix - Keep rules consistent: Don't disable rules without good reason
- Use auto-fix: Let ESLint fix issues automatically when possible
- Format regularly: Run
npm run formatto keep code consistent - Review warnings: Don't ignore warnings, they often catch real issues
When migrating to React, you'll need different ESLint configs:
npm install --save-dev eslint-plugin-react eslint-plugin-react-hooksreact/prop-types- PropTypes validationreact-hooks/rules-of-hooks- Hooks usage rulesreact-hooks/exhaustive-deps- useEffect dependencies
The linting patterns you learn here (TypeScript rules, formatting) will transfer directly to React!
Maintaining code quality makes migration easier! 🎯