chore(angular): strict tslint (#16708)

This commit is contained in:
Manu MA
2018-12-12 17:17:43 +01:00
committed by GitHub
parent ecf1bae441
commit 585a84f829
33 changed files with 103 additions and 76 deletions

View File

@ -50,34 +50,34 @@
"peerDependencies": {
"@angular-devkit/core": "^7.1.2",
"@angular-devkit/schematics": "^7.1.2",
"@angular/core": "^7.1.2",
"@angular/common": "^7.1.2",
"@angular/forms": "^7.1.2",
"@angular/router": "~7.1.2",
"@angular/compiler": "^7.1.2",
"@angular/compiler-cli": "^7.1.2",
"@angular/platform-browser": "^7.1.2",
"@angular/platform-browser-dynamic": "^7.1.2",
"@angular/core": "^7.1.3",
"@angular/common": "^7.1.3",
"@angular/forms": "^7.1.3",
"@angular/router": "~7.1.3",
"@angular/compiler": "^7.1.3",
"@angular/compiler-cli": "^7.1.3",
"@angular/platform-browser": "^7.1.3",
"@angular/platform-browser-dynamic": "^7.1.3",
"rxjs": ">=6.2.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/core": "^7.1.2",
"@angular-devkit/schematics": "^7.1.2",
"@angular/core": "^7.1.2",
"@angular/common": "^7.1.2",
"@angular/forms": "^7.1.2",
"@angular/router": "^7.1.2",
"@angular/compiler": "^7.1.2",
"@angular/compiler-cli": "^7.1.2",
"@angular/platform-browser": "^7.1.2",
"@angular/platform-browser-dynamic": "^7.1.2",
"@angular/core": "^7.1.3",
"@angular/common": "^7.1.3",
"@angular/forms": "^7.1.3",
"@angular/router": "^7.1.3",
"@angular/compiler": "^7.1.3",
"@angular/compiler-cli": "^7.1.3",
"@angular/platform-browser": "^7.1.3",
"@angular/platform-browser-dynamic": "^7.1.3",
"@types/node": "~10.12.0",
"fs-extra": "^7.0.0",
"glob": "^7.1.2",
"glob": "^7.1.3",
"rxjs": "^6.2.0",
"tslint": "^5.10.0",
"tslint-ionic-rules": "0.0.17",
"tslint-ionic-rules": "0.0.21",
"typescript": "3.1.6",
"zone.js": "^0.8.26"
},

View File

@ -1,15 +1,12 @@
import '@ionic/core/dist/ionic/svg';
import { defineCustomElements } from '@ionic/core/loader';
import { Config } from './providers/config';
import { IonicWindow } from './types/interfaces';
// Webpack import for ionicons
// @ts-ignore
// tslint:disable-next-line:no-import-side-effect
import '@ionic/core/dist/ionic/svg';
export function appInitialize(config: Config) {
return (): any => {
const win: IonicWindow = window as any;
const win: IonicWindow | undefined = window as any;
if (typeof win !== 'undefined') {
const Ionic = win.Ionic = win.Ionic || {};

View File

@ -1,5 +1,6 @@
import { Directive, ElementRef, HostListener } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from './value-accessor';
@Directive({

View File

@ -1,5 +1,6 @@
import { Directive, ElementRef, HostListener } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from './value-accessor';
@Directive({

View File

@ -1,5 +1,6 @@
import { Directive, ElementRef, HostListener } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from './value-accessor';
@Directive({

View File

@ -56,7 +56,7 @@ export function setIonicClasses(element: ElementRef) {
for (let i = 0; i < classList.length; i++) {
const item = classList.item(i);
if (item && startsWith(item, 'ng-')) {
if (item !== null && startsWith(item, 'ng-')) {
classList.add(`ion-${item.substr(3)}`);
}
}

View File

@ -1,5 +1,7 @@
import { Directive, ElementRef, HostListener, Input, Optional } from '@angular/core';
import { NavController } from '../../providers/nav-controller';
import { IonRouterOutlet } from './ion-router-outlet';
@Directive({
@ -8,10 +10,10 @@ import { IonRouterOutlet } from './ion-router-outlet';
export class IonBackButtonDelegate {
@Input()
set defaultHref(value: string) {
set defaultHref(value: string | undefined | null) {
this.elementRef.nativeElement.defaultHref = value;
}
get defaultHref() {
get defaultHref(): string | undefined | null {
return this.elementRef.nativeElement.defaultHref;
}

View File

@ -1,10 +1,12 @@
import { Attribute, ChangeDetectorRef, ComponentFactoryResolver, ComponentRef, Directive, ElementRef, EventEmitter, Injector, Input, NgZone, OnDestroy, OnInit, Optional, Output, ViewContainerRef } from '@angular/core';
import { ActivatedRoute, ChildrenOutletContexts, OutletContext, PRIMARY_OUTLET, Router } from '@angular/router';
import { StackController } from './stack-controller';
import { NavController } from '../../providers/nav-controller';
import { bindLifecycleEvents } from '../../providers/angular-delegate';
import { RouteView, getUrl } from './stack-utils';
import { Config } from '../../providers';
import { bindLifecycleEvents } from '../../providers/angular-delegate';
import { NavController } from '../../providers/nav-controller';
import { StackController } from './stack-controller';
import { RouteView, getUrl } from './stack-utils';
@Directive({
selector: 'ion-router-outlet',

View File

@ -1,8 +1,10 @@
import { Component, ContentChild, HostListener, ViewChild } from '@angular/core';
import { TabButtonClickDetail } from '@ionic/core';
import { IonRouterOutlet } from './ion-router-outlet';
import { NavController } from '../../providers';
import { IonTabBar } from '../proxies';
import { IonRouterOutlet } from './ion-router-outlet';
import { RouteView } from './stack-utils';
@Component({

View File

@ -1,4 +1,5 @@
import { ComponentFactoryResolver, Directive, ElementRef, Injector, ViewContainerRef } from '@angular/core';
import { AngularDelegate } from '../../providers/angular-delegate';
@Directive({

View File

@ -1,9 +1,9 @@
import { Directive, ElementRef, HostListener, Input, Optional } from '@angular/core';
import { NavController, NavDirection } from '../../providers/nav-controller';
import { Router, RouterLink } from '@angular/router';
import { LocationStrategy } from '@angular/common';
import { Directive, ElementRef, HostListener, Input, Optional } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { Subscription } from 'rxjs';
import { NavController, NavDirection } from '../../providers/nav-controller';
@Directive({
selector: '[routerLink]',
@ -45,10 +45,7 @@ export class RouterLinkDelegate {
@HostListener('click', ['$event'])
onClick(ev: UIEvent) {
if (this.routerDirection) {
this.navCtrl.setDirection(this.routerDirection);
}
ev.preventDefault();
}
}

View File

@ -1,10 +1,10 @@
import { ComponentRef, NgZone } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterDirection } from '@ionic/core';
import { NavController, NavDirection } from '../../providers/nav-controller';
import { RouterDirection } from '@ionic/core';
import { RouteView, computeStackId, destroyView, getUrl, insertView, isTabSwitch, toSegments } from './stack-utils';
import { RouteView, computeStackId, destroyView, getUrl, insertView, isTabSwitch, toSegments } from './stack-utils';
export class StackController {
@ -23,7 +23,7 @@ export class StackController {
private navCtrl: NavController,
private zone: NgZone,
) {
this.tabsPrefix = tabsPrefix ? toSegments(tabsPrefix) : undefined;
this.tabsPrefix = tabsPrefix !== undefined ? toSegments(tabsPrefix) : undefined;
}
createView(enteringRef: ComponentRef<any>, activatedRoute: ActivatedRoute): RouteView {
@ -128,7 +128,7 @@ export class StackController {
showGoBack: boolean,
progressAnimation: boolean
) {
if (this.runningTransition) {
if (this.runningTransition !== undefined) {
await this.runningTransition;
this.runningTransition = undefined;
}

View File

@ -37,7 +37,6 @@ function setBack(views: RouteView[], view: RouteView) {
}
}
export function getUrl(router: Router, activatedRoute: ActivatedRoute) {
const urlTree = router.createUrlTree(['.'], { relativeTo: activatedRoute });
return router.serializeUrl(urlTree);
@ -73,7 +72,7 @@ export function toSegments(path: string): string[] {
.filter(s => s !== '');
}
export function destroyView(view: RouteView) {
export function destroyView(view: RouteView | undefined) {
if (view) {
// TODO lifecycle event
view.ref.destroy();

View File

@ -1,4 +1,5 @@
import { Directive, TemplateRef } from '@angular/core';
import { VirtualContext } from './virtual-utils';
/**

View File

@ -1,4 +1,5 @@
import { Directive, TemplateRef } from '@angular/core';
import { VirtualContext } from './virtual-utils';
/**

View File

@ -1,4 +1,5 @@
import { Directive, TemplateRef, ViewContainerRef } from '@angular/core';
import { VirtualContext } from './virtual-utils';
/**

View File

@ -1,10 +1,11 @@
import { ChangeDetectorRef, ContentChild, Directive, ElementRef, EmbeddedViewRef } from '@angular/core';
import { proxyInputs } from '../proxies';
import { VirtualItem } from './virtual-item';
import { VirtualHeader } from './virtual-header';
import { VirtualFooter } from './virtual-footer';
import { VirtualContext } from './virtual-utils';
import { proxyInputs } from '../proxies';
import { VirtualFooter } from './virtual-footer';
import { VirtualHeader } from './virtual-header';
import { VirtualItem } from './virtual-item';
import { VirtualContext } from './virtual-utils';
@Directive({
selector: 'ion-virtual-scroll',

View File

@ -1,13 +1,12 @@
import { CommonModule } from '@angular/common';
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { IonicConfig } from '@ionic/core';
import { CommonModule } from '@angular/common';
import { appInitialize } from './app-initialize';
import { ConfigToken } from './providers/config';
import * as c from './directives';
import * as d from './directives/proxies';
import * as p from './providers';
import { ConfigToken } from './providers/config';
const DECLARATIONS = [
// proxies
@ -122,7 +121,6 @@ const PROVIDERS = [
p.DomController
];
@NgModule({
declarations: DECLARATIONS,
exports: DECLARATIONS,

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { ActionSheetOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
@Injectable()

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { AlertOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
@Injectable()

View File

@ -1,7 +1,7 @@
import { ApplicationRef, ComponentFactoryResolver, Injectable, InjectionToken, Injector, NgZone, ViewContainerRef } from '@angular/core';
import { FrameworkDelegate } from '@ionic/core';
import { NavParams } from '../directives/navigation/nav-params';
import { NavParams } from '../directives/navigation/nav-params';
@Injectable()
export class AngularDelegate {
@ -20,7 +20,6 @@ export class AngularDelegate {
}
}
export class AngularFrameworkDelegate implements FrameworkDelegate {
private elRefMap = new WeakMap<HTMLElement, any>();
@ -133,7 +132,6 @@ export function bindLifecycleEvents(instance: any, element: HTMLElement) {
const NavParamsToken = new InjectionToken<any>('NavParamsToken');
function getProviders(params: {[key: string]: any}) {
return [
{

View File

@ -1,7 +1,7 @@
import { Config as CoreConfig, IonicConfig } from '@ionic/core';
import { InjectionToken } from '@angular/core';
import { IonicWindow } from '../types/interfaces';
import { Config as CoreConfig, IonicConfig } from '@ionic/core';
import { IonicWindow } from '../types/interfaces';
export class Config {
@ -40,7 +40,7 @@ export class Config {
export const ConfigToken = new InjectionToken<any>('USERCONFIG');
function getConfig(): CoreConfig | null {
const win: IonicWindow = window as any;
const win: IonicWindow | undefined = window as any;
if (typeof win !== 'undefined') {
const Ionic = win.Ionic;
if (Ionic && Ionic.config) {

View File

@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
export type EventHandler = (...args: any[]) => any;
@Injectable()
export class Events {
@ -74,7 +73,6 @@ export class Events {
}
}
export function setupEvents() {
const events = new Events();
@ -87,7 +85,6 @@ export function setupEvents() {
return events;
}
export function setupProvideEvents() {
return () => {
return setupEvents();

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { LoadingOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
@Injectable()

View File

@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { proxyMethod } from '../util/util';
const CTRL = 'ion-menu-controller';
@ -14,7 +15,6 @@ export class MenuController {
return proxyMethod(CTRL, 'open', menuId);
}
/**
* Programmatically close the Menu. If no `menuId` is given as the first
* argument then it'll close any menu which is open. If a `menuId`

View File

@ -1,6 +1,8 @@
import { ComponentFactoryResolver, Injectable, Injector } from '@angular/core';
import { ModalOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
import { AngularDelegate } from './angular-delegate';
@Injectable()

View File

@ -1,9 +1,10 @@
import { Injectable, Optional } from '@angular/core';
import { Location } from '@angular/common';
import { Injectable, Optional } from '@angular/core';
import { NavigationExtras, NavigationStart, Router, UrlTree } from '@angular/router';
import { Platform } from './platform';
import { RouterDirection } from '@ionic/core';
import { Platform } from './platform';
export type NavDirection = 'forward' | 'back' | 'root' | 'auto';
@Injectable()

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { PickerOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
@Injectable()

View File

@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { BackButtonDetail, Platforms, getPlatforms, isPlatform } from '@ionic/core';
import { proxyEvent } from '../util/util';
import { Subject, Subscription } from 'rxjs';
import { proxyEvent } from '../util/util';
export interface BackButtonEmitter extends Subject<BackButtonDetail> {
subscribeWithPriority(priority: number, callback: () => Promise<any> | void): Subscription;

View File

@ -1,6 +1,8 @@
import { ComponentFactoryResolver, Injectable, Injector } from '@angular/core';
import { PopoverOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
import { AngularDelegate } from './angular-delegate';
@Injectable()

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { ToastOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
@Injectable()

View File

@ -10,8 +10,8 @@ export function inputs(instance: any, el: ElementRef, props: string[]) {
}
export function proxyEvent<T>(emitter: Subject<T>, el: EventTarget, eventName: string) {
el.addEventListener(eventName, (ev) => {
emitter.next(ev ? (ev as any).detail as T : undefined);
el.addEventListener(eventName, ev => {
emitter.next((ev as any).detail as T);
});
}
@ -34,15 +34,14 @@ export function deepEqual(x: any, y: any) {
if (x === y) {
return true;
} else if (typeof x === 'object' && x != null && (typeof y === 'object' && y != null)) {
if (Object.keys(x).length !== Object.keys(y).length) return false;
if (Object.keys(x).length !== Object.keys(y).length) { return false; }
for (const prop in x) {
if (y.hasOwnProperty(prop)) {
if (!deepEqual(x[prop], y[prop])) return false;
} else return false;
if (!deepEqual(x[prop], y[prop])) { return false; }
} else { return false; }
}
return true;
} else return false;
} else { return false; }
}

View File

@ -1,6 +1,24 @@
{
"extends": "tslint-ionic-rules",
"extends": ["tslint-ionic-rules/strict"],
"linterOptions": {
"exclude": [
"**/*.spec.ts",
"**/*.spec.tsx"
]
},
"rules": {
"no-non-null-assertion": false
"no-conditional-assignment": false,
"no-non-null-assertion": false,
"no-unnecessary-type-assertion": false,
"no-import-side-effect": false,
"trailing-comma": false,
"no-null-keyword": false,
"no-console": false,
"no-unbound-method": true,
"no-floating-promises": false,
"no-invalid-template-strings": true,
"ban-export-const-enum": true,
"prefer-for-of": false
}
}