diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..e3fb306bc --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,182 @@ +{ + "root": true, + "ignorePatterns": ["**/*"], + "plugins": ["@nrwl/nx"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": { + "@nrwl/nx/enforce-module-boundaries": [ + "error", + { + "enforceBuildableLibDependency": true, + "allow": [], + "depConstraints": [ + { + "sourceTag": "*", + "onlyDependOnLibsWithTags": ["*"] + } + ] + } + ] + } + }, + { + "files": ["*.ts", "*.tsx"], + "extends": ["plugin:@nrwl/nx/typescript"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "extends": ["plugin:@nrwl/nx/javascript"], + "rules": {} + }, + { + "files": ["*.ts"], + "rules": { + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "app", + "style": "kebab-case" + } + ], + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "app", + "style": "camelCase" + } + ], + "@angular-eslint/no-conflicting-lifecycle": "error", + "@angular-eslint/no-host-metadata-property": "error", + "@angular-eslint/no-input-rename": "error", + "@angular-eslint/no-inputs-metadata-property": "error", + "@angular-eslint/no-output-native": "error", + "@angular-eslint/no-output-on-prefix": "error", + "@angular-eslint/no-output-rename": "error", + "@angular-eslint/no-outputs-metadata-property": "error", + "@angular-eslint/use-lifecycle-interface": "error", + "@angular-eslint/use-pipe-transform-interface": "error", + "@typescript-eslint/consistent-type-definitions": "error", + "@typescript-eslint/dot-notation": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/explicit-member-accessibility": [ + "warn", + { + "accessibility": "no-public" + } + ], + "@typescript-eslint/member-ordering": "error", + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "memberLike", + "modifiers": ["readonly"], + "format": ["UPPER_CASE", "camelCase"] + }, + { + "selector": "enumMember", + "format": ["UPPER_CASE"] + }, + { + "selector": "memberLike", + "modifiers": ["private"], + "format": ["camelCase"], + "leadingUnderscore": "require" + }, + { + "selector": "memberLike", + "modifiers": ["protected"], + "format": ["camelCase"], + "leadingUnderscore": "require" + }, + { + "selector": "memberLike", + "modifiers": ["private", "readonly"], + "format": ["UPPER_CASE", "camelCase"], + "leadingUnderscore": "require" + } + ], + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-empty-interface": "error", + "@typescript-eslint/no-inferrable-types": [ + "error", + { + "ignoreParameters": true + } + ], + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/no-non-null-assertion": "error", + "@typescript-eslint/no-shadow": [ + "error", + { + "hoist": "all" + } + ], + "@typescript-eslint/no-unused-expressions": "error", + "@typescript-eslint/prefer-function-type": "error", + "@typescript-eslint/unified-signatures": "error", + "arrow-body-style": "error", + "constructor-super": "error", + "eqeqeq": ["error", "smart"], + "guard-for-in": "error", + "id-blacklist": "off", + "id-match": "off", + "import/no-deprecated": "warn", + "no-bitwise": "error", + "no-caller": "error", + "no-console": [ + "error", + { + "allow": [ + "log", + "warn", + "dir", + "timeLog", + "assert", + "clear", + "count", + "countReset", + "group", + "groupEnd", + "table", + "dirxml", + "error", + "groupCollapsed", + "Console", + "profile", + "profileEnd", + "timeStamp", + "context" + ] + } + ], + "no-debugger": "error", + "no-empty": "off", + "no-eval": "error", + "no-fallthrough": "error", + "no-new-wrappers": "error", + "no-restricted-imports": ["error", "rxjs/Rx"], + "no-throw-literal": "error", + "no-undef-init": "error", + "no-underscore-dangle": "off", + "no-var": "error", + "prefer-const": "error", + "radix": "error" + }, + "plugins": ["eslint-plugin-import", "@angular-eslint/eslint-plugin", "@typescript-eslint"] + }, + { + "files": ["*.html"], + "rules": { + "@angular-eslint/template/banana-in-box": "error", + "@angular-eslint/template/no-negated-async": "error" + }, + "plugins": ["@angular-eslint/eslint-plugin-template"] + } + ] +} diff --git a/angular.json b/angular.json index 1e85832de..4109803d4 100644 --- a/angular.json +++ b/angular.json @@ -1,5 +1,20 @@ { "version": 1, + "cli": { + "defaultCollection": "@nrwl/angular", + "analytics": false, + "packageManager": "yarn" + }, + "defaultProject": "red-ui", + "schematics": { + "@nrwl/angular:application": { + "unitTestRunner": "jest", + "e2eTestRunner": "cypress" + }, + "@nrwl/angular:library": { + "unitTestRunner": "jest" + } + }, "projects": { "red-ui": { "projectType": "application", @@ -59,7 +74,6 @@ "optimization": true, "outputHashing": "all", "sourceMap": false, - "extractCss": true, "namedChunks": false, "extractLicenses": true, "vendorChunk": false, @@ -79,7 +93,8 @@ "serviceWorker": true, "ngswConfigPath": "apps/red-ui/ngsw-config.json" } - } + }, + "outputs": ["{options.outputPath}"] }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", @@ -99,10 +114,9 @@ } }, "lint": { - "builder": "@angular-devkit/build-angular:tslint", + "builder": "@nrwl/linter:eslint", "options": { - "tsConfig": ["apps/red-ui/tsconfig.app.json"], - "exclude": ["**/node_modules/**", "!apps/red-ui/**/*"] + "lintFilePatterns": ["apps/red-ui/src/**/*.ts", "apps/red-ui/src/**/*.html"] } }, "test": { @@ -110,7 +124,8 @@ "options": { "jestConfig": "apps/red-ui/jest.config.js", "passWithNoTests": true - } + }, + "outputs": ["coverage/apps/red-ui"] } } }, @@ -121,17 +136,16 @@ "prefix": "redaction", "architect": { "build": { - "builder": "@angular-devkit/build-ng-packagr:build", + "builder": "@angular-devkit/build-angular:ng-packagr", "options": { "tsConfig": "libs/red-ui-http/tsconfig.lib.json", "project": "libs/red-ui-http/ng-package.json" } }, "lint": { - "builder": "@angular-devkit/build-angular:tslint", + "builder": "@nrwl/linter:eslint", "options": { - "tsConfig": ["libs/red-ui-http/tsconfig.lib.json"], - "exclude": ["**/node_modules/**", "!libs/red-ui-http/**/*"] + "lintFilePatterns": ["libs/red-ui-http/src/**/*.ts", "libs/red-ui-http/src/**/*.html"] } }, "test": { @@ -139,7 +153,8 @@ "options": { "jestConfig": "libs/red-ui-http/jest.config.js", "passWithNoTests": true - } + }, + "outputs": ["coverage/libs/red-ui-http"] } }, "schematics": { @@ -155,10 +170,9 @@ "prefix": "redaction", "architect": { "lint": { - "builder": "@angular-devkit/build-angular:tslint", + "builder": "@nrwl/linter:eslint", "options": { - "tsConfig": ["libs/red-cache/tsconfig.lib.json", "libs/red-cache/tsconfig.spec.json"], - "exclude": ["**/node_modules/**", "!libs/red-cache/**/*"] + "lintFilePatterns": ["libs/red-cache/src/**/*.ts", "libs/red-cache/src/**/*.html"] } }, "test": { @@ -166,7 +180,8 @@ "options": { "jestConfig": "libs/red-cache/jest.config.js", "passWithNoTests": true - } + }, + "outputs": ["coverage/libs/red-cache"] } }, "schematics": { @@ -175,19 +190,5 @@ } } } - }, - "cli": { - "defaultCollection": "@nrwl/angular", - "analytics": false - }, - "schematics": { - "@nrwl/angular:application": { - "unitTestRunner": "jest", - "e2eTestRunner": "cypress" - }, - "@nrwl/angular:library": { - "unitTestRunner": "jest" - } - }, - "defaultProject": "red-ui" + } } diff --git a/apps/.gitkeep b/apps/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/red-ui/.eslintrc.json b/apps/red-ui/.eslintrc.json new file mode 100644 index 000000000..bfaea24bb --- /dev/null +++ b/apps/red-ui/.eslintrc.json @@ -0,0 +1,37 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts"], + "extends": ["plugin:@nrwl/nx/angular", "plugin:@angular-eslint/template/process-inline-templates"], + "parserOptions": { + "project": ["apps/red-ui/tsconfig.*?.json"] + }, + "rules": { + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "redaction", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "redaction", + "style": "kebab-case" + } + ] + }, + "plugins": ["@angular-eslint/eslint-plugin", "@typescript-eslint"] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nrwl/nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/red-ui/jest.config.js b/apps/red-ui/jest.config.js index 0efc9a215..91536f49b 100644 --- a/apps/red-ui/jest.config.js +++ b/apps/red-ui/jest.config.js @@ -1,21 +1,19 @@ module.exports = { - name: 'red-ui', - preset: '../../jest.config.js', + preset: '../../jest.preset.js', setupFilesAfterEnv: ['/src/test-setup.ts'], globals: { 'ts-jest': { - tsConfig: '/tsconfig.spec.json', stringifyContentPathRegex: '\\.(html|svg)$', - astTransformers: [ - 'jest-preset-angular/build/InlineFilesTransformer', - 'jest-preset-angular/build/StripStylesTransformer' - ] + astTransformers: { before: ['jest-preset-angular/build/InlineFilesTransformer', 'jest-preset-angular/build/StripStylesTransformer'] }, + tsconfig: '/tsconfig.spec.json' } }, coverageDirectory: '../../coverage/apps/red-ui', + + displayName: 'red-ui', snapshotSerializers: [ - 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js', - 'jest-preset-angular/build/AngularSnapshotSerializer.js', - 'jest-preset-angular/build/HTMLCommentSerializer.js' + 'jest-preset-angular/build/serializers/no-ng-attributes', + 'jest-preset-angular/build/serializers/ng-snapshot', + 'jest-preset-angular/build/serializers/html-comment' ] }; diff --git a/apps/red-ui/src/app/app-routing.module.ts b/apps/red-ui/src/app/app-routing.module.ts index 4ccfaae0d..737cf6a86 100644 --- a/apps/red-ui/src/app/app-routing.module.ts +++ b/apps/red-ui/src/app/app-routing.module.ts @@ -1,14 +1,14 @@ -import { AuthErrorComponent } from './components/auth-error/auth-error.component'; +import { AuthErrorComponent } from '@components/auth-error/auth-error.component'; import { AuthGuard } from './modules/auth/auth.guard'; -import { CompositeRouteGuard } from './guards/composite-route.guard'; +import { CompositeRouteGuard } from '@guards/composite-route.guard'; import { RedRoleGuard } from './modules/auth/red-role.guard'; -import { BaseScreenComponent } from './components/base-screen/base-screen.component'; +import { BaseScreenComponent } from '@components/base-screen/base-screen.component'; import { RouteReuseStrategy, RouterModule } from '@angular/router'; import { NgModule } from '@angular/core'; -import { DownloadsListScreenComponent } from './components/downloads-list-screen/downloads-list-screen.component'; -import { AppStateGuard } from './state/app-state.guard'; -import { UserProfileScreenComponent } from './components/user-profile/user-profile-screen.component'; -import { CustomRouteReuseStrategy } from './utils/custom-route-reuse.strategy'; +import { DownloadsListScreenComponent } from '@components/downloads-list-screen/downloads-list-screen.component'; +import { AppStateGuard } from '@state/app-state.guard'; +import { UserProfileScreenComponent } from '@components/user-profile/user-profile-screen.component'; +import { CustomRouteReuseStrategy } from '@utils/custom-route-reuse.strategy'; const routes = [ { diff --git a/apps/red-ui/src/app/app.component.html b/apps/red-ui/src/app/app.component.html index 7115e458f..80f9c88ad 100644 --- a/apps/red-ui/src/app/app.component.html +++ b/apps/red-ui/src/app/app.component.html @@ -1,4 +1,2 @@ - + diff --git a/apps/red-ui/src/app/app.component.ts b/apps/red-ui/src/app/app.component.ts index d8a314e3b..d916c2840 100644 --- a/apps/red-ui/src/app/app.component.ts +++ b/apps/red-ui/src/app/app.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; -import { AppLoadStateService } from './services/app-load-state.service'; -import { RouterHistoryService } from './services/router-history.service'; +import { AppLoadStateService } from '@services/app-load-state.service'; +import { RouterHistoryService } from '@services/router-history.service'; @Component({ selector: 'redaction-root', diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index 34210459f..7313a7497 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -4,34 +4,34 @@ import { AppComponent } from './app.component'; import { ActivatedRoute, Router } from '@angular/router'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http'; -import { BaseScreenComponent } from './components/base-screen/base-screen.component'; +import { BaseScreenComponent } from '@components/base-screen/base-screen.component'; import { ApiModule } from '@redaction/red-ui-http'; -import { ApiPathInterceptor } from './utils/api-path-interceptor'; +import { ApiPathInterceptor } from '@utils/api-path-interceptor'; import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; -import { languageInitializer } from './i18n/language.initializer'; -import { LanguageService } from './i18n/language.service'; +import { languageInitializer } from '@i18n/language.initializer'; +import { LanguageService } from '@i18n/language.service'; import { ToastrModule } from 'ngx-toastr'; import { ServiceWorkerModule } from '@angular/service-worker'; -import { environment } from '../environments/environment'; +import { environment } from '@environments/environment'; import { AuthModule } from './modules/auth/auth.module'; -import { LogoComponent } from './components/logo/logo.component'; -import { AuthErrorComponent } from './components/auth-error/auth-error.component'; -import { ToastComponent } from './components/toast/toast.component'; +import { LogoComponent } from '@components/logo/logo.component'; +import { AuthErrorComponent } from '@components/auth-error/auth-error.component'; +import { ToastComponent } from '@components/toast/toast.component'; import { HttpCacheInterceptor } from '@redaction/red-cache'; -import { NotificationsComponent } from './components/notifications/notifications.component'; +import { NotificationsComponent } from '@components/notifications/notifications.component'; import { KeycloakService } from 'keycloak-angular'; -import { DownloadsListScreenComponent } from './components/downloads-list-screen/downloads-list-screen.component'; +import { DownloadsListScreenComponent } from '@components/downloads-list-screen/downloads-list-screen.component'; import { AppRoutingModule } from './app-routing.module'; -import { SharedModule } from './modules/shared/shared.module'; -import { FileUploadDownloadModule } from './modules/upload-download/file-upload-download.module'; -import { UserProfileScreenComponent } from './components/user-profile/user-profile-screen.component'; +import { SharedModule } from '@shared/shared.module'; +import { FileUploadDownloadModule } from '@upload-download/file-upload-download.module'; +import { UserProfileScreenComponent } from '@components/user-profile/user-profile-screen.component'; import { PlatformLocation } from '@angular/common'; import { BASE_HREF } from './tokens'; -declare var ace; +declare let ace; -export function HttpLoaderFactory(httpClient: HttpClient) { +export function httpLoaderFactory(httpClient: HttpClient) { return new TranslateHttpLoader(httpClient, '/assets/i18n/', '.json'); } @@ -68,7 +68,7 @@ const components = [AppComponent, LogoComponent, AuthErrorComponent, ToastCompon TranslateModule.forRoot({ loader: { provide: TranslateLoader, - useFactory: HttpLoaderFactory, + useFactory: httpLoaderFactory, deps: [HttpClient] } }), diff --git a/apps/red-ui/src/app/components/auth-error/auth-error.component.html b/apps/red-ui/src/app/components/auth-error/auth-error.component.html index eb7dd22d8..a3d625205 100644 --- a/apps/red-ui/src/app/components/auth-error/auth-error.component.html +++ b/apps/red-ui/src/app/components/auth-error/auth-error.component.html @@ -1,19 +1,19 @@
-

+

diff --git a/apps/red-ui/src/app/components/auth-error/auth-error.component.ts b/apps/red-ui/src/app/components/auth-error/auth-error.component.ts index b6516e085..351af3380 100644 --- a/apps/red-ui/src/app/components/auth-error/auth-error.component.ts +++ b/apps/red-ui/src/app/components/auth-error/auth-error.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { UserService } from '../../services/user.service'; -import { AppConfigKey, AppConfigService } from '../../modules/app-config/app-config.service'; +import { UserService } from '@services/user.service'; +import { AppConfigKey, AppConfigService } from '@app-config/app-config.service'; @Component({ selector: 'redaction-auth-error', diff --git a/apps/red-ui/src/app/components/base-screen/base-screen.component.html b/apps/red-ui/src/app/components/base-screen/base-screen.component.html index 8ba2f7f19..984874129 100644 --- a/apps/red-ui/src/app/components/base-screen/base-screen.component.html +++ b/apps/red-ui/src/app/components/base-screen/base-screen.component.html @@ -1,7 +1,7 @@
- -