From 92d7419bc12dec58227a57603cd1b087adbf74ae Mon Sep 17 00:00:00 2001 From: Maxime GRIS Date: Sat, 20 Jun 2020 19:48:08 +0200 Subject: [PATCH] fix/ ng lint with eslint --- .eslintrc.json | 61 ++++++++++++++++++++++ angular.json | 4 +- e2e/eslintrc.e2e.json | 6 ++- e2e/main.e2e.ts | 4 +- eslintrc.json | 24 --------- main.ts | 1 - package.json | 16 +++--- src/app/app.component.ts | 12 ++--- src/app/core/services/electron/electron.service.ts | 4 +- .../page-not-found.component.spec.ts | 4 +- .../shared/directives/webview/webview.directive.ts | 2 +- src/eslintrc.app.json | 9 ++++ src/eslintrc.config.json | 6 --- src/tsconfig.app.json | 11 +++- 14 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 eslintrc.json create mode 100644 src/eslintrc.app.json delete mode 100644 src/eslintrc.config.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..5e30c10 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,61 @@ +{ + "env": { + "browser": true, + "node": true, + "es6": true, + "es2017": true + }, + "overrides": [ + { + "files": ["*.ts"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 10, + "project": "src/tsconfig.app.json", + "sourceType": "module", + "ecmaFeatures": { + "modules": true + } + }, + "plugins": [ + "@typescript-eslint", + "@angular-eslint/eslint-plugin" + ], + "rules": { + "@typescript-eslint/indent": [ + "error", 2, { + "SwitchCase": 1, + "CallExpression": {"arguments": "first"}, + "FunctionExpression": {"parameters": "first"}, + "FunctionDeclaration": {"parameters": "first"} + } + ], + "@typescript-eslint/no-empty-function": 0, + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/no-explicit-any": 0, + "@typescript-eslint/no-unsafe-call": 0, + "@typescript-eslint/no-unsafe-member-access": 0, + "@typescript-eslint/no-unsafe-assignment": 0, + "@typescript-eslint/no-unsafe-return": 0, + "@typescript-eslint/no-floating-promises": 0, + "@angular-eslint/use-injectable-provided-in": "error", + "@angular-eslint/no-attribute-decorator": "error" + } + }, + { + "files": ["*.component.html"], + "parser": "@angular-eslint/template-parser", + "plugins": ["@angular-eslint/template"], + "rules": { + "@angular-eslint/template/banana-in-a-box": "error", + "@angular-eslint/template/no-negated-async": "error" + } + } + ] +} diff --git a/angular.json b/angular.json index 8a79e93..ff9bc40 100644 --- a/angular.json +++ b/angular.json @@ -127,7 +127,7 @@ "lint": { "builder": "@angular-eslint/builder:lint", "options": { - "eslintConfig": "src/eslintrc.config.json", + "eslintConfig": "src/eslintrc.app.json", "tsConfig": [ "src/tsconfig.app.json", "src/tsconfig.spec.json" @@ -168,4 +168,4 @@ "prefix": "app" } } -} \ No newline at end of file +} diff --git a/e2e/eslintrc.e2e.json b/e2e/eslintrc.e2e.json index 51edf19..515a7b3 100644 --- a/e2e/eslintrc.e2e.json +++ b/e2e/eslintrc.e2e.json @@ -1,6 +1,8 @@ { - "extends": "../eslintrc.json", + "extends": "../.eslintrc.json", "parserOptions": { - "project": ["e2e/tsconfig.e2e.json"] + "project": [ + "e2e/tsconfig.e2e.json" + ] } } diff --git a/e2e/main.e2e.ts b/e2e/main.e2e.ts index 163f134..cc1780f 100644 --- a/e2e/main.e2e.ts +++ b/e2e/main.e2e.ts @@ -1,5 +1,5 @@ -import {expect} from 'chai'; -import {SpectronClient} from 'spectron'; +import { expect } from 'chai'; +import { SpectronClient } from 'spectron'; import commonSetup from './common-setup'; diff --git a/eslintrc.json b/eslintrc.json deleted file mode 100644 index 913e297..0000000 --- a/eslintrc.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "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": { - "@typescript-eslint/no-empty-function": 0, - "@typescript-eslint/no-var-requires": 0, - "@typescript-eslint/no-explicit-any": 0 - } -} diff --git a/main.ts b/main.ts index 7868694..4b3aa6e 100644 --- a/main.ts +++ b/main.ts @@ -25,7 +25,6 @@ function createWindow(): BrowserWindow { if (serve) { - require('devtron').install(); win.webContents.openDevTools(); require('electron-reload')(__dirname, { diff --git a/package.json b/package.json index 613d0e1..7d0cba0 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,10 @@ "devDependencies": { "@angular-builders/custom-webpack": "9.1.0", "@angular-devkit/build-angular": "0.901.9", - "@angular-eslint/builder": "0.0.1-alpha.18", + "@angular-eslint/builder": "0.0.1-alpha.32", + "@angular-eslint/eslint-plugin": "0.0.1-alpha.32", + "@angular-eslint/eslint-plugin-template": "0.0.1-alpha.32", + "@angular-eslint/template-parser": "0.0.1-alpha.32", "@angular/cli": "9.1.9", "@angular/common": "9.1.11", "@angular/compiler": "9.1.11", @@ -57,19 +60,18 @@ "@types/jasminewd2": "2.0.8", "@types/mocha": "7.0.2", "@types/node": "12.11.1", - "@typescript-eslint/eslint-plugin": "2.27.0", - "@typescript-eslint/parser": "2.27.0", + "@typescript-eslint/eslint-plugin": "3.3.0", + "@typescript-eslint/eslint-plugin-tslint": "3.3.0", + "@typescript-eslint/parser": "3.3.0", "chai": "4.2.0", - "codelyzer": "5.2.2", "conventional-changelog-cli": "2.0.34", "core-js": "3.6.5", "cross-env": "7.0.2", - "devtron": "1.4.0", "electron": "9.0.4", "electron-builder": "22.7.0", "electron-reload": "1.5.0", - "eslint": "6.8.0", - "eslint-plugin-import": "2.20.2", + "eslint": "7.3.0", + "eslint-plugin-import": "2.21.2", "jasmine-core": "3.5.0", "jasmine-spec-reporter": "5.0.2", "karma": "5.1.0", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index a83ed60..94966ed 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -10,19 +10,19 @@ import { AppConfig } from '../environments/environment'; }) export class AppComponent { constructor( - public electronService: ElectronService, + private electronService: ElectronService, private translate: TranslateService ) { - translate.setDefaultLang('en'); + this.translate.setDefaultLang('en'); console.log('AppConfig', AppConfig); if (electronService.isElectron) { console.log(process.env); - console.log('Mode electron'); - console.log('Electron ipcRenderer', electronService.ipcRenderer); - console.log('NodeJS childProcess', electronService.childProcess); + console.log('Run in electron'); + console.log('Electron ipcRenderer', this.electronService.ipcRenderer); + console.log('NodeJS childProcess', this.electronService.childProcess); } else { - console.log('Mode web'); + console.log('Run in browser'); } } } diff --git a/src/app/core/services/electron/electron.service.ts b/src/app/core/services/electron/electron.service.ts index 35489f0..9017c8a 100644 --- a/src/app/core/services/electron/electron.service.ts +++ b/src/app/core/services/electron/electron.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; // If you import a module but never use any of the imported values other than as TypeScript types, // the resulting javascript file will look as if you never imported the module at all. -import { ipcRenderer, webFrame } from 'electron'; +import { ipcRenderer, webFrame, remote } from 'electron'; import * as childProcess from 'child_process'; import * as fs from 'fs'; @@ -12,6 +12,7 @@ import * as fs from 'fs'; export class ElectronService { ipcRenderer: typeof ipcRenderer; webFrame: typeof webFrame; + remote: typeof remote; childProcess: typeof childProcess; fs: typeof fs; @@ -24,6 +25,7 @@ export class ElectronService { if (this.isElectron) { this.ipcRenderer = window.require('electron').ipcRenderer; this.webFrame = window.require('electron').webFrame; + this.remote = window.require('electron').remote; this.childProcess = window.require('child_process'); this.fs = window.require('fs'); diff --git a/src/app/shared/components/page-not-found/page-not-found.component.spec.ts b/src/app/shared/components/page-not-found/page-not-found.component.spec.ts index 697a946..fe3d6df 100644 --- a/src/app/shared/components/page-not-found/page-not-found.component.spec.ts +++ b/src/app/shared/components/page-not-found/page-not-found.component.spec.ts @@ -8,9 +8,9 @@ describe('PageNotFoundComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ PageNotFoundComponent ] + declarations: [PageNotFoundComponent] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/src/app/shared/directives/webview/webview.directive.ts b/src/app/shared/directives/webview/webview.directive.ts index 2249586..239fed4 100644 --- a/src/app/shared/directives/webview/webview.directive.ts +++ b/src/app/shared/directives/webview/webview.directive.ts @@ -4,5 +4,5 @@ import { Directive } from '@angular/core'; selector: 'webview' }) export class WebviewDirective { - constructor() {} + constructor() { } } diff --git a/src/eslintrc.app.json b/src/eslintrc.app.json new file mode 100644 index 0000000..45559a3 --- /dev/null +++ b/src/eslintrc.app.json @@ -0,0 +1,9 @@ +{ + "extends": "../.eslintrc.json", + "parserOptions": { + "project": [ + "src/tsconfig.app.json", + "src/tsconfig.spec.json" + ] + } +} diff --git a/src/eslintrc.config.json b/src/eslintrc.config.json deleted file mode 100644 index ad87184..0000000 --- a/src/eslintrc.config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../eslintrc.json", - "parserOptions": { - "project": ["src/tsconfig.app.json", "src/tsconfig.spec.json"] - } -} diff --git a/src/tsconfig.app.json b/src/tsconfig.app.json index fbae189..f795ede 100644 --- a/src/tsconfig.app.json +++ b/src/tsconfig.app.json @@ -6,7 +6,16 @@ "baseUrl": "", "types": [] }, + "include": [ + "**/*.ts", + + ], "exclude": [ "**/*.spec.ts" - ] + ], + "angularCompilerOptions": { + "fullTemplateTypeCheck": true, + "strictInjectionParameters": true, + "preserveWhitespaces": true + } }