🔧 Add recommended ESLint rules

merge-requests/9/head
Nato Boram 2022-03-11 00:55:23 -05:00
parent 7980719b9a
commit d8fc7d06a3
No known key found for this signature in database
GPG Key ID: 478E3C64BF88AFFA
10 changed files with 18 additions and 21 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
src/test.ts

View File

@ -19,6 +19,8 @@
"createDefaultProgram": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@angular-eslint/all",
"plugin:@angular-eslint/recommended--extra",
"plugin:@angular-eslint/template/process-inline-templates"

View File

@ -24,15 +24,10 @@ build:
paths:
- dist/angular
lint:
stage: test
script:
- pnpm run lint
test:
stage: test
script:
- pnpm run test
- pnpm run lint
pages:
stage: deploy

View File

@ -4,7 +4,7 @@ import { AppComponent } from './app.component'
describe('AppComponent', (): void => {
beforeEach(waitForAsync((): void => {
TestBed.configureTestingModule({
void TestBed.configureTestingModule({
imports: [
RouterTestingModule,
],
@ -19,7 +19,7 @@ describe('AppComponent', (): void => {
if (!(fixture.debugElement.componentInstance instanceof AppComponent)) throw new Error("Expected AppComponent")
const app: AppComponent = fixture.debugElement.componentInstance
expect(app).toBeTruthy()
void expect(app).toBeTruthy()
})
it(`should have a themeService`, (): void => {
@ -27,7 +27,7 @@ describe('AppComponent', (): void => {
if (!(fixture.debugElement.componentInstance instanceof AppComponent)) throw new Error("Expected AppComponent")
const app: AppComponent = fixture.debugElement.componentInstance
expect(app.themeService).toBeTruthy()
void expect(app.themeService).toBeTruthy()
})
it('should render title', (): void => {
@ -36,10 +36,10 @@ describe('AppComponent', (): void => {
if (!isHTMLElement(fixture.debugElement.nativeElement)) throw new Error("Expected HTMLElement")
const compiled: HTMLElement = fixture.debugElement.nativeElement
expect(compiled.querySelector('h1')?.textContent).toContain('Public Gateway Cacher')
void expect(compiled.querySelector('h1')?.textContent).toContain('Public Gateway Cacher')
})
})
function isHTMLElement(element: any): element is HTMLElement {
return element.__proto__ instanceof HTMLElement
function isHTMLElement(element: unknown): element is HTMLElement {
return Object.getPrototypeOf(element) instanceof HTMLElement
}

View File

@ -8,7 +8,7 @@ describe('PagesComponent', (): void => {
let fixture: ComponentFixture<PagesComponent>
beforeEach(waitForAsync((): void => {
TestBed.configureTestingModule({
void TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [PagesComponent]
})
@ -22,6 +22,6 @@ describe('PagesComponent', (): void => {
})
it('should create', (): void => {
expect(component).toBeTruthy()
void expect(component).toBeTruthy()
})
})

View File

@ -10,6 +10,6 @@ describe('GatewayService', (): void => {
it('should be created', (): void => {
const service: GatewayService = TestBed.inject(GatewayService)
expect(service).toBeTruthy()
void expect(service).toBeTruthy()
})
})

View File

@ -18,7 +18,7 @@ export class GatewayService {
return this.http.get<string[]>(
environment.base_href && environment.base_href !== '/'
? `${environment.base_href}/assets/json/gateways.json`
: `${document.querySelector('base')?.href}assets/json/gateways.json`
: `${document.querySelector('base')?.href ?? ''}assets/json/gateways.json`
)
}

View File

@ -10,6 +10,6 @@ describe('ThemeService', (): void => {
})
it('should be created', (): void => {
expect(service).toBeTruthy()
void expect(service).toBeTruthy()
})
})

View File

@ -45,8 +45,7 @@
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js'; // Included with Angular CLI.
import 'zone.js' // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS

View File

@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/testing'
import { getTestBed } from '@angular/core/testing'
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'
import 'zone.js/testing'
declare const require: any