Migrate to @angular-eslint/prefer-inject and @typescript-eslint/prefer-readonly (#11665)

This commit is contained in:
Denys Vuika
2026-02-18 15:38:01 +00:00
committed by GitHub
parent f8fa996b04
commit 3f542d99ba
470 changed files with 2638 additions and 2247 deletions
@@ -26,7 +26,8 @@ import {
OnChanges,
SimpleChanges,
ViewEncapsulation,
ChangeDetectionStrategy
ChangeDetectionStrategy,
inject
} from '@angular/core';
import { ExtensionService } from '../../services/extension.service';
@@ -47,6 +48,8 @@ import { ExtensionService } from '../../services/extension.service';
]
})
export class DynamicColumnComponent implements OnInit, OnChanges, OnDestroy {
private readonly extensions = inject(ExtensionService);
@ViewChild('content', { read: ViewContainerRef, static: true })
content: ViewContainerRef;
@@ -58,8 +61,6 @@ export class DynamicColumnComponent implements OnInit, OnChanges, OnDestroy {
private componentRef: ComponentRef<any>;
constructor(private extensions: ExtensionService) {}
ngOnInit() {
const componentType = this.extensions.getComponentById(this.id);
if (componentType) {
@@ -15,7 +15,18 @@
* limitations under the License.
*/
import { Component, Input, ComponentRef, ViewChild, ViewContainerRef, OnDestroy, OnChanges, SimpleChanges, AfterViewInit } from '@angular/core';
import {
Component,
Input,
ComponentRef,
ViewChild,
ViewContainerRef,
OnDestroy,
OnChanges,
SimpleChanges,
AfterViewInit,
inject
} from '@angular/core';
import { ExtensionService } from '../../services/extension.service';
import { ExtensionComponent } from '../../services/component-register.service';
import { MatMenuItem } from '@angular/material/menu';
@@ -26,6 +37,8 @@ import { MatMenuItem } from '@angular/material/menu';
template: `<div #content></div>`
})
export class DynamicExtensionComponent implements OnChanges, OnDestroy, AfterViewInit {
private readonly extensions = inject(ExtensionService);
@ViewChild('content', { read: ViewContainerRef, static: true })
content: ViewContainerRef;
@@ -41,8 +54,6 @@ export class DynamicExtensionComponent implements OnChanges, OnDestroy, AfterVie
private componentRef: ComponentRef<ExtensionComponent>;
private loaded: boolean = false;
constructor(private extensions: ExtensionService) {}
ngOnChanges(changes: SimpleChanges) {
if (!this.loaded) {
this.loadComponent();
@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, OnInit, OnDestroy, ViewChild, ViewContainerRef, ComponentRef, OnChanges, SimpleChanges } from '@angular/core';
import { Component, Input, OnInit, OnDestroy, ViewChild, ViewContainerRef, ComponentRef, OnChanges, SimpleChanges, inject } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { ExtensionService } from '../../services/extension.service';
@@ -24,6 +24,8 @@ import { ExtensionService } from '../../services/extension.service';
template: `<div #content></div>`
})
export class DynamicTabComponent implements OnInit, OnChanges, OnDestroy {
private readonly extensions = inject(ExtensionService);
@ViewChild('content', { read: ViewContainerRef, static: true })
content: ViewContainerRef;
@@ -36,8 +38,6 @@ export class DynamicTabComponent implements OnInit, OnChanges, OnDestroy {
private componentRef: ComponentRef<any>;
constructor(private extensions: ExtensionService) {}
ngOnInit() {
const componentType = this.extensions.getComponentById(this.id);
if (componentType) {
@@ -37,6 +37,8 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
template: `<div #content></div>`
})
export class PreviewExtensionComponent implements OnInit, OnChanges, OnDestroy {
private readonly extensionService = inject(ExtensionService);
@ViewChild('content', { read: ViewContainerRef, static: true })
content: ViewContainerRef;
@@ -63,8 +65,6 @@ export class PreviewExtensionComponent implements OnInit, OnChanges, OnDestroy {
private componentRef: ComponentRef<any>;
constructor(private extensionService: ExtensionService) {}
ngOnInit() {
if (!this.id) {
return;
@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { ExtensionConfig, ExtensionRef } from '../config/extension.config';
import { ExtensionService } from '../services/extension.service';
import { Observable, BehaviorSubject } from 'rxjs';
@@ -26,10 +26,12 @@ import { DocumentListPresetRef } from '../config/document-list.extensions';
providedIn: 'root'
})
export class AppExtensionService {
references$: Observable<ExtensionRef[]>;
private _references = new BehaviorSubject<ExtensionRef[]>([]);
protected extensionService = inject(ExtensionService);
constructor(protected extensionService: ExtensionService) {
references$: Observable<ExtensionRef[]>;
private readonly _references = new BehaviorSubject<ExtensionRef[]>([]);
constructor() {
this.references$ = this._references.asObservable();
}
@@ -16,7 +16,8 @@
*/
import { TestBed, fakeAsync, flushMicrotasks, tick } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { ExtensionConfig } from '../config/extension.config';
import { ExtensionLoaderService } from './extension-loader.service';
@@ -35,10 +36,7 @@ describe('ExtensionLoaderService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
ExtensionLoaderService
]
providers: [ExtensionLoaderService, provideHttpClient(), provideHttpClientTesting()]
});
extensionLoaderService = TestBed.inject(ExtensionLoaderService);
httpMock = TestBed.inject(HttpTestingController);
@@ -85,10 +83,12 @@ describe('ExtensionLoaderService', () => {
it('should load only extensions defined by $references', fakeAsync(() => {
appExtensionsConfig.$references = ['test.extension.1.json'];
extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.2.json, test.extension.3.json']).then((config: ExtensionConfig) => {
const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name);
expect(pluginsReference).toEqual(['test.extension.1']);
});
extensionLoaderService
.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.2.json, test.extension.3.json'])
.then((config: ExtensionConfig) => {
const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name);
expect(pluginsReference).toEqual(['test.extension.1']);
});
httpMock.expectOne('assets/app.extensions.json').flush(appExtensionsConfig);
tick();
@@ -98,20 +98,20 @@ describe('ExtensionLoaderService', () => {
flushMicrotasks();
}));
it('should load extensions from passed extension value',fakeAsync(() => {
it('should load extensions from passed extension value', fakeAsync(() => {
appExtensionsConfig.$references = ['test.extension.1.json'];
extensionLoaderService.load(
'assets/app.extensions.json',
'assets/plugins',
undefined,
[{
$id: 'extension-value-id',
$license: 'license',
$name: 'name',
$version:'version',
$vendor: 'vendor'
}]).then((config: ExtensionConfig) => {
extensionLoaderService
.load('assets/app.extensions.json', 'assets/plugins', undefined, [
{
$id: 'extension-value-id',
$license: 'license',
$name: 'name',
$version: 'version',
$vendor: 'vendor'
}
])
.then((config: ExtensionConfig) => {
const hasExtensionValue = config.$references.some((entry: ExtensionConfig) => entry.$id === 'extension-value-id');
expect(hasExtensionValue).toBe(true);
});
@@ -122,17 +122,17 @@ describe('ExtensionLoaderService', () => {
}));
it('should load extensions if only extension value was passed', fakeAsync(() => {
extensionLoaderService.load(
'assets/app.extensions.json',
'assets/plugins',
undefined,
[{
$id: 'extension-value-id',
$license: 'license',
$name: 'name',
$version:'version',
$vendor: 'vendor'
}]).then((config: ExtensionConfig) => {
extensionLoaderService
.load('assets/app.extensions.json', 'assets/plugins', undefined, [
{
$id: 'extension-value-id',
$license: 'license',
$name: 'name',
$version: 'version',
$vendor: 'vendor'
}
])
.then((config: ExtensionConfig) => {
const hasExtensionValue = config.$references.some((entry: ExtensionConfig) => entry.$id === 'extension-value-id');
expect(hasExtensionValue).toBe(true);
});
@@ -144,23 +144,24 @@ describe('ExtensionLoaderService', () => {
it('should load extensions with multiple extension values', fakeAsync(() => {
appExtensionsConfig.$references = ['test.extension.1.json'];
extensionLoaderService.load(
'assets/app.extensions.json',
'assets/plugins',
undefined,
[{
$id: 'extension-value-id-1',
$license: 'license',
$name: 'name',
$version:'version',
$vendor: 'vendor'
},{
$id: 'extension-value-id-2',
$license: 'license',
$name: 'name',
$version:'version',
$vendor: 'vendor'
}]).then((config: ExtensionConfig) => {
extensionLoaderService
.load('assets/app.extensions.json', 'assets/plugins', undefined, [
{
$id: 'extension-value-id-1',
$license: 'license',
$name: 'name',
$version: 'version',
$vendor: 'vendor'
},
{
$id: 'extension-value-id-2',
$license: 'license',
$name: 'name',
$version: 'version',
$vendor: 'vendor'
}
])
.then((config: ExtensionConfig) => {
const hasFirstExtensionValue = config.$references.some((entry: ExtensionConfig) => entry.$id === 'extension-value-id-1');
expect(hasFirstExtensionValue).toBe(true);
const hasSecondExtensionValue = config.$references.some((entry: ExtensionConfig) => entry.$id === 'extension-value-id-2');
@@ -16,7 +16,7 @@
*/
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { ActionRef, ContentActionRef, ContentActionType } from '../config/action.extensions';
import { ExtensionElement } from '../config/extension-element';
import { filterEnabled, getValue, mergeObjects, sortByOrder } from '../config/extension-utils';
@@ -28,7 +28,7 @@ import { RuleRef } from '../config/rule.extensions';
providedIn: 'root'
})
export class ExtensionLoaderService {
constructor(private http: HttpClient) {}
private readonly http = inject(HttpClient);
load(configPath: string, pluginsPath: string, extensions?: string[], extensionValues?: ExtensionConfig[]): Promise<ExtensionConfig> {
return new Promise<any>((resolve) => {
@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ExtensionService } from './extension.service';
import { ExtensionService, EXTENSION_JSONS, EXTENSION_JSON_VALUES } from './extension.service';
import { ExtensionLoaderService } from './extension-loader.service';
import { ExtensionConfig } from '../config/extension.config';
import { RuleRef } from '../config/rule.extensions';
@@ -23,6 +23,9 @@ import { RouteRef } from '../config/routing.extensions';
import { ActionRef } from '../config/action.extensions';
import { ComponentRegisterService } from './component-register.service';
import { RuleService } from './rule.service';
import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
describe('ExtensionService', () => {
const blankConfig: ExtensionConfig = {
@@ -35,15 +38,24 @@ describe('ExtensionService', () => {
};
let loader: ExtensionLoaderService;
let componentRegister: ComponentRegisterService;
let service: ExtensionService;
let ruleService: RuleService;
beforeEach(() => {
loader = new ExtensionLoaderService(null);
componentRegister = new ComponentRegisterService();
ruleService = new RuleService(loader);
service = new ExtensionService(loader, componentRegister, ruleService, [], []);
TestBed.configureTestingModule({
providers: [
provideHttpClient(),
provideHttpClientTesting(),
ExtensionService,
ExtensionLoaderService,
ComponentRegisterService,
RuleService,
{ provide: EXTENSION_JSONS, useValue: [] },
{ provide: EXTENSION_JSON_VALUES, useValue: [] }
]
});
loader = TestBed.inject(ExtensionLoaderService);
service = TestBed.inject(ExtensionService);
});
it('should load and setup a config', async () => {
@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Injectable, Type, InjectionToken, Inject } from '@angular/core';
import { Injectable, Type, InjectionToken, inject } from '@angular/core';
import { RuleEvaluator, RuleRef, RuleContext } from '../config/rule.extensions';
import { ExtensionConfig } from '../config/extension.config';
import { ExtensionLoaderService } from './extension-loader.service';
@@ -75,6 +75,12 @@ export function provideExtensionConfigValues(extensionConfigValue: ExtensionConf
providedIn: 'root'
})
export class ExtensionService {
protected loader = inject(ExtensionLoaderService);
protected componentRegister = inject(ComponentRegisterService);
protected ruleService = inject(RuleService);
protected extensionJsons = inject(EXTENSION_JSONS);
protected extensionJsonValues = inject(EXTENSION_JSON_VALUES);
configPath = 'assets/app.extensions.json';
pluginsPath = 'assets/plugins';
@@ -88,13 +94,7 @@ export class ExtensionService {
protected config: ExtensionConfig = null;
protected onSetup$ = new BehaviorSubject<ExtensionConfig>(this.config);
constructor(
protected loader: ExtensionLoaderService,
protected componentRegister: ComponentRegisterService,
protected ruleService: RuleService,
@Inject(EXTENSION_JSONS) protected extensionJsons: string[],
@Inject(EXTENSION_JSON_VALUES) protected extensionJsonValues: ExtensionConfig[]
) {
constructor() {
this.setup$ = this.onSetup$.asObservable();
}
@@ -103,7 +103,7 @@ export class ExtensionService {
* @returns The loaded config data
*/
async load(): Promise<ExtensionConfig> {
const config = await this.loader.load(this.configPath, this.pluginsPath, this.extensionJsons.flat(), this.extensionJsonValues.flat());
const config = await this.loader.load(this.configPath, this.pluginsPath, this.extensionJsons.flat(), this.extensionJsonValues.flat() as any);
this.setup(config);
return config;
@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { RuleRef, RuleContext, RuleEvaluator, RuleParameter } from '../config/rule.extensions';
import { ExtensionConfig } from '../config/extension.config';
import { ExtensionLoaderService } from './extension-loader.service';
@@ -24,12 +24,12 @@ import { ExtensionLoaderService } from './extension-loader.service';
providedIn: 'root'
})
export class RuleService {
protected loader = inject(ExtensionLoaderService);
context: RuleContext = null;
rules: Array<RuleRef> = [];
evaluators: { [key: string]: RuleEvaluator } = {};
constructor(protected loader: ExtensionLoaderService) {}
setup(config: ExtensionConfig) {
this.rules = this.loader.getRules(config);
}