-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Description
Using the following settings:
import { ASTUtils } from "@angular-eslint/utils"
export default defineConfig([
// ...
{
rules: {
"prefer-arrow-functions/prefer-arrow-functions": [
"error",
{
{
classPropertiesAllowed: true,
disallowPrototype: true,
returnStyle: "implicit"
},
allowedNames: Array.from(ASTUtils.ANGULAR_LIFECYCLE_METHODS)
}
]
}
}
]And for reference:
> const { ASTUtils } = await import("@angular-eslint/utils");
undefined
> Array.from(ASTUtils.ANGULAR_LIFECYCLE_METHODS)
[
'ngAfterContentChecked',
'ngAfterContentInit',
'ngAfterViewChecked',
'ngAfterViewInit',
'ngDoBootstrap',
'ngDoCheck',
'ngOnChanges',
'ngOnDestroy',
'ngOnInit'
]still flags the following:
import type { AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoBootstrap, DoCheck, OnChanges, OnDestroy, OnInit } from '@angular/core'
import { Component } from '@angular/core'
@Component({
selector: 'app-good-example',
template: '',
})
export class GoodExampleComponent
implements
AfterContentChecked,
AfterContentInit,
AfterViewChecked,
AfterViewInit,
DoBootstrap,
DoCheck,
OnChanges,
OnDestroy,
OnInit
{
// Testing good examples for: Angular hooks need to be functions defined on the prototype
ngAfterContentChecked() {}
ngAfterContentInit() {}
ngAfterViewChecked() {}
ngAfterViewInit() {}
ngDoBootstrap() {}
ngDoCheck() {}
ngOnChanges() {}
ngOnDestroy() {}
ngOnInit() {}
}Suggested Solution
I would expect allowedNames: ['ngOnInit', ...] to also allow using a function method ngOnInit set on the class prototype (which is needed for Angular)
Help Needed
In the mean time I've been reconfiguring this rule with classPropertiesAllowed: false by targeting filenames, but that is fragile and only works when a specific naming convention is followed perfectly.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels