Skip to content

Latest commit

Β 

History

History
104 lines (79 loc) Β· 4.85 KB

File metadata and controls

104 lines (79 loc) Β· 4.85 KB

@rdlabo/eslint-plugin-rules

A collection of ESLint rules specifically designed for Angular applications. These rules help maintain code quality and enforce best practices in your Angular projects.

npm version License: MIT

πŸ’– Support This Project

Enjoying this project? Your support helps keep it alive and growing!
Sponsoring means you directly contribute to new features, improvements, and maintenance.

Become a Sponsor β†’

✨ Features

  • πŸ›‘οΈ Enforces best practices for Angular development
  • πŸ” Prevents common anti-patterns
  • 🎯 Improves code quality and maintainability

πŸ“¦ Installation

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

βš™οΈ Configuration

Configuration (eslint.config.js)

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'],
        },
      ],
      '@rdlabo/rules/ionic-attr-type-check': 'error',
    },
  },
);

πŸ“‹ Available Rules

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/ionic-attr-type-check Disallows string values for non-string attributes in Ionic components βœ…

@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.

πŸ”§ Recommended Additional Rules

TypeScript Member Accessibility

Control the usage of explicit accessibility modifiers in class members:

"rules": {
  "@typescript-eslint/explicit-member-accessibility": ["error", { "accessibility": "no-public" }],
}

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for details.