Skip to content

rdlabo-team/eslint-plugin-rules

Repository files navigation

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

About

rdlabo's custom eslint rules

Resources

License

Stars

7 stars

Watchers

2 watching

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages