chore: update tslint rules (#7391)

This commit is contained in:
Manol Donev
2019-06-26 15:13:48 +03:00
committed by GitHub
parent 92370279d8
commit 4f39fb728b
399 changed files with 3101 additions and 2210 deletions

View File

@@ -1,4 +1,4 @@
import { BindingOptions } from ".";
import { BindingOptions } from ".";
import { ViewBase } from "../view-base";
import { unsetValue } from "../properties";
@@ -45,7 +45,7 @@ function getProperties(property: string): Array<string> {
}
// first replace all '$parents[..]' with a safe string
// second removes all ] since they are not important for property access and not needed
// second removes all ] since they are not important for property access and not needed
// then split properties either on '.' or '['
const parentsMatches = property.match(parentsRegex);
result = property.replace(parentsRegex, "parentsMatch")
@@ -59,6 +59,7 @@ function getProperties(property: string): Array<string> {
}
}
propertiesCache[property] = result;
return result;
}
@@ -69,6 +70,7 @@ export function getEventOrGestureName(name: string): string {
// NOTE: method fromString from "ui/gestures";
export function isGesture(eventOrGestureName: string): boolean {
let t = eventOrGestureName.trim().toLowerCase();
return t === "tap"
|| t === "doubletap"
|| t === "pinch"
@@ -88,6 +90,7 @@ export function isEventOrGesture(name: string, view: ViewBase): boolean {
return view.constructor && evt in view.constructor || isGesture(eventOrGestureName.toLowerCase());
}
return false;
}
@@ -134,7 +137,7 @@ export class Binding {
if (context !== undefined && context !== null) {
this.update(context);
}
};
}
public clearSource(): void {
this.propertyChangeListeners.forEach((observable, index, map) => {
@@ -169,6 +172,7 @@ export class Binding {
else if (objectType === "string") {
source = new String(source);
}
/* tslint:enable */
return source;
}
@@ -177,6 +181,7 @@ export class Binding {
const target = this.targetOptions.instance.get();
if (!target) {
this.unbind();
return;
}
@@ -287,7 +292,7 @@ export class Binding {
}
private addPropertyChangeListeners(source: WeakRef<Object>, sourceProperty: Array<string>, parentProperies?: string) {
let objectsAndProperties = this.resolveObjectsAndProperties(source.get(), sourceProperty)
let objectsAndProperties = this.resolveObjectsAndProperties(source.get(), sourceProperty);
let prop = parentProperies || "";
for (let i = 0, length = objectsAndProperties.length; i < length; i++) {
@@ -316,6 +321,7 @@ export class Binding {
let escapedSourceProperty = escapeRegexSymbols(this.options.sourceProperty);
let expRegex = new RegExp(escapedSourceProperty, "g");
let resultExp = this.options.expression.replace(expRegex, bc.newPropertyValueKey);
return resultExp;
}
@@ -382,10 +388,12 @@ export class Binding {
return result;
}
return new Error(expression + " is not a valid expression.");
}
catch (e) {
let errorMessage = "Run-time error occured in file: " + e.sourceURL + " at line: " + e.line + " and column: " + e.column;
return new Error(errorMessage);
}
}
@@ -448,7 +456,7 @@ export class Binding {
const newProps = sourceProps.slice(changedPropertyIndex + 1);
// add new weak event listeners
const newObject = data.object[sourceProps[changedPropertyIndex]]
const newObject = data.object[sourceProps[changedPropertyIndex]];
if (!types.isNullOrUndefined(newObject) && typeof newObject === "object") {
this.addPropertyChangeListeners(new WeakRef(newObject), newProps, parentProps);
}
@@ -576,11 +584,13 @@ export class Binding {
if (objectsAndProperties.length > 0) {
let resolvedObj = objectsAndProperties[objectsAndProperties.length - 1].instance;
let prop = objectsAndProperties[objectsAndProperties.length - 1].property;
return {
instance: new WeakRef(this.sourceAsObject(resolvedObj)),
property: prop
}
};
}
return null;
}

View File

@@ -59,6 +59,7 @@ export function _getStyleProperties(): CssProperty<any, any>[] {
function getPropertiesFromMap(map): Property<any, any>[] | CssProperty<any, any>[] {
const props = [];
Object.getOwnPropertySymbols(map).forEach(symbol => props.push(map[symbol]));
return props;
}
@@ -260,7 +261,7 @@ export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> imp
const originalValue: U = coerceKey in target ? target[coerceKey] : defaultValue;
// need that to make coercing but also fire change events
target[propertyName] = originalValue;
}
};
this.set = function (this: T, boxedValue: U): void {
const reset = boxedValue === unsetValue;
@@ -341,7 +342,7 @@ export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> imp
}
}
}
}
};
}
}
@@ -403,6 +404,7 @@ export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> imp
setInheritedValue.call(child, newValue);
}
}
return true;
});
}
@@ -809,7 +811,7 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
this.notify<PropertyChangeData>({ object: this, eventName, propertyName, value, oldValue });
}
}
}
};
}
const defaultPropertyDescriptor = descriptor(defaultValueKey, ValueSource.Default, false, false, false);
@@ -835,7 +837,7 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
Object.defineProperty(cls.prototype, options.cssName, stylePropertyDescriptor);
}
Object.defineProperty(cls.prototype, keyframeName, keyframePropertyDescriptor);
}
};
}
public _initDefaultNativeValue(target: T): void {
@@ -989,6 +991,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
setInheritedFunc.call(childStyle, value);
}
}
return true;
});
}
@@ -1082,7 +1085,7 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth
this[property.cssLocalName] = value;
});
}
}
};
cssSymbolPropertyMap[key] = this;
}
@@ -1315,6 +1318,7 @@ export function propagateInheritableCssProperties(parentStyle: Style, childStyle
export function makeValidator<T>(...values: T[]): (value: any) => value is T {
const set = new Set(values);
return (value: any): value is T => set.has(value);
}
@@ -1362,5 +1366,6 @@ export function getComputedCssValues(view: ViewBase): [string, any][] {
result.push(["left", "auto"]);
result.push(["bottom", "auto"]);
result.push(["right", "auto"]);
return result;
}

View File

@@ -73,6 +73,7 @@ export function getViewById(view: ViewBaseDefinition, id: string): ViewBaseDefin
const descendantsCallback = function (child: ViewBaseDefinition): boolean {
if (child.id === id) {
retVal = child;
// break the iteration by returning false
return false;
}
@@ -81,6 +82,7 @@ export function getViewById(view: ViewBaseDefinition, id: string): ViewBaseDefin
};
eachDescendant(view, descendantsCallback);
return retVal;
}
@@ -95,6 +97,7 @@ export function eachDescendant(view: ViewBaseDefinition, callback: (child: ViewB
if (continueIteration) {
child.eachChild(localCallback);
}
return continueIteration;
};
@@ -343,6 +346,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this.eachChild(child => {
this.loadView(child);
return true;
});
@@ -360,6 +364,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this.eachChild(child => {
this.unloadView(child);
return true;
});
@@ -393,6 +398,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
public _batchUpdate<T>(callback: () => T): T {
try {
this._suspendNativeUpdates(SuspendType.Incremental);
return callback();
} finally {
this._resumeNativeUpdates(SuspendType.Incremental);
@@ -459,6 +465,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
allStates.push(this.pseudoClassAliases[name][i]);
}
}
return allStates;
}
@@ -751,6 +758,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this.eachChild((child) => {
child._setupUI(context);
return true;
});
}
@@ -784,6 +792,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this.eachChild((child) => {
child._tearDownUI(force);
return true;
});
@@ -867,7 +876,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
/**
* @deprecated
*
*
* This used to be the way to set attribute values in early {N} versions.
* Now attributes are expected to be set as plain properties on the view instances.
*/
@@ -931,6 +940,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this._cssState.onChange();
eachDescendant(this, (child: ViewBase) => {
child._cssState.onChange();
return true;
});
}
@@ -947,13 +957,15 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this._onCssStateChange();
this.eachChild(child => {
child._inheritStyleScope(styleScope);
return true
return true;
});
}
}
public showModal(...args): ViewBase {
const parent = this.parent;
return parent && parent.showModal(...args);
}
@@ -967,6 +979,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
public _dialogClosed(): void {
eachDescendant(this, (child: ViewBase) => {
child._dialogClosed();
return true;
});
}
@@ -974,6 +987,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
public _onRootViewReset(): void {
eachDescendant(this, (child: ViewBase) => {
child._onRootViewReset();
return true;
});
}

View File

@@ -45,20 +45,21 @@ export function CSSType(type: string): ClassDecorator {
export function viewMatchesModuleContext(
view: ViewDefinition,
context: ModuleContext,
context: ModuleContext,
types: ModuleType[]): boolean {
return context &&
view._moduleName &&
context.type &&
context.type &&
types.some(type => type === context.type) &&
context.path &&
context.path &&
context.path.includes(view._moduleName);
}
export function PseudoClassHandler(...pseudoClasses: string[]): MethodDecorator {
const stateEventNames = pseudoClasses.map(s => ":" + s);
const listeners = Symbol("listeners");
return <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => {
function update(change: number) {
let prev = this[listeners] || 0;
@@ -104,6 +105,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
get css(): string {
const scope = this._styleScope;
return scope && scope.css;
}
set css(value: string) {
@@ -162,9 +164,11 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
this.eachChildView((child) => {
if (child._onLivesync(context)) {
handled = true;
return false;
}
});
return handled;
}
@@ -180,6 +184,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
}
this.changeCssFile(context.path);
return true;
}
@@ -347,7 +352,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
if (typeof options.closeCallback === "function") {
options.closeCallback.apply(undefined, originalArgs);
}
}
};
that._hideNativeModalView(parent, whenClosedCallback);
}
@@ -380,7 +385,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
object: this,
context: this._modalContext,
closeCallback: this._closeModalCallback
}
};
this.notify(args);
}
@@ -710,6 +715,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
if (!this._cssType) {
this._cssType = this.typeName.toLowerCase();
}
return this._cssType;
}
set cssType(type: string) {
@@ -953,6 +959,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
let changed: boolean = this._currentWidthMeasureSpec !== widthMeasureSpec || this._currentHeightMeasureSpec !== heightMeasureSpec;
this._currentWidthMeasureSpec = widthMeasureSpec;
this._currentHeightMeasureSpec = heightMeasureSpec;
return changed;
}
@@ -971,6 +978,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
this._oldTop = top;
this._oldRight = right;
this._oldBottom = bottom;
return { boundsChanged, sizeChanged };
}
@@ -1034,6 +1042,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
animation.target = this;
const anim = new animationModule.Animation([animation]);
this._localAnimations.add(anim);
return anim;
}

