diff --git a/src/main/rules/GCI120/GCI120.json b/src/main/rules/GCI120/GCI120.json new file mode 100644 index 00000000..68520dc7 --- /dev/null +++ b/src/main/rules/GCI120/GCI120.json @@ -0,0 +1,24 @@ +{ + "title": "Component change detection strategy should be OnPush", + "type": "CODE_SMELL", + "code": { + "impacts": { + "RELIABILITY": "" + }, + "attribute": "" + }, + "status": "", + "remediation": { + "func": "", + "constantCost": "" + }, + "tags": [ + "creedengo", + "eco-design", + "performance" + ], + "defaultSeverity": "Major", + "compatibleLanguages": [ + "Angular", + ] +} diff --git a/src/main/rules/GCI120/angular/GCI120.asciidoc b/src/main/rules/GCI120/angular/GCI120.asciidoc new file mode 100644 index 00000000..e1a2b91e --- /dev/null +++ b/src/main/rules/GCI120/angular/GCI120.asciidoc @@ -0,0 +1,42 @@ +== Why is this an issue? + +With Default change detection strategy, Angular will check this component and all its children everytime change detection runs. Any change in any part of the app, including unrelated components, will trigger re-evaluation of this components view. +It's advised to use OnPush change detection strategy, to improve performance by recuding the number of checks, limiting them to: input changes or events changes. + +ps: tracked elements should be immutable. + +== Non compliant Code Example + +[source,angular] +---- +@Component({ + selector: 'my-app', + template: 'my-app.component.html', + changeDetection: ChangeDetectionStrategy.Default, +}) +class MyAppComponent { +... +---- + +[source,angular] +---- +@Component({ + selector: 'my-app', + template: 'my-app.component.html', +}) +class MyAppComponent { +... +---- + + +== Compliant Solution +[source,angular] +---- +@Component({ + selector: 'my-app', + template: 'my-app.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +class MyAppComponent { +... +----