A collection of ESLint rules specifically designed for Angular applications. These rules help maintain code quality and enforce best practices in your Angular projects.
- 🛡️ Enforces best practices for Angular development
- 🔍 Prevents common anti-patterns
- 🎯 Improves code quality and maintainability
- ⚡ Supports both modern and legacy ESLint configurations
npm install @rdlabo/eslint-plugin-rules --save-dev
Note: If your project doesn't have
angular-eslint
packages installed, please install them first: angular-eslint
const rdlabo = require('@rdlabo/eslint-plugin-rules');
module.exports = tseslint.config(
{
files: ['*.ts'],
plugins: {
'@rdlabo/rules': rdlabo,
},
rules: {
'@rdlabo/rules/deny-constructor-di': 'error',
'@rdlabo/rules/deny-import-from-ionic-module': 'error',
'@rdlabo/rules/implements-ionic-lifecycle': 'error',
'@rdlabo/rules/deny-soft-private-modifier': 'error',
'@rdlabo/rules/signal-use-as-signal': 'error',
'@rdlabo/rules/signal-use-as-signal-template': 'error',
'@rdlabo/rules/component-property-use-readonly': 'error',
},
},
{
files: ['*.html'],
plugins: {
'@rdlabo/rules': rdlabo,
},
rules: {
'@rdlabo/rules/deny-element': [
'error',
{
elements: [
'ion-modal',
'ion-popover',
'ion-toast',
'ion-alert',
'ion-loading',
'ion-picker',
'ion-action-sheet',
],
},
],
},
}
);
Rule | Description | Auto-fixable |
---|---|---|
@rdlabo/rules/deny-constructor-di | Prevents Dependency Injection within constructors | ❌ |
@rdlabo/rules/deny-element | Restricts usage of specific HTML elements | ❌ |
@rdlabo/rules/deny-import-from-ionic-module | Prevents direct imports from @ionic/angular
|
✅ |
@rdlabo/rules/implements-ionic-lifecycle | Ensures proper implementation of Ionic lifecycle hooks | ✅ |
@rdlabo/rules/deny-soft-private-modifier | Prevents usage of soft private modifiers | ✅ |
@rdlabo/rules/signal-use-as-signal | Validates proper usage of Angular signals | ✅ |
@rdlabo/rules/signal-use-as-signal-template | Enforces correct usage of Angular Signals in templates | ❌ |
@rdlabo/rules/component-property-use-readonly | Enforces readonly modifier for class properties | ✅ |
@rdlabo/rules/import-inject-object
is removed. This is because we removed the auto-fixable feature from @rdlabo/rules/deny-constructor-di
due to concerns about its compatibility with the new ng generate @angular/core:inject
command.
Control the usage of explicit accessibility modifiers in class members:
"rules": {
"@typescript-eslint/explicit-member-accessibility": ["error", { "accessibility": "no-public" }],
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.