View File

@@ -102,13 +102,14 @@ function initializeDialogFragment() {
context: android.content.Context,
themeResId: number) {
super(context, themeResId);
return global.__native(this);
}
public onDetachedFromWindow(): void {
super.onDetachedFromWindow();
this.fragment = null;
};
}
public onBackPressed(): void {
const view = this.fragment.owner;
@@ -143,6 +144,7 @@ function initializeDialogFragment() {
constructor() {
super();
return global.__native(this);
}
@@ -177,6 +179,7 @@ function initializeDialogFragment() {
}
dialog.setCanceledOnTouchOutside(this._cancelable);
return dialog;
}
@@ -398,7 +401,7 @@ export class View extends ViewCommon {
}
private hasGestureObservers() {
return this._gestureObservers && Object.keys(this._gestureObservers).length > 0
return this._gestureObservers && Object.keys(this._gestureObservers).length > 0;
}
public initNativeView(): void {
@@ -555,10 +558,11 @@ export class View extends ViewCommon {
let nativeArray = (<any>Array).create("int", 2);
this.nativeViewProtected.getLocationInWindow(nativeArray);
return {
x: layout.toDeviceIndependentPixels(nativeArray[0]),
y: layout.toDeviceIndependentPixels(nativeArray[1]),
}
};
}
public getLocationOnScreen(): Point {
@@ -568,10 +572,11 @@ export class View extends ViewCommon {
let nativeArray = (<any>Array).create("int", 2);
this.nativeViewProtected.getLocationOnScreen(nativeArray);
return {
x: layout.toDeviceIndependentPixels(nativeArray[0]),
y: layout.toDeviceIndependentPixels(nativeArray[1]),
}
};
}
public getLocationRelativeTo(otherView: ViewCommon): Point {
@@ -585,10 +590,11 @@ export class View extends ViewCommon {
this.nativeViewProtected.getLocationOnScreen(myArray);
let otherArray = (<any>Array).create("int", 2);
otherView.nativeViewProtected.getLocationOnScreen(otherArray);
return {
x: layout.toDeviceIndependentPixels(myArray[0] - otherArray[0]),
y: layout.toDeviceIndependentPixels(myArray[1] - otherArray[1]),
}
};
}
public static resolveSizeAndState(size: number, specSize: number, specMode: number, childMeasuredState: number): number {
@@ -631,7 +637,7 @@ export class View extends ViewCommon {
cancelable: options.android ? !!options.android.cancelable : true,
shownCallback: () => this._raiseShownModallyEvent(),
dismissCallback: () => this.closeModal()
}
};
saveModal(dialogOptions);
@@ -811,7 +817,7 @@ export class View extends ViewCommon {
[horizontalAlignmentProperty.setNative](value: HorizontalAlignment) {
const nativeView = this.nativeViewProtected;
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
// Set only if params gravity exists.
// Set only if params gravity exists.
if (lp.gravity !== undefined) {
switch (value) {
case "left":
@@ -849,7 +855,7 @@ export class View extends ViewCommon {
[verticalAlignmentProperty.setNative](value: VerticalAlignment) {
const nativeView = this.nativeViewProtected;
const lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
// Set only if params gravity exists.
// Set only if params gravity exists.
if (lp.gravity !== undefined) {
switch (value) {
case "top":
@@ -992,6 +998,7 @@ export class CustomLayoutView extends ContainerView implements CustomLayoutViewD
if (child instanceof View) {
this._updateNativeLayoutParams(child);
}
return true;
}
@@ -1035,7 +1042,7 @@ interface NativePercentLengthPropertyOptions {
auto?: number;
getPixels?: NativeGetter;
setPixels: NativeSetter;
setPercent?: NativeSetter
setPercent?: NativeSetter;
}
function createNativePercentLengthProperty(options: NativePercentLengthPropertyOptions) {
@@ -1055,7 +1062,7 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
} else {
return { value, unit: "px" };
}
}
};
}
if (setter) {
View.prototype[setter] = function(this: View, length: PercentLength) {
@@ -1078,54 +1085,54 @@ function createNativePercentLengthProperty(options: NativePercentLengthPropertyO
} else {
throw new Error(`Unsupported PercentLength ${length}`);
}
}
};
}
}
createNativePercentLengthProperty({
setter: marginTopProperty.setNative,
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginTop },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginTopPercent }
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginTop; },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginTopPercent; }
});
createNativePercentLengthProperty({
setter: marginRightProperty.setNative,
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginRight },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginRightPercent }
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginRight; },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginRightPercent; }
});
createNativePercentLengthProperty({
setter: marginBottomProperty.setNative,
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginBottom },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginBottomPercent }
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginBottom; },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginBottomPercent; }
});
createNativePercentLengthProperty({
setter: marginLeftProperty.setNative,
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginLeft },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginLeftPercent }
get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginLeft; },
get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginLeftPercent; }
});
createNativePercentLengthProperty({
setter: widthProperty.setNative,
auto: -1, //android.view.ViewGroup.LayoutParams.MATCH_PARENT,
get setPixels() { return org.nativescript.widgets.ViewHelper.setWidth },
get setPercent() { return org.nativescript.widgets.ViewHelper.setWidthPercent }
get setPixels() { return org.nativescript.widgets.ViewHelper.setWidth; },
get setPercent() { return org.nativescript.widgets.ViewHelper.setWidthPercent; }
});
createNativePercentLengthProperty({
setter: heightProperty.setNative,
auto: -1, //android.view.ViewGroup.LayoutParams.MATCH_PARENT,
get setPixels() { return org.nativescript.widgets.ViewHelper.setHeight },
get setPercent() { return org.nativescript.widgets.ViewHelper.setHeightPercent }
get setPixels() { return org.nativescript.widgets.ViewHelper.setHeight; },
get setPercent() { return org.nativescript.widgets.ViewHelper.setHeightPercent; }
});
createNativePercentLengthProperty({
setter: "_setMinWidthNative",
get setPixels() { return org.nativescript.widgets.ViewHelper.setMinWidth }
get setPixels() { return org.nativescript.widgets.ViewHelper.setMinWidth; }
});
createNativePercentLengthProperty({
setter: "_setMinHeightNative",
get setPixels() { return org.nativescript.widgets.ViewHelper.setMinHeight }
get setPixels() { return org.nativescript.widgets.ViewHelper.setMinHeight; }
});

