chore(): enable "prefer-for-of"

This commit is contained in:
Manu Mtz.-Almeida
2018-07-30 00:11:04 +02:00
parent d1fd1c5276
commit b0ed4265eb
7 changed files with 69 additions and 76 deletions

View File

@ -329,8 +329,8 @@ export class Animator {
*/ */
afterClearStyles(propertyNames: string[]): Animator { afterClearStyles(propertyNames: string[]): Animator {
this._afterStyles = this._afterStyles || {}; this._afterStyles = this._afterStyles || {};
for (let i = 0; i < propertyNames.length; i++) { for (const prop of propertyNames) {
this._afterStyles[propertyNames[i]] = ''; this._afterStyles[prop] = '';
} }
return this; return this;
} }
@ -407,9 +407,9 @@ export class Animator {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._playInit(opts); child._playInit(opts);
} }
} }
@ -465,9 +465,9 @@ export class Animator {
_playProgress(opts: PlayOptions | undefined) { _playProgress(opts: PlayOptions | undefined) {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._playProgress(opts); child._playProgress(opts);
} }
} }
@ -500,9 +500,9 @@ export class Animator {
if (!this._destroyed) { if (!this._destroyed) {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._playToStep(stepValue); child._playToStep(stepValue);
} }
} }
@ -569,9 +569,9 @@ export class Animator {
_playEnd(stepValue?: number) { _playEnd(stepValue?: number) {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._playEnd(stepValue); child._playEnd(stepValue);
} }
} }
@ -607,8 +607,8 @@ export class Animator {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
if (children[i]._hasDuration(opts)) { if (child._hasDuration(opts)) {
return true; return true;
} }
} }
@ -627,8 +627,8 @@ export class Animator {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
if (children[i]._hasDomReads()) { if (child._hasDomReads()) {
return true; return true;
} }
} }
@ -756,20 +756,19 @@ export class Animator {
const easing = (forcedLinearEasing ? 'linear' : this.getEasing()); const easing = (forcedLinearEasing ? 'linear' : this.getEasing());
const durString = dur + 'ms'; const durString = dur + 'ms';
for (let i = 0; i < elements.length; i++) { for (const { style } of elements) {
const eleStyle = elements[i].style;
if (dur > 0) { if (dur > 0) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
eleStyle.transform = ''; style.transform = '';
eleStyle.transitionDuration = durString; style.transitionDuration = durString;
// each animation can have a different easing // each animation can have a different easing
if (easing) { if (easing) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
eleStyle.transitionTimingFunction = easing; style.transitionTimingFunction = easing;
} }
} else { } else {
eleStyle.transform = 'none'; style.transform = 'none';
} }
} }
} }
@ -804,8 +803,8 @@ export class Animator {
_setBeforeStyles() { _setBeforeStyles() {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
children[i]._setBeforeStyles(); child._setBeforeStyles();
} }
} }
@ -818,24 +817,22 @@ export class Animator {
const addClasses = this._beforeAddClasses; const addClasses = this._beforeAddClasses;
const removeClasses = this._beforeRemoveClasses; const removeClasses = this._beforeRemoveClasses;
for (let i = 0; i < elements.length; i++) { for (const el of elements) {
const el = elements[i];
const elementClassList = el.classList; const elementClassList = el.classList;
// css classes to add before the animation // css classes to add before the animation
if (addClasses) { if (addClasses) {
for (let j = 0; j < addClasses.length; j++) { for (const c of addClasses) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
elementClassList.add(addClasses[j]); elementClassList.add(c);
} }
} }
// css classes to remove before the animation // css classes to remove before the animation
if (removeClasses) { if (removeClasses) {
for (const c of removeClasses) {
for (let j = 0; j < removeClasses.length; j++) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
elementClassList.remove(removeClasses[j]); elementClassList.remove(c);
} }
} }
@ -856,17 +853,17 @@ export class Animator {
_fireBeforeReadFunc() { _fireBeforeReadFunc() {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM READ **************** // ******** DOM READ ****************
children[i]._fireBeforeReadFunc(); child._fireBeforeReadFunc();
} }
} }
const readFunctions = this._readCallbacks; const readFunctions = this._readCallbacks;
if (readFunctions) { if (readFunctions) {
for (let i = 0; i < readFunctions.length; i++) { for (const callback of readFunctions) {
// ******** DOM READ **************** // ******** DOM READ ****************
readFunctions[i](); callback();
} }
} }
} }
@ -878,17 +875,17 @@ export class Animator {
_fireBeforeWriteFunc() { _fireBeforeWriteFunc() {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._fireBeforeWriteFunc(); child._fireBeforeWriteFunc();
} }
} }
const writeFunctions = this._writeCallbacks; const writeFunctions = this._writeCallbacks;
if (writeFunctions) { if (writeFunctions) {
for (let i = 0; i < writeFunctions.length; i++) { for (const callback of writeFunctions) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
writeFunctions[i](); callback();
} }
} }
} }
@ -979,8 +976,8 @@ export class Animator {
if (addWillChange && effects) { if (addWillChange && effects) {
wc = []; wc = [];
for (let i = 0; i < effects.length; i++) { for (const effect of effects) {
const propWC = effects[i].wc; const propWC = effect.wc;
if (propWC === 'webkitTransform') { if (propWC === 'webkitTransform') {
wc.push('transform', '-webkit-transform'); wc.push('transform', '-webkit-transform');
@ -996,9 +993,9 @@ export class Animator {
const elements = this._elements; const elements = this._elements;
if (elements) { if (elements) {
for (let i = 0; i < elements.length; i++) { for (const el of elements) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
(elements[i] as any).style.willChange = willChange; el.style.setProperty('will-change', willChange);
} }
} }
} }
@ -1024,9 +1021,9 @@ export class Animator {
_progressStart() { _progressStart() {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._progressStart(); child._progressStart();
} }
} }
@ -1047,9 +1044,9 @@ export class Animator {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i].progressStep(stepValue); child.progressStep(stepValue);
} }
} }
@ -1105,9 +1102,9 @@ export class Animator {
_progressEnd(shouldComplete: boolean, stepValue: number, dur: number, isAsync: boolean) { _progressEnd(shouldComplete: boolean, stepValue: number, dur: number, isAsync: boolean) {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
children[i]._progressEnd(shouldComplete, stepValue, dur, isAsync); child._progressEnd(shouldComplete, stepValue, dur, isAsync);
} }
} }
@ -1157,8 +1154,8 @@ export class Animator {
_didFinishAll(hasCompleted: boolean, finishAsyncAnimations: boolean, finishNoDurationAnimations: boolean) { _didFinishAll(hasCompleted: boolean, finishAsyncAnimations: boolean, finishNoDurationAnimations: boolean) {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
children[i]._didFinishAll(hasCompleted, finishAsyncAnimations, finishNoDurationAnimations); child._didFinishAll(hasCompleted, finishAsyncAnimations, finishNoDurationAnimations);
} }
} }
@ -1176,15 +1173,15 @@ export class Animator {
if (this._onFinishCallbacks) { if (this._onFinishCallbacks) {
// run all finish callbacks // run all finish callbacks
for (let i = 0; i < this._onFinishCallbacks.length; i++) { for (const callback of this._onFinishCallbacks) {
this._onFinishCallbacks[i](this); callback(this);
} }
} }
if (this._onFinishOneTimeCallbacks) { if (this._onFinishOneTimeCallbacks) {
// run all "onetime" finish callbacks // run all "onetime" finish callbacks
for (let i = 0; i < this._onFinishOneTimeCallbacks.length; i++) { for (const callback of this._onFinishOneTimeCallbacks) {
this._onFinishOneTimeCallbacks[i](this); callback(this);
} }
this._onFinishOneTimeCallbacks.length = 0; this._onFinishOneTimeCallbacks.length = 0;
} }
@ -1199,8 +1196,8 @@ export class Animator {
} }
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
children[i].reverse(shouldReverse); child.reverse(shouldReverse);
} }
} }
this._isReverse = !!shouldReverse; this._isReverse = !!shouldReverse;
@ -1215,8 +1212,8 @@ export class Animator {
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
children[i].destroy(); child.destroy();
} }
} }
@ -1254,8 +1251,8 @@ export class Animator {
// get the lowest level element that has an Animator // get the lowest level element that has an Animator
const children = this._childAnimations; const children = this._childAnimations;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (const child of children) {
const targetEl = children[i]._transEl(); const targetEl = child._transEl();
if (targetEl) { if (targetEl) {
return targetEl; return targetEl;
} }
@ -1267,6 +1264,7 @@ export class Animator {
this._hasDur && this._hasDur &&
this._elements && this._elements &&
this._elements.length > 0 ? this._elements.length > 0 ?
this._elements[0] : null); this._elements[0] : null
);
} }
} }

