fix/ ng lint with eslint

This commit is contained in:
Maxime GRIS
2020-06-20 19:48:08 +02:00
parent 21f7401740
commit 92d7419bc1
14 changed files with 109 additions and 55 deletions

61
.eslintrc.json Normal file
View File

@@ -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"
}
}
]
}

View File

@@ -127,7 +127,7 @@
"lint": { "lint": {
"builder": "@angular-eslint/builder:lint", "builder": "@angular-eslint/builder:lint",
"options": { "options": {
"eslintConfig": "src/eslintrc.config.json", "eslintConfig": "src/eslintrc.app.json",
"tsConfig": [ "tsConfig": [
"src/tsconfig.app.json", "src/tsconfig.app.json",
"src/tsconfig.spec.json" "src/tsconfig.spec.json"

View File

@@ -1,6 +1,8 @@
{ {
"extends": "../eslintrc.json", "extends": "../.eslintrc.json",
"parserOptions": { "parserOptions": {
"project": ["e2e/tsconfig.e2e.json"] "project": [
"e2e/tsconfig.e2e.json"
]
} }
} }

View File

@@ -1,5 +1,5 @@
import {expect} from 'chai'; import { expect } from 'chai';
import {SpectronClient} from 'spectron'; import { SpectronClient } from 'spectron';
import commonSetup from './common-setup'; import commonSetup from './common-setup';

View File

@@ -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
}
}

View File

@@ -25,7 +25,6 @@ function createWindow(): BrowserWindow {
if (serve) { if (serve) {
require('devtron').install();
win.webContents.openDevTools(); win.webContents.openDevTools();
require('electron-reload')(__dirname, { require('electron-reload')(__dirname, {

View File

@@ -40,7 +40,10 @@
"devDependencies": { "devDependencies": {
"@angular-builders/custom-webpack": "9.1.0", "@angular-builders/custom-webpack": "9.1.0",
"@angular-devkit/build-angular": "0.901.9", "@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/cli": "9.1.9",
"@angular/common": "9.1.11", "@angular/common": "9.1.11",
"@angular/compiler": "9.1.11", "@angular/compiler": "9.1.11",
@@ -57,19 +60,18 @@
"@types/jasminewd2": "2.0.8", "@types/jasminewd2": "2.0.8",
"@types/mocha": "7.0.2", "@types/mocha": "7.0.2",
"@types/node": "12.11.1", "@types/node": "12.11.1",
"@typescript-eslint/eslint-plugin": "2.27.0", "@typescript-eslint/eslint-plugin": "3.3.0",
"@typescript-eslint/parser": "2.27.0", "@typescript-eslint/eslint-plugin-tslint": "3.3.0",
"@typescript-eslint/parser": "3.3.0",
"chai": "4.2.0", "chai": "4.2.0",
"codelyzer": "5.2.2",
"conventional-changelog-cli": "2.0.34", "conventional-changelog-cli": "2.0.34",
"core-js": "3.6.5", "core-js": "3.6.5",
"cross-env": "7.0.2", "cross-env": "7.0.2",
"devtron": "1.4.0",
"electron": "9.0.4", "electron": "9.0.4",
"electron-builder": "22.7.0", "electron-builder": "22.7.0",
"electron-reload": "1.5.0", "electron-reload": "1.5.0",
"eslint": "6.8.0", "eslint": "7.3.0",
"eslint-plugin-import": "2.20.2", "eslint-plugin-import": "2.21.2",
"jasmine-core": "3.5.0", "jasmine-core": "3.5.0",
"jasmine-spec-reporter": "5.0.2", "jasmine-spec-reporter": "5.0.2",
"karma": "5.1.0", "karma": "5.1.0",

View File

@@ -10,19 +10,19 @@ import { AppConfig } from '../environments/environment';
}) })
export class AppComponent { export class AppComponent {
constructor( constructor(
public electronService: ElectronService, private electronService: ElectronService,
private translate: TranslateService private translate: TranslateService
) { ) {
translate.setDefaultLang('en'); this.translate.setDefaultLang('en');
console.log('AppConfig', AppConfig); console.log('AppConfig', AppConfig);
if (electronService.isElectron) { if (electronService.isElectron) {
console.log(process.env); console.log(process.env);
console.log('Mode electron'); console.log('Run in electron');
console.log('Electron ipcRenderer', electronService.ipcRenderer); console.log('Electron ipcRenderer', this.electronService.ipcRenderer);
console.log('NodeJS childProcess', electronService.childProcess); console.log('NodeJS childProcess', this.electronService.childProcess);
} else { } else {
console.log('Mode web'); console.log('Run in browser');
} }
} }
} }

View File

@@ -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, // 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. // 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 childProcess from 'child_process';
import * as fs from 'fs'; import * as fs from 'fs';
@@ -12,6 +12,7 @@ import * as fs from 'fs';
export class ElectronService { export class ElectronService {
ipcRenderer: typeof ipcRenderer; ipcRenderer: typeof ipcRenderer;
webFrame: typeof webFrame; webFrame: typeof webFrame;
remote: typeof remote;
childProcess: typeof childProcess; childProcess: typeof childProcess;
fs: typeof fs; fs: typeof fs;
@@ -24,6 +25,7 @@ export class ElectronService {
if (this.isElectron) { if (this.isElectron) {
this.ipcRenderer = window.require('electron').ipcRenderer; this.ipcRenderer = window.require('electron').ipcRenderer;
this.webFrame = window.require('electron').webFrame; this.webFrame = window.require('electron').webFrame;
this.remote = window.require('electron').remote;
this.childProcess = window.require('child_process'); this.childProcess = window.require('child_process');
this.fs = window.require('fs'); this.fs = window.require('fs');

View File

@@ -8,9 +8,9 @@ describe('PageNotFoundComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ PageNotFoundComponent ] declarations: [PageNotFoundComponent]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@@ -4,5 +4,5 @@ import { Directive } from '@angular/core';
selector: 'webview' selector: 'webview'
}) })
export class WebviewDirective { export class WebviewDirective {
constructor() {} constructor() { }
} }

9
src/eslintrc.app.json Normal file
View File

@@ -0,0 +1,9 @@
{
"extends": "../.eslintrc.json",
"parserOptions": {
"project": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
]
}
}

View File

@@ -1,6 +0,0 @@
{
"extends": "../eslintrc.json",
"parserOptions": {
"project": ["src/tsconfig.app.json", "src/tsconfig.spec.json"]
}
}

View File

@@ -6,7 +6,16 @@
"baseUrl": "", "baseUrl": "",
"types": [] "types": []
}, },
"include": [
"**/*.ts",
],
"exclude": [ "exclude": [
"**/*.spec.ts" "**/*.spec.ts"
] ],
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"preserveWhitespaces": true
}
} }