From 632c4540564117092d1f196099f59b6e0d3e9fdc Mon Sep 17 00:00:00 2001 From: Yuri Cherepanov Date: Fri, 15 Nov 2019 22:45:10 +0200 Subject: [PATCH 1/5] require is not defined fix security issue with http local server: https://github.com/electron/electron/blob/master/docs/api/browser-window.md#class-browserwindow beutify dev-web -> web fix tslint.json v5 naming issue --- angular.json | 6 +++--- main.ts | 1 + package.json | 4 ++-- tslint.json | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/angular.json b/angular.json index 82bf5d7bd..df3fb4642 100644 --- a/angular.json +++ b/angular.json @@ -50,7 +50,7 @@ } ] }, - "dev-web": { + "web": { "optimization": false, "outputHashing": "all", "sourceMap": true, @@ -95,8 +95,8 @@ "dev": { "browserTarget": "angular-electron:build:dev" }, - "dev-web": { - "browserTarget": "angular-electron:build:dev-web" + "web": { + "browserTarget": "angular-electron:build:web" }, "production": { "browserTarget": "angular-electron:build:production" diff --git a/main.ts b/main.ts index 71bd5864b..793275d1b 100644 --- a/main.ts +++ b/main.ts @@ -19,6 +19,7 @@ function createWindow() { height: size.height, webPreferences: { nodeIntegration: true, + allowRunningInsecureContent: (serve) ? true : false, }, }); diff --git a/package.json b/package.json index bbbcf127f..c5e054904 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "build:dev": "npm run build -- -c dev", "build:prod": "npm run build -- -c production", "ng:serve": "ng serve", - "ng:serve:web": "ng serve -c dev-web -o", + "ng:serve:web": "ng serve -c web -o", "electron:serve-tsc": "tsc -p tsconfig-serve.json", "electron:serve": "wait-on http-get://localhost:4200/ && npm run electron:serve-tsc && electron . --serve", "electron:local": "npm run build:prod && electron .", @@ -59,7 +59,7 @@ "codelyzer": "5.1.0", "conventional-changelog-cli": "2.0.25", "core-js": "3.1.4", - "electron": "7.0.0", + "electron": "7.1.1", "electron-builder": "21.2.0", "electron-reload": "1.5.0", "jasmine-core": "3.4.0", diff --git a/tslint.json b/tslint.json index d67588335..6da6f449a 100644 --- a/tslint.json +++ b/tslint.json @@ -80,7 +80,7 @@ } ], "unified-signatures": true, - "use-life-cycle-interface": true, + "use-lifecycle-interface": true, "use-lifecycle-interface": true, "use-pipe-transform-interface": true, "variable-name": false, From 7637f459630b0910c07408afdb5b25934704992c Mon Sep 17 00:00:00 2001 From: Yuri Cherepanov Date: Mon, 18 Nov 2019 00:26:58 +0200 Subject: [PATCH 2/5] eslint-migration --- angular.json | 6 +++-- e2e/eslintrc.e2e.json | 6 +++++ eslintrc.json | 24 +++++++++++++++++++ main.ts | 9 +++---- package.json | 6 ++++- src/app/app.module.ts | 2 +- .../services/electron/electron.service.ts | 2 +- src/eslintrc.config.json | 6 +++++ 8 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 e2e/eslintrc.e2e.json create mode 100644 eslintrc.json create mode 100644 src/eslintrc.config.json diff --git a/angular.json b/angular.json index df3fb4642..ceda86d98 100644 --- a/angular.json +++ b/angular.json @@ -135,8 +135,9 @@ } }, "lint": { - "builder": "@angular-devkit/build-angular:tslint", + "builder": "@angular-eslint/builder:lint", "options": { + "eslintConfig": "src/eslintrc.config.json", "tsConfig": [ "src/tsconfig.app.json", "src/tsconfig.spec.json" @@ -153,8 +154,9 @@ "projectType": "application", "architect": { "lint": { - "builder": "@angular-devkit/build-angular:tslint", + "builder": "@angular-eslint/builder:lint", "options": { + "eslintConfig": "e2e/eslintrc.e2e.json", "tsConfig": [ "e2e/tsconfig.e2e.json" ], diff --git a/e2e/eslintrc.e2e.json b/e2e/eslintrc.e2e.json new file mode 100644 index 000000000..51edf1908 --- /dev/null +++ b/e2e/eslintrc.e2e.json @@ -0,0 +1,6 @@ +{ + "extends": "../eslintrc.json", + "parserOptions": { + "project": ["e2e/tsconfig.e2e.json"] + } +} diff --git a/eslintrc.json b/eslintrc.json new file mode 100644 index 000000000..3e88df3c9 --- /dev/null +++ b/eslintrc.json @@ -0,0 +1,24 @@ +{ + "env": { + "browser": true, + "node": true, + "es6": true, + "es2017": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "tsconfigRootDir": "." + }, + "plugins": ["@typescript-eslint"], + "rules": { + "no-empty-function": ["warn"], + "@typescript-eslint/no-empty-function": ["warn"], + "@typescript-eslint/no-var-requires": ["warn"] + } +} diff --git a/main.ts b/main.ts index 793275d1b..e38690786 100644 --- a/main.ts +++ b/main.ts @@ -2,11 +2,11 @@ import { app, BrowserWindow, screen } from 'electron'; import * as path from 'path'; import * as url from 'url'; -let win, serve; -const args = process.argv.slice(1); -serve = args.some(val => val === '--serve'); +let win: BrowserWindow = null; +const args = process.argv.slice(1), + serve = args.some(val => val === '--serve'); -function createWindow() { +function createWindow(): BrowserWindow { const electronScreen = screen; const size = electronScreen.getPrimaryDisplay().workAreaSize; @@ -48,6 +48,7 @@ function createWindow() { win = null; }); + return win; } try { diff --git a/package.json b/package.json index c5e054904..39f736fe0 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "devDependencies": { "@angular-builders/custom-webpack": "^8.2.0", "@angular-devkit/build-angular": "0.803.6", + "@angular-eslint/builder": "0.0.1-alpha.17", "@angular/cli": "8.3.6", "@angular/common": "8.2.12", "@angular/compiler": "8.2.12", @@ -55,6 +56,8 @@ "@types/jasminewd2": "2.0.6", "@types/mocha": "5.2.7", "@types/node": "12.6.8", + "@typescript-eslint/eslint-plugin": "^2.7.0", + "@typescript-eslint/parser": "^2.7.0", "chai": "4.2.0", "codelyzer": "5.1.0", "conventional-changelog-cli": "2.0.25", @@ -62,6 +65,8 @@ "electron": "7.1.1", "electron-builder": "21.2.0", "electron-reload": "1.5.0", + "eslint": "^6.6.0", + "eslint-plugin-import": "^2.18.2", "jasmine-core": "3.4.0", "jasmine-spec-reporter": "4.2.1", "karma": "4.2.0", @@ -74,7 +79,6 @@ "rxjs": "6.5.3", "spectron": "9.0.0", "ts-node": "8.3.0", - "tslint": "5.20.0", "typescript": "3.5.3", "wait-on": "3.3.0", "webdriver-manager": "12.1.5", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 876d7ce96..b2f66c70e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -19,7 +19,7 @@ import { HomeModule } from './home/home.module'; import { AppComponent } from './app.component'; // AoT requires an exported function for factories -export function HttpLoaderFactory(http: HttpClient) { +export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader { return new TranslateHttpLoader(http, './assets/i18n/', '.json'); } diff --git a/src/app/core/services/electron/electron.service.ts b/src/app/core/services/electron/electron.service.ts index 411ef54d0..7a9e766d8 100644 --- a/src/app/core/services/electron/electron.service.ts +++ b/src/app/core/services/electron/electron.service.ts @@ -16,7 +16,7 @@ export class ElectronService { childProcess: typeof childProcess; fs: typeof fs; - get isElectron() { + get isElectron(): boolean { return window && window.process && window.process.type; } diff --git a/src/eslintrc.config.json b/src/eslintrc.config.json new file mode 100644 index 000000000..ad87184e5 --- /dev/null +++ b/src/eslintrc.config.json @@ -0,0 +1,6 @@ +{ + "extends": "../eslintrc.json", + "parserOptions": { + "project": ["src/tsconfig.app.json", "src/tsconfig.spec.json"] + } +} From 3c1f9f6caaa59d076b083c250ff535f8c70d77fb Mon Sep 17 00:00:00 2001 From: Yuri Cherepanov Date: Mon, 18 Nov 2019 00:39:59 +0200 Subject: [PATCH 3/5] eslint-migration - remove tslint.json configuration --- tslint.json | 96 ----------------------------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 tslint.json diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 6da6f449a..000000000 --- a/tslint.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "rulesDirectory": ["node_modules/codelyzer"], - "rules": { - "arrow-return-shorthand": true, - "callable-types": true, - "class-name": true, - "comment-format": [true, "check-space"], - "component-class-suffix": true, - "component-selector": [true, "element", "app", "kebab-case"], - "curly": true, - "deprecation": { "severity": "warn" }, - "directive-class-suffix": true, - "eofline": true, - "forin": true, - "import-blacklist": [true, "rxjs/Rx"], - "import-spacing": true, - "indent": [true, "spaces"], - "interface-over-type-literal": true, - "label-position": true, - "max-line-length": [true, 140], - "member-access": false, - "member-ordering": [ - true, - { - "order": [ - "static-field", - "instance-field", - "static-method", - "instance-method" - ] - } - ], - "no-arg": true, - "no-bitwise": true, - "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], - "no-construct": true, - "no-debugger": true, - "no-duplicate-super": true, - "no-empty": false, - "no-empty-interface": true, - "no-eval": true, - "no-host-metadata-property": true, - "no-inferrable-types": [true, "ignore-params"], - "no-input-rename": true, - "no-inputs-metadata-property": true, - "no-misused-new": true, - "no-non-null-assertion": true, - "no-output-on-prefix": true, - "no-output-rename": true, - "no-outputs-metadata-property": true, - "no-shadowed-variable": true, - "no-string-literal": false, - "no-string-throw": true, - "no-switch-case-fall-through": true, - "no-trailing-whitespace": true, - "no-unnecessary-initializer": true, - "no-unused-expression": true, - "no-var-keyword": true, - "object-literal-sort-keys": false, - "one-line": [ - true, - "check-open-brace", - "check-catch", - "check-else", - "check-whitespace" - ], - "prefer-const": true, - "quotemark": [true, "single"], - "radix": true, - "semicolon": [true, "always"], - "triple-equals": [true, "allow-null-check"], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - } - ], - "unified-signatures": true, - "use-lifecycle-interface": true, - "use-lifecycle-interface": true, - "use-pipe-transform-interface": true, - "variable-name": false, - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] - } -} From 99e7ec00bf78c936f6cd0c0317e5871d7f58404d Mon Sep 17 00:00:00 2001 From: Yuri Cherepanov Date: Mon, 18 Nov 2019 01:24:07 +0200 Subject: [PATCH 4/5] eslint-migration - disable warnings/errors Disable warnings and errors on initial code empty functions/require remove transations stub from spec test --- e2e/common-setup.ts | 5 ++++- e2e/main.spec.ts | 4 +++- eslintrc.json | 7 +------ main.ts | 1 + src/app/app.component.spec.ts | 5 ----- src/app/home/home.component.ts | 5 +++-- .../components/page-not-found/page-not-found.component.ts | 4 +++- src/app/shared/directives/webview/webview.directive.ts | 1 + src/test.ts | 1 + 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/e2e/common-setup.ts b/e2e/common-setup.ts index 7f6ebfd11..e6c0436cf 100644 --- a/e2e/common-setup.ts +++ b/e2e/common-setup.ts @@ -1,8 +1,11 @@ +/* eslint "@typescript-eslint/no-var-requires": 0 */ const Application = require('spectron').Application; +/* eslint "@typescript-eslint/no-var-requires": 0 */ const electronPath = require('electron'); // Require Electron from the binaries included in node_modules. +/* eslint "@typescript-eslint/no-var-requires": 0 */ const path = require('path'); -export default function setup() { +export default function setup(): void { beforeEach(async function () { this.app = new Application({ // Your electron path can be any binary diff --git a/e2e/main.spec.ts b/e2e/main.spec.ts index a20d48461..ec90683cc 100644 --- a/e2e/main.spec.ts +++ b/e2e/main.spec.ts @@ -1,4 +1,4 @@ -import {expect, assert} from 'chai'; +import {expect} from 'chai'; import {SpectronClient} from 'spectron'; import commonSetup from './common-setup'; @@ -6,11 +6,13 @@ import commonSetup from './common-setup'; describe('angular-electron App', function () { commonSetup.apply(this); + /* eslint "@typescript-eslint/no-explicit-any": 0 */ let browser: any; let client: SpectronClient; beforeEach(function () { client = this.app.client; + /* eslint "@typescript-eslint/no-explicit-any": 0 */ browser = client as any; }); diff --git a/eslintrc.json b/eslintrc.json index 3e88df3c9..a1f75f922 100644 --- a/eslintrc.json +++ b/eslintrc.json @@ -15,10 +15,5 @@ "parserOptions": { "tsconfigRootDir": "." }, - "plugins": ["@typescript-eslint"], - "rules": { - "no-empty-function": ["warn"], - "@typescript-eslint/no-empty-function": ["warn"], - "@typescript-eslint/no-var-requires": ["warn"] - } + "plugins": ["@typescript-eslint"] } diff --git a/main.ts b/main.ts index e38690786..35dd37aad 100644 --- a/main.ts +++ b/main.ts @@ -24,6 +24,7 @@ function createWindow(): BrowserWindow { }); if (serve) { + /* eslint "@typescript-eslint/no-var-requires": 0 */ require('electron-reload')(__dirname, { electron: require(`${__dirname}/node_modules/electron`) }); diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 4deab6e5e..cdccbff38 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,7 +1,6 @@ import { TestBed, async } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; -import { TranslateModule } from '@ngx-translate/core'; import { ElectronService } from './core/services'; describe('AppComponent', () => { @@ -19,7 +18,3 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); })); }); - -class TranslateServiceStub { - setDefaultLang(lang: string): void {} -} diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index f56c8c173..739960791 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -7,9 +7,10 @@ import { Component, OnInit } from '@angular/core'; }) export class HomeComponent implements OnInit { + /* eslint "no-empty-function":0, "@typescript-eslint/no-empty-function": 0 */ constructor() { } - ngOnInit() { - } + /* eslint "no-empty-function":0, "@typescript-eslint/no-empty-function": 0 */ + ngOnInit(): void { } } diff --git a/src/app/shared/components/page-not-found/page-not-found.component.ts b/src/app/shared/components/page-not-found/page-not-found.component.ts index 7d66ed4c1..2aca12676 100644 --- a/src/app/shared/components/page-not-found/page-not-found.component.ts +++ b/src/app/shared/components/page-not-found/page-not-found.component.ts @@ -6,7 +6,9 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./page-not-found.component.scss'] }) export class PageNotFoundComponent implements OnInit { + /* eslint "no-empty-function":0, "@typescript-eslint/no-empty-function": 0 */ constructor() {} - ngOnInit() {} + /* eslint "no-empty-function":0, "@typescript-eslint/no-empty-function": 0 */ + ngOnInit(): void {} } diff --git a/src/app/shared/directives/webview/webview.directive.ts b/src/app/shared/directives/webview/webview.directive.ts index 579b0f98c..cbe497e3f 100644 --- a/src/app/shared/directives/webview/webview.directive.ts +++ b/src/app/shared/directives/webview/webview.directive.ts @@ -4,5 +4,6 @@ import { Directive } from '@angular/core'; selector: '[webview]' }) export class WebviewDirective { + /* eslint "no-empty-function":0, "@typescript-eslint/no-empty-function": 0 */ constructor() {} } diff --git a/src/test.ts b/src/test.ts index 16317897b..2f09f7f2c 100644 --- a/src/test.ts +++ b/src/test.ts @@ -7,6 +7,7 @@ import { platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; +/* eslint "@typescript-eslint/no-explicit-any":0 */ declare const require: any; // First, initialize the Angular testing environment. From 2f64f37e885e55cad0aa74020a40d2e50e44c4c2 Mon Sep 17 00:00:00 2001 From: Yuri Cherepanov Date: Mon, 18 Nov 2019 01:47:30 +0200 Subject: [PATCH 5/5] eslint-migration - fix removed translation import --- src/app/app.component.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index cdccbff38..ac74d207e 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,6 +1,7 @@ import { TestBed, async } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; +import { TranslateModule } from '@ngx-translate/core'; import { ElectronService } from './core/services'; describe('AppComponent', () => {