Skip to content

Commit a41299a

Browse files
committed
Libraries converted from TSLint to ESLint and linting fixed
1 parent ac538b9 commit a41299a

20 files changed

+1055
-428
lines changed

.eslintrc.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": [
4+
"projects/**/*"
5+
],
6+
"overrides": [
7+
{
8+
"files": [
9+
"*.ts"
10+
],
11+
"parserOptions": {
12+
"project": [
13+
"tsconfig.json",
14+
"e2e/tsconfig.json"
15+
],
16+
"createDefaultProgram": true
17+
},
18+
"extends": [
19+
"plugin:@angular-eslint/ng-cli-compat",
20+
"plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
21+
"plugin:@angular-eslint/template/process-inline-templates"
22+
],
23+
"rules": {
24+
"@typescript-eslint/explicit-member-accessibility": [
25+
"off",
26+
{
27+
"accessibility": "explicit"
28+
}
29+
],
30+
"arrow-parens": [
31+
"off",
32+
"always"
33+
],
34+
"import/order": "off"
35+
}
36+
},
37+
{
38+
"files": [
39+
"*.html"
40+
],
41+
"extends": [
42+
"plugin:@angular-eslint/template/recommended"
43+
],
44+
"rules": {}
45+
}
46+
]
47+
}

README.asciidoc

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ toc::[]
1717

1818
= devon4ng library
1919

20-
This project was generated with https://github.com/angular/angular-cli[Angular CLI] version 7.3.6 and upgraded to Angular 8.0.1. It contains the devon4ng libraries.
20+
This project was generated with https://github.com/angular/angular-cli[Angular CLI] version 7.3.6 and upgraded to Angular 11.2.1. It contains the devon4ng libraries.
2121

2222
== Library catalogue
2323

@@ -28,7 +28,10 @@ This repository includes the following devon4ng libraries.
2828

2929
== Project Requirements
3030

31-
In order to use these libraries your project must use at least **Angular 7** in order to ensure the library will work as expected.
31+
In order to use these libraries your project must use at least **Angular 7** in order to ensure the library will work as expected. To install **the correct vesion for your Angular project** please refer to the versions in the correspondent npm package page:
32+
33+
- link:https://www.npmjs.com/package/@devon4ng/cache?activeTab=versions[@devon4ng/cache versions]
34+
- link:https://www.npmjs.com/package/@devon4ng/authorization?activeTab=versions[@devon4ng/authorization versions]
3235

3336
== How to contribute
3437

angular.json

+15-21
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"options": {
1515
"tsConfig": "projects/devon4ng/cache/tsconfig.lib.json",
1616
"project": "projects/devon4ng/cache/ng-package.json"
17-
}
18-
, "configurations": {
17+
},
18+
"configurations": {
1919
"production": {
2020
"tsConfig": "projects/devon4ng/cache/tsconfig.lib.prod.json"
2121
}
2222
}
23-
},
23+
},
2424
"test": {
2525
"builder": "@angular-devkit/build-angular:karma",
2626
"options": {
@@ -30,14 +30,11 @@
3030
}
3131
},
3232
"lint": {
33-
"builder": "@angular-devkit/build-angular:tslint",
33+
"builder": "@angular-eslint/builder:lint",
3434
"options": {
35-
"tsConfig": [
36-
"projects/devon4ng/cache/tsconfig.lib.json",
37-
"projects/devon4ng/cache/tsconfig.spec.json"
38-
],
39-
"exclude": [
40-
"**/node_modules/**"
35+
"lintFilePatterns": [
36+
"projects/devon4ng/cache/**/*.ts",
37+
"projects/devon4ng/cache/**/*.html"
4138
]
4239
}
4340
}
@@ -54,13 +51,13 @@
5451
"options": {
5552
"tsConfig": "projects/devon4ng/authorization/tsconfig.lib.json",
5653
"project": "projects/devon4ng/authorization/ng-package.json"
57-
}
58-
, "configurations": {
54+
},
55+
"configurations": {
5956
"production": {
6057
"tsConfig": "projects/devon4ng/authorization/tsconfig.lib.prod.json"
6158
}
6259
}
63-
},
60+
},
6461
"test": {
6562
"builder": "@angular-devkit/build-angular:karma",
6663
"options": {
@@ -70,19 +67,16 @@
7067
}
7168
},
7269
"lint": {
73-
"builder": "@angular-devkit/build-angular:tslint",
70+
"builder": "@angular-eslint/builder:lint",
7471
"options": {
75-
"tsConfig": [
76-
"projects/devon4ng/authorization/tsconfig.lib.json",
77-
"projects/devon4ng/authorization/tsconfig.spec.json"
78-
],
79-
"exclude": [
80-
"**/node_modules/**"
72+
"lintFilePatterns": [
73+
"projects/devon4ng/authorization/**/*.ts",
74+
"projects/devon4ng/authorization/**/*.html"
8175
]
8276
}
8377
}
8478
}
8579
}
8680
},
8781
"defaultProject": "@devon4ng/cache"
88-
}
82+
}