View File

@@ -270,6 +270,7 @@ export class View extends ViewCommon {
}
const pointInWindow = this.nativeViewProtected.convertPointToView(this.nativeViewProtected.bounds.origin, null);
return {
x: pointInWindow.x,
y: pointInWindow.y
@@ -283,6 +284,7 @@ export class View extends ViewCommon {
const pointInWindow = this.nativeViewProtected.convertPointToView(this.nativeViewProtected.bounds.origin, null);
const pointOnScreen = this.nativeViewProtected.window.convertPointToWindow(pointInWindow, null);
return {
x: pointOnScreen.x,
y: pointOnScreen.y
@@ -298,6 +300,7 @@ export class View extends ViewCommon {
const myPointInWindow = this.nativeViewProtected.convertPointToView(this.nativeViewProtected.bounds.origin, null);
const otherPointInWindow = otherView.nativeViewProtected.convertPointToView(otherView.nativeViewProtected.bounds.origin, null);
return {
x: myPointInWindow.x - otherPointInWindow.x,
y: myPointInWindow.y - otherPointInWindow.y
@@ -373,7 +376,8 @@ export class View extends ViewCommon {
const parentWithController = ios.getParentWithViewController(parent);
if (!parentWithController) {
traceWrite(`Could not find parent with viewController for ${parent} while showing modal view.`,
traceCategories.ViewHierarchy, traceMessageType.error)
traceCategories.ViewHierarchy, traceMessageType.error);
return;
}
@@ -381,12 +385,14 @@ export class View extends ViewCommon {
if (parentController.presentedViewController) {
traceWrite("Parent is already presenting view controller. Close the current modal page before showing another one!",
traceCategories.ViewHierarchy, traceMessageType.error);
return;
}
if (!parentController.view || !parentController.view.window) {
traceWrite("Parent page is not part of the window hierarchy.",
traceCategories.ViewHierarchy, traceMessageType.error);
return;
}
@@ -448,13 +454,15 @@ export class View extends ViewCommon {
protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) {
if (!parent || !parent.viewController) {
traceError("Trying to hide modal view but no parent with viewController specified.")
traceError("Trying to hide modal view but no parent with viewController specified.");
return;
}
// modal view has already been closed by UI, probably as a popover
if (!parent.viewController.presentedViewController) {
whenClosedCallback();
return;
}
@@ -466,6 +474,7 @@ export class View extends ViewCommon {
[isEnabledProperty.getDefault](): boolean {
const nativeView = this.nativeViewProtected;
return nativeView instanceof UIControl ? nativeView.enabled : true;
}
[isEnabledProperty.setNative](value: boolean) {
@@ -594,6 +603,7 @@ export class View extends ViewCommon {
const frame = nativeView.frame;
const origin = frame.origin;
const size = frame.size;
return {
left: Math.round(layout.toDevicePixels(origin.x)),
top: Math.round(layout.toDevicePixels(origin.y)),
@@ -729,6 +739,7 @@ export namespace ios {
layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor),
layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor)
]);
return layoutGuide;
}
@@ -794,6 +805,7 @@ export namespace ios {
return adjustedFrame;
}
return null;
}
@@ -901,7 +913,7 @@ export namespace ios {
const inWindow = CGRectMake(inWindowLeft, inWindowTop, frame.size.width, frame.size.height);
return { safeArea: safeArea, fullscreen: fullscreen, inWindow: inWindow }
return { safeArea: safeArea, fullscreen: fullscreen, inWindow: inWindow };
}
export class UILayoutViewController extends UIViewController {
@@ -910,6 +922,7 @@ export namespace ios {
public static initWithOwner(owner: WeakRef<View>): UILayoutViewController {
const controller = <UILayoutViewController>UILayoutViewController.new();
controller.owner = owner;
return controller;
}

View File

@@ -1,4 +1,4 @@
import { Observable, EventData } from "../../../data/observable";
import { Observable, EventData } from "../../../data/observable";
const handlersForEventName = new Map<string, (eventData: EventData) => void>();
const sourcesMap = new WeakMap<Observable, Map<string, Array<TargetHandlerPair>>>();
@@ -22,6 +22,7 @@ function getHandlerForEventName(eventName: string): (eventData: EventData) => vo
if (!sourceEventMap) {
// There is no event map for this source - it is safe to detach the listener;
source.removeEventListener(eventName, handlersForEventName.get(eventName));
return;
}