View File

@ -493,8 +493,8 @@ export class Datetime {
col = pickerColumns[i]; col = pickerColumns[i];
columnsWidth.push(0); columnsWidth.push(0);
for (let j = 0; j < col.options.length; j++) { for (const option of col.options) {
width = col.options[j].text!.length; width = option.text!.length;
if (width > columnsWidth[i]) { if (width > columnsWidth[i]) {
columnsWidth[i] = width; columnsWidth[i] = width;
} }

View File

@ -31,12 +31,11 @@ export class ItemDivider {
componentDidLoad() { componentDidLoad() {
// Change the button size to small for each ion-button in the item // Change the button size to small for each ion-button in the item
// unless the size is explicitly set // unless the size is explicitly set
const buttons = this.el.querySelectorAll('ion-button'); Array.from(this.el.querySelectorAll('ion-button')).forEach(button => {
for (let i = 0; i < buttons.length; i++) { if (!button.size) {
if (!buttons[i].size) { button.size = 'small';
buttons[i].size = 'small';
} }
} });
} }
hostData() { hostData() {

View File

@ -76,8 +76,7 @@ export function matches(view: ViewController | undefined, id: string, params: Co
} }
// Test for A's keys different from B. // Test for A's keys different from B.
for (let i = 0; i < keysA.length; i++) { for (const key of keysA) {
const key = keysA[i];
if (currentParams[key] !== params[key]) { if (currentParams[key] !== params[key]) {
return false; return false;
} }

View File

@ -50,8 +50,7 @@ export class Route {
this.onUpdate(newValue); this.onUpdate(newValue);
return; return;
} }
for (let i = 0; i < keys1.length; i++) { for (const key of keys1) {
const key = keys1[i];
if (newValue[key] !== oldValue[key]) { if (newValue[key] !== oldValue[key]) {
this.onUpdate(newValue); this.onUpdate(newValue);
return; return;

View File

@ -38,10 +38,9 @@ export function isFocused(input: HTMLInputElement): boolean {
function removeClone(componentEl: HTMLElement, inputEl: HTMLElement) { function removeClone(componentEl: HTMLElement, inputEl: HTMLElement) {
if (componentEl && componentEl.parentElement) { if (componentEl && componentEl.parentElement) {
const clonedInputEles = componentEl.parentElement.querySelectorAll('.cloned-input'); Array.from(componentEl.parentElement.querySelectorAll('.cloned-input'))
for (let i = 0; i < clonedInputEles.length; i++) { .forEach(clon => clon.remove());
clonedInputEles[i].remove();
}
componentEl.style.pointerEvents = ''; componentEl.style.pointerEvents = '';
} }
(inputEl.style as any)['transform'] = ''; (inputEl.style as any)['transform'] = '';

View File

@ -4,7 +4,6 @@
"no-conditional-assignment": false, "no-conditional-assignment": false,
"no-non-null-assertion": false, "no-non-null-assertion": false,
"no-unnecessary-type-assertion": false, "no-unnecessary-type-assertion": false,
"prefer-for-of": false,
"no-import-side-effect": false, "no-import-side-effect": false,
"trailing-comma": false, "trailing-comma": false,
"no-null-keyword": false, "no-null-keyword": false,