package.json

+14-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"start": "ng serve",
1212
"build": "ng build",
1313
"test": "ng test",
14-
"lint": "ng lint",
14+
"lint:cache": "npx ng lint @devon4ng/cache",
15+
"lint:authorization": "npx ng lint @devon4ng/authorization",
1516
"e2e": "ng e2e"
1617
},
1718
"private": true,
@@ -32,14 +33,24 @@
3233
},
3334
"devDependencies": {
3435
"@angular-devkit/build-angular": "~0.1102.1",
36+
"@angular-eslint/builder": "1.2.0",
37+
"@angular-eslint/eslint-plugin": "1.2.0",
38+
"@angular-eslint/eslint-plugin-template": "1.2.0",
39+
"@angular-eslint/schematics": "1.2.0",
40+
"@angular-eslint/template-parser": "1.2.0",
3541
"@angular/cli": "~11.2.1",
3642
"@angular/compiler-cli": "~11.2.1",
3743
"@angular/language-service": "~11.2.1",
3844
"@types/jasmine": "~3.6.0",
3945
"@types/jasminewd2": "~2.0.3",
4046
"@types/node": "^12.11.1",
4147
"@types/object-hash": "^1.3.4",
42-
"codelyzer": "^6.0.0",
48+
"@typescript-eslint/eslint-plugin": "4.3.0",
49+
"@typescript-eslint/parser": "4.3.0",
50+
"eslint": "^7.6.0",
51+
"eslint-plugin-import": "2.22.1",
52+
"eslint-plugin-jsdoc": "30.7.6",
53+
"eslint-plugin-prefer-arrow": "1.2.2",
4354
"jasmine-core": "~3.6.0",
4455
"jasmine-spec-reporter": "~5.0.0",
4556
"karma": "~6.1.1",
@@ -50,7 +61,6 @@
5061
"ng-packagr": "^11.2.2",
5162
"protractor": "~7.0.0",
5263
"ts-node": "~7.0.0",
53-
"tslint": "~6.1.0",
5464
"typescript": "~4.0.7"
5565
}
56-
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"extends": "../../../.eslintrc.json",
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"parserOptions": {
8+
"project": [
9+
"projects/devon4ng/authorization/tsconfig.lib.json",
10+
"projects/devon4ng/authorization/tsconfig.spec.json"
11+
],
12+
"createDefaultProgram": true
13+
},
14+
"rules": {
15+
"@angular-eslint/component-selector": [
16+
"error",
17+
{
18+
"type": "element",
19+
"prefix": "daon",
20+
"style": "kebab-case"
21+
}
22+
],
23+
"@angular-eslint/directive-selector": [
24+
"error",
25+
{
26+
"type": "attribute",
27+
"prefix": "daon",
28+
"style": "camelCase"
29+
}
30+
],
31+
"@typescript-eslint/explicit-member-accessibility": [
32+
"off",
33+
{
34+
"accessibility": "explicit"
35+
}
36+
],
37+
"arrow-parens": ["off", "always"],
38+
"import/order": "off"
39+
}
40+
},
41+
{
42+
"files": ["*.html"],
43+
"rules": {}
44+
}
45+
]
46+
}

projects/devon4ng/authorization/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devon4ng/authorization",
3-
"version": "11.0.0",
3+
"version": "11.0.1",
44
"description": "Adds rights-based authorization to your Angular app's routes",
55
"author": {
66
"name": "devonfw team"
@@ -26,4 +26,4 @@
2626
"@angular/router": "^11.2.0",
2727
"rxjs": "^6.6.0"
2828
}
29-
}
29+
}

projects/devon4ng/authorization/src/lib/devonfw-authorization.module.spec.ts

+33-43
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
/* eslint-disable no-shadow */
13
import { Component } from '@angular/core';
24
import { fakeAsync, TestBed, TestModuleMetadata, tick } from '@angular/core/testing';
35
import { RouterTestingModule } from '@angular/router/testing';
@@ -181,13 +183,13 @@ describe('DevonfwAuthorizationModule', () => {
181183
});
182184
});
183185

184-
function whenNavigateTo(commands: any[]) {
186+
const whenNavigateTo = (commands: any[]) => {
185187
const appComponentFixture = TestBed.createComponent(MyTestAppComponent);
186188
const router: Router = TestBed.inject(Router);
187189
const location: Location = TestBed.inject(Location);
188190

189191
return {
190-
thenExpectLocationPathToEqual(path: string) {
192+
thenExpectLocationPathToEqual: (path: string) => {
191193
appComponentFixture.ngZone.run(() => {
192194
// when
193195
router.navigate(commands);
@@ -200,10 +202,10 @@ function whenNavigateTo(commands: any[]) {
200202
});
201203
},
202204
};
203-
}
205+
};
204206

205-
function configureTestingModule<R>(config?: AuthorizationModuleConfig) {
206-
function configureTestingModuleProvidingMock(authorizationServiceMock?: IsAuthorized<R>) {
207+
const configureTestingModule = <R>(config?: AuthorizationModuleConfig) => {
208+
const configureTestingModuleProvidingMock = (authorizationServiceMock?: IsAuthorized<R>) => {
207209
const testingModuleDefinition: TestModuleMetadata = {
208210
declarations: [MyTestAppComponent, MyTestPageComponent],
209211
imports: [RouterTestingModule.withRoutes(routes), DevonfwAuthorizationModule.forRoot(config)],
@@ -221,61 +223,49 @@ function configureTestingModule<R>(config?: AuthorizationModuleConfig) {
221223
TestBed.configureTestingModule(testingModuleDefinition);
222224
const router: Router = TestBed.inject(Router);
223225
addAuthorizationGuards(router);
224-
}
226+
};
225227

226228
return {
227-
withDummyAuthorization() {
229+
withDummyAuthorization: () => {
228230
configureTestingModuleProvidingMock();
229231
},
230232

231-
withFailingAuthorization() {
233+
withFailingAuthorization: () => {
232234
configureTestingModuleProvidingMock(createAuthorizationServiceMock<R>().whichFails());
233235
},
234236

235-
forUserHavingRightsOf(userRights: R[]) {
237+
forUserHavingRightsOf: (userRights: R[]) => {
236238
configureTestingModuleProvidingMock(createAuthorizationServiceMock<R>().forUserHavingRightsOf(userRights));
237239
},
238240

239-
forUnauthorizedUsers() {
241+
forUnauthorizedUsers: () => {
240242
configureTestingModuleProvidingMock(createAuthorizationServiceMock<R>().forUnauthorizedUsers());
241243
},
242244
};
243-
}
245+
};
244246

245-
export function createAuthorizationServiceMock<R>() {
246-
return {
247-
forUserHavingRightsOf(userRights: R[]): IsAuthorized<R> {
248-
return {
249-
isAuthorizedForRightsOf(requiredRights: R[]): Observable<boolean> {
250-
let isAuthorized = true;
247+
export const createAuthorizationServiceMock = <R>() => ({
248+
forUserHavingRightsOf: (userRights: R[]): IsAuthorized<R> => ({
249+
isAuthorizedForRightsOf: (requiredRights: R[]): Observable<boolean> => {
250+
let isAuthorized = true;
251251

252-
if (requiredRights && requiredRights.length > 0) {
253-
isAuthorized = requiredRights.reduce(
254-
(requiredAuthorizationFulfilled, requiredRight) =>
255-
requiredAuthorizationFulfilled ? (userRights ? userRights.includes(requiredRight) : false) : false,
256-
true
257-
);
258-
}
252+
if (requiredRights && requiredRights.length > 0) {
253+
isAuthorized = requiredRights.reduce(
254+
(requiredAuthorizationFulfilled, requiredRight) =>
255+
requiredAuthorizationFulfilled ? (userRights ? userRights.includes(requiredRight) : false) : false,
256+
true
257+
);
258+
}
259259

260-
return of(isAuthorized);
261-
},
262-
};
260+
return of(isAuthorized);
263261
},
262+
}),
264263

265-
forUnauthorizedUsers(): IsAuthorized<R> {
266-
return {
267-
isAuthorizedForRightsOf(): Observable<boolean> {
268-
return of(false);
269-
},
270-
};
271-
},
264+
forUnauthorizedUsers: (): IsAuthorized<R> => ({
265+
isAuthorizedForRightsOf: (): Observable<boolean> => of(false),
266+
}),
272267

273-
whichFails(): IsAuthorized<R> {
274-
return {
275-
isAuthorizedForRightsOf(): Observable<boolean> {
276-
return throwError(new Error());
277-
},
278-
};
279-
},
280-
};
281-
}
268+
whichFails: (): IsAuthorized<R> => ({
269+
isAuthorizedForRightsOf: (): Observable<boolean> => throwError(new Error()),
270+
}),
271+
});

projects/devon4ng/authorization/src/lib/guard/authorization.guard.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ describe('AuthorizationGuard', () => {
99
const guard = new AuthorizationGuard(routerMock, authorizationServiceMock, {});
1010

1111
const routeWithoutConfig: any = {};
12-
const state: any = {};
1312
// when
14-
const canActivate = guard.canActivate(routeWithoutConfig, state);
13+
const canActivate = guard.canActivate(routeWithoutConfig);
1514
// then
1615
expect(canActivate).toBeFalsy();
1716
});

0 commit comments

Comments
 (0)