component-class-suffix
component-max-inline-declarations
component-selector
contextual-decorator
@Injectable()
, signifying that they can be injected with dependencies, which is key for Angular’s dependency injection mechanism to work properly. This also ensures that the Angular application follows best practices in terms of service creation and management.
@Injectable()
, it signals to developers and the framework that this class follows the Angular pattern for services, making it easier to understand the architecture and flow of the application.
@Injectable()
. The Angular framework relies on decorators to identify and inject dependencies; without the appropriate decorator, the framework cannot properly construct an instance of the class, leading to difficult-to-trace bugs.
contextual-lifecycle
ngOnInit
, are not mistakenly used within services (@Injectable
), where they have no effect and can mislead developers about the service initialization process.directive-class-suffix
@Directive
, making the codebase easier to read and maintain by clearly indicating the purpose and nature of each class.directive-selector
no-async-lifecycle-method
async
in Angular lifecycle methods such as ngOnInit
, signaling to developers that Angular lifecycle methods don’t support the handling of asynchronous operations in the way they might expect. Using async
suggests Angular waits for the operation to complete, which it doesn’t, possibly leading to race conditions or uninitialized data.
async
from the lifecycle method and using promises with .then()
and .catch()
, developers are encouraged to explicitly handle success and failure cases of asynchronous operations, improving the robustness of the application.
no-attribute-decorator
@Input
decorator for property binding in Angular components instead of the less commonly needed @Attribute
decorator, improving code consistency and understanding among team members.@Attribute
decorator which is meant for fetching the initial value of a host element attribute, not for dynamic two-way data binding which is more often the requirement in modern Angular applications.@Input
, which is designed for component input properties and supports dynamic values via data binding, aligning with Angular’s reactive programming model.@Attribute
for scenarios where developers intend to have dynamic data binding with parent components, ensuring the components are correctly responsive to data changes.no-conflicting-lifecycle
OnInit
and OnDestroy
without OnChanges
can indicate a misunderstanding of when these hooks are supposed to be used.no-empty-lifecycle-method
no-forward-ref
forwardRef
references for DIforwardRef
in dependency injections. The usage of forwardRef
can lead to hard-to-trace dependencies and might complicate the DI framework’s ability to statically analyze and detect services, potentially leading to runtime errors or complicated debugging sessions.forwardRef
to circumvent circular dependencies, developers are pushed to reconsider their application’s structure, possibly refactoring their code to avoid such circular references in the first place.forwardRef
, this rule indirectly enhances application performance. Since forwardRef
adds an extra layer of complexity to the DI mechanism, removing its usage can lead to a more optimized dependency resolution process at runtime, resulting in faster application startup times and potentially better runtime performance.forwardRef
is used, it can be less clear why a certain service is injected in a particular way, especially to those new to the codebase or Angular. Enforcing this rule means that developers need to find alternative, and often more straightforward, methods of dependency injection, which can make the code easier to understand and maintain.no-host-metadata-property
host
metadata property. See more at https://angular.io/styleguide#style-06-03host
metadata property within @Component
decorators, aligning with Angular style guide recommendations.@HostListener
for handling DOM events, making the component class cleaner and the event handling logic more transparent.host
metadata property, leading to a more stable Angular application structure.no-input-prefix
no-input-rename
'angular/no-input-rename'
discourages the practice of aliasing input bindings, promoting direct and clear communication between parent and child components in Angular applications. This ensures a more readable and maintainable codebase, as developers can easily understand and trace property bindings without the need to decipher aliased names.
no-inputs-metadata-property
inputs
metadata property. See more at https://angular.io/styleguide#style-05-12@Input()
decorator over the inputs
array in the @Component
decorator. This makes the code more readable and the bindings between parent and child components clear.
inputs
metadata property, the rule encourages developers to declare inputs explicitly within the component class, which can enhance type safety by allowing TypeScript to check and enforce appropriate types for the properties.
inputs
metadata property. Explicitly defining inputs with the @Input()
decorator makes it less likely that inputs will be omitted or misconfigured within the component metadata, thereby reducing debugging time and increasing the application’s reliability.
no-lifecycle-call
no-output-native
no-output-on-prefix
no-output-rename
no-outputs-metadata-property
outputs
metadata property. See more at https://angular.io/styleguide#style-05-12@Output()
decorator directly on the property, it is immediately clear that the property is intended to be an output.
@Output()
over the outputs
array in @Component
metadata. Following these best practices helps in keeping the code standardized across different projects and developers.
outputs
metadata property, which might be less intuitive and error-prone, especially for developers new to Angular or working on large projects. Directly decorating the properties with @Output()
makes it easier to identify outputs and their corresponding events.
@Output()
, allowing for better autocomplete, refactoring capabilities, and error detection. This can lead to a more efficient development process and fewer runtime errors.
no-pipe-impure
no-queries-metadata-property
queries
metadata property. See more at https://angular.io/styleguide#style-05-12.queries
metadata property in component decorators.
@ContentChildren
and @ViewChildren
decorators directly in class definitions makes it easier for developers to identify and understand component relationships and dependencies.
pipe-prefix
prefer-on-push-component-change-detection
changeDetection
is set to ChangeDetectionStrategy.OnPush
ChangeDetectionStrategy.OnPush
in Angular components, which ensures that change detection runs only when the reference to an input property changes. This can lead to significant performance improvements in applications, especially those with complex component trees, by reducing the frequency of change detection checks.
OnPush
change detection strategy, developers can easily understand and manage the state and change detection flow within the application.
OnPush
change detection requires explicit triggering for changes to be reflected in the view, developers are less likely to inadvertently rely on Angular’s default change detection to update the view when data changes, encouraging better data management practices.
OnPush
, developers need to explicitly mark components for check or update input properties immutably, leading to less unnecessary checks and updates, and ultimately a smoother user experience.
prefer-output-readonly
@Output
as readonly
since they are not supposed to be reassigned@Output
properties are declared as readonly
. This aligns with the design principle that output properties should not be reassigned after initialization, promoting immutability and reducing potential bugs related to the unintended modification of these properties.
@Output
properties as readonly
, it clearly communicates the intent to other developers that these properties are meant for emitting events to parent components and should not be manipulated directly. This enhances code readability and maintainability.
readonly
with @Output
properties can help prevent runtime errors that might occur if an output property is accidentally reassigned. Since Angular uses these properties for output event binding, altering them can break the expected component communication flow.
@Output
properties, as they are guaranteed not to change after their initial assignment. This can lead to more efficient detection of changes and updating of views.
prefer-standalone-component
standalone
property is set to true
in the component decoratorstandalone
property within the Angular component decorator to be set to true
promotes the use of standalone components, which are modular and can be independently used or tested. This aligns with modern Angular practices of building scalable and maintainable applications.standalone
property to be explicitly declared, this ESLint rule ensures greater consistency across the codebase. Each component’s ability to function independently or require certain dependencies is made clear, improving code readability and understanding among team members.standalone
property as mandated by this rule can lead to easier refactoring and testing of components. Standalone components encapsulate their dependencies, making them easier to migrate, mock, or replace during testing or when changing aspects of the application’s design or functionality.relative-url-prefix
./
or ../
, thereby improving the reliability of the application.require-localize-metadata
$localize
tagged messages, which significantly enhances the traceability of texts across different languages and their translations, making it easier to manage and update translations in larger applications.
sort-lifecycle-methods
sort-ngmodule-metadata-arrays
NgModule
metadata arrays for easy visual scanningNgModule
metadata arrays, which improves maintainability by making it easier to visually scan and locate specific modules, components, or services.use-component-selector
use-component-view-encapsulation
ViewEncapsulation.None
ViewEncapsulation.None
, the rule encourages developers to follow best practices in Angular application development. Using the default view encapsulation (Emulated
) aligns with Angular’s component-based architecture, where each component should be self-contained.
use-injectable-provided-in
providedIn
property makes Injectables
tree-shakableprovidedIn
property, which facilitates Angular’s tree-shaking capabilities during the build process, leading to potentially smaller bundle sizes.providedIn
property, aligning the codebase with the Angular team’s recommendations for service declaration.use-lifecycle-interface
use-pipe-transform-interface
Pipes
implement PipeTransform
interfacePipeTransform
interface, which is essential for maintaining predictable behavior of pipes across the project.PipeTransform
interface, making it easier for new developers to understand the codebase.transform
method with the correct signature, reducing runtime errors due to incorrect implementations.