From b4156074eb1951dfaa7e53aeec5611e466d817eb Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sun, 26 Mar 2023 14:50:45 +0300 Subject: [PATCH] stricter rules --- .eslintrc.json | 104 +++++++++++++----- .../table-column-name.component.ts | 6 +- .../directives/allow.directive.spec.ts | 4 +- .../directives/deny.directive.spec.ts | 4 +- .../services/permissions-guard.service.ts | 2 +- 5 files changed, 86 insertions(+), 34 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 415447a..940de35 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,36 +1,25 @@ { + "root": true, "env": { - "browser": true, - "node": true + "browser": true }, "ignorePatterns": ["!**/*"], "overrides": [ { - "files": ["**/*.ts"], + "files": ["*.ts"], + "extends": ["plugin:@typescript-eslint/recommended"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, "rules": { - "@angular-eslint/directive-selector": [ + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/explicit-member-accessibility": [ "error", { - "type": "attribute", - "prefix": "iqser", - "style": "camelCase" + "accessibility": "no-public" } ], - "@angular-eslint/component-selector": [ - "error", - { - "type": "element", - "prefix": "iqser", - "style": "kebab-case" - } - ], - "@angular-eslint/prefer-on-push-component-change-detection": "error", - "@angular-eslint/use-lifecycle-interface": "error", - "@angular-eslint/no-input-prefix": "error", - "@angular-eslint/no-input-rename": "error", - "@angular-eslint/no-output-on-prefix": "error", - "@angular-eslint/no-output-rename": "error", - "@angular-eslint/prefer-output-readonly": "error", "@typescript-eslint/unbound-method": "error", "@typescript-eslint/no-floating-promises": "off", "@typescript-eslint/naming-convention": [ @@ -54,14 +43,79 @@ "leadingUnderscore": "allow" } ], + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/lines-between-class-members": "off" + } + }, + { + "files": ["*.ts"], + "extends": [ + "eslint:recommended", + "plugin:@angular-eslint/recommended", + "plugin:@angular-eslint/recommended--extra", + "plugin:@angular-eslint/template/process-inline-templates", + "plugin:prettier/recommended", + "plugin:rxjs/recommended" + ], + "rules": { + "rxjs/no-ignored-subscription": "error", + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "iqser", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "iqser", + "style": "kebab-case" + } + ], + "@angular-eslint/prefer-on-push-component-change-detection": "error", + "@angular-eslint/use-lifecycle-interface": "error", + "@angular-eslint/no-input-prefix": "error", + "@angular-eslint/no-input-rename": "error", + "@angular-eslint/no-output-on-prefix": "error", + "@angular-eslint/no-output-rename": "error", + "@angular-eslint/prefer-output-readonly": "error", "no-underscore-dangle": "off", "no-param-reassign": "error", "no-dupe-class-members": "off", "no-redeclare": "off", "no-unused-vars": "off", - "consistent-return": "off", - "@typescript-eslint/restrict-template-expressions": "off", - "@typescript-eslint/lines-between-class-members": "off" + "consistent-return": "off" + } + }, + { + "files": ["*.html"], + "extends": ["plugin:@angular-eslint/template/recommended"] + }, + { + // https://github.com/angular-eslint/angular-eslint#notes-for-eslint-plugin-prettier-users + "files": ["*.html"], + "excludedFiles": ["*inline-template-*.component.html"], + "extends": ["plugin:prettier/recommended"], + "rules": { + "prettier/prettier": [ + "error", + { + "parser": "angular" + } + ] + } + }, + { + "files": ["**/*.spec.ts"], + "env": { + "node": true, + "jest": true + }, + "rules": { + "@angular-eslint/prefer-on-push-component-change-detection": "off" } } ] diff --git a/src/lib/listing/table-column-name/table-column-name.component.ts b/src/lib/listing/table-column-name/table-column-name.component.ts index 5e0d4e6..16f870c 100644 --- a/src/lib/listing/table-column-name/table-column-name.component.ts +++ b/src/lib/listing/table-column-name/table-column-name.component.ts @@ -1,10 +1,8 @@ import { ChangeDetectionStrategy, Component, Input, Optional } from '@angular/core'; import { SortingOrders, SortingService } from '../../sorting'; -import { KeysOf, Required } from '../../utils'; +import { KeysOf } from '../../utils'; import { Id, IListable } from '../models'; -const ifHasRightIcon = (thisArg: TableColumnNameComponent) => !!thisArg.rightIcon; - @Component({ selector: 'iqser-table-column-name [label]', templateUrl: './table-column-name.component.html', @@ -19,7 +17,7 @@ export class TableColumnNameComponent, PrimaryKe @Input() class?: string; @Input() leftIcon?: string; @Input() rightIcon?: string; - @Input() @Required(ifHasRightIcon) rightIconTooltip?: string; + @Input() rightIconTooltip?: string; constructor(@Optional() readonly sortingService: SortingService) {} } diff --git a/src/lib/permissions/directives/allow.directive.spec.ts b/src/lib/permissions/directives/allow.directive.spec.ts index a43485a..162fc86 100644 --- a/src/lib/permissions/directives/allow.directive.spec.ts +++ b/src/lib/permissions/directives/allow.directive.spec.ts @@ -415,7 +415,7 @@ describe('Permission directive with different async functions in permissions via permissionsService.add({ ADMIN: (name, store) => { expect(name).toBeTruthy(); - expect(store[name!].name).toBeTruthy(); + expect(store[name].name).toBeTruthy(); return name === ADMIN; }, }); @@ -483,7 +483,7 @@ describe('Permission directive testing different async functions in permissions permissionsService.add({ ADMIN: (name, store) => { expect(name).toBeTruthy(); - expect(store[name!].name).toBeTruthy(); + expect(store[name].name).toBeTruthy(); return name === ADMIN; }, }); diff --git a/src/lib/permissions/directives/deny.directive.spec.ts b/src/lib/permissions/directives/deny.directive.spec.ts index 27ef4d5..46c3ce5 100644 --- a/src/lib/permissions/directives/deny.directive.spec.ts +++ b/src/lib/permissions/directives/deny.directive.spec.ts @@ -386,7 +386,7 @@ describe('Permission directive with different async functions in permissions via permissionsService.add({ ADMIN: (name, store) => { expect(name).toBeTruthy(); - expect(store[name!].name).toBeTruthy(); + expect(store[name].name).toBeTruthy(); return name === ADMIN; }, }); @@ -468,7 +468,7 @@ describe('Permission directive testing different async functions in permissions permissionsService.add({ ADMIN: (name, store) => { expect(name).toBeTruthy(); - expect(store[name!].name).toBeTruthy(); + expect(store[name].name).toBeTruthy(); return name === ADMIN; }, }); diff --git a/src/lib/permissions/services/permissions-guard.service.ts b/src/lib/permissions/services/permissions-guard.service.ts index 6d95ae1..921eb81 100644 --- a/src/lib/permissions/services/permissions-guard.service.ts +++ b/src/lib/permissions/services/permissions-guard.service.ts @@ -121,7 +121,7 @@ export class IqserPermissionsGuard implements CanActivate, CanMatch, CanActivate return redirectHandle.then(() => false); } - if (!!failedPermission) { + if (failedPermission) { const redirectHandle = this.#handleRedirectOfFailedPermission(permissions, failedPermission, route, state); return redirectHandle.then(() => !pass); }