Enable no-confusing-arrow and newline-per-chained-call

Change-Id: I3b1a88301cfacf75593dea5e19a2e6b6b2869740
This commit is contained in:
Tao Zhou
2020-01-10 11:39:34 +01:00
parent f6605f368b
commit 80cfe59582
61 changed files with 593 additions and 466 deletions

View File

@@ -197,11 +197,13 @@ limitations under the License.
return suggestion._account_id === accountId;
};
element._getSuggestions().then(suggestions => {
assert.deepEqual(suggestions,
[{name: originalSuggestions[0].email,
value: originalSuggestions[0]._account_id}]);
}).then(done);
element._getSuggestions()
.then(suggestions => {
assert.deepEqual(suggestions,
[{name: originalSuggestions[0].email,
value: originalSuggestions[0]._account_id}]);
})
.then(done);
});
});

View File

@@ -291,10 +291,11 @@
this._fireSave();
return obj;
});
}).catch(err => {
this.disabled = false;
throw err;
});
})
.catch(err => {
this.disabled = false;
throw err;
});
return this._xhrPromise;
}
@@ -568,10 +569,11 @@
}
this._fireDiscard();
}).catch(err => {
this.disabled = false;
throw err;
});
})
.catch(err => {
this.disabled = false;
throw err;
});
return this._xhrPromise;
}

View File

@@ -62,7 +62,9 @@ limitations under the License.
expectedTooltip, done) {
// Normalize and convert the date to mimic server response.
dateStr = normalizedDate(dateStr)
.toJSON().replace('T', ' ').slice(0, -1);
.toJSON()
.replace('T', ' ')
.slice(0, -1);
sandbox.useFakeTimers(normalizedDate(nowStr).getTime());
element.dateStr = dateStr;
flush(() => {

View File

@@ -75,24 +75,26 @@
// TODO(taoalpha): to be deprecated.
function send(method, url, opt_callback, opt_payload) {
return getRestAPI().send(method, url, opt_payload).then(response => {
if (response.status < 200 || response.status >= 300) {
return response.text().then(text => {
if (text) {
return Promise.reject(new Error(text));
return getRestAPI().send(method, url, opt_payload)
.then(response => {
if (response.status < 200 || response.status >= 300) {
return response.text().then(text => {
if (text) {
return Promise.reject(new Error(text));
} else {
return Promise.reject(new Error(response.status));
}
});
} else {
return Promise.reject(new Error(response.status));
return getRestAPI().getResponseObject(response);
}
})
.then(response => {
if (opt_callback) {
opt_callback(response);
}
return response;
});
} else {
return getRestAPI().getResponseObject(response);
}
}).then(response => {
if (opt_callback) {
opt_callback(response);
}
return response;
});
}
// TEST only methods / properties

View File

@@ -109,21 +109,22 @@
Gerrit.delete = function(url, opt_callback) {
console.warn('.delete() is deprecated! Use plugin.restApi().delete()');
return getRestAPI().send('DELETE', url).then(response => {
if (response.status !== 204) {
return response.text().then(text => {
if (text) {
return Promise.reject(new Error(text));
} else {
return Promise.reject(new Error(response.status));
return getRestAPI().send('DELETE', url)
.then(response => {
if (response.status !== 204) {
return response.text().then(text => {
if (text) {
return Promise.reject(new Error(text));
} else {
return Promise.reject(new Error(response.status));
}
});
}
if (opt_callback) {
opt_callback(response);
}
return response;
});
}
if (opt_callback) {
opt_callback(response);
}
return response;
});
};
Gerrit.awaitPluginsLoaded = function() {

View File

@@ -329,10 +329,11 @@ limitations under the License.
sandbox.stub(window, 'fetch', () => {
return Promise.resolve({status: 204});
});
plugin.restApi().getLoggedIn().then(loggedIn => {
assert.isTrue(loggedIn);
done();
});
plugin.restApi().getLoggedIn()
.then(loggedIn => {
assert.isTrue(loggedIn);
done();
});
});
test('attributeHelper', () => {

View File

@@ -121,10 +121,11 @@ limitations under the License.
{status: 400, text() { return Promise.resolve('text'); }}));
return instance.delete('/url').then(r => {
throw new Error('Should not resolve');
}).catch(err => {
assert.isTrue(sendStub.calledWith('DELETE', '/url'));
assert.equal('text', err.message);
});
})
.catch(err => {
assert.isTrue(sendStub.calledWith('DELETE', '/url'));
assert.equal('text', err.message);
});
});
test('getLoggedIn', () => {

View File

@@ -133,7 +133,8 @@
target.disabled = false;
if (!response.ok) { return; }
Gerrit.Nav.navigateToChange(this.change);
}).catch(err => {
})
.catch(err => {
target.disabled = false;
return;
});

View File

@@ -59,7 +59,8 @@
if (!this._hljsState.loading) {
this._hljsState.loading = true;
this._loadScript(this._getHLJSUrl())
.then(this._onHLJSLibLoaded.bind(this)).catch(reject);
.then(this._onHLJSLibLoaded.bind(this))
.catch(reject);
}
this._hljsState.callbacks.push(resolve);

View File

@@ -315,17 +315,21 @@ limitations under the License.
sandbox.stub(auth, '_isTokenValid');
auth._isTokenValid
.onFirstCall().returns(true)
.onSecondCall().returns(false)
.onThirdCall().returns(true);
auth.fetch('/url-one').then(() => {
getToken.returns(Promise.resolve(makeToken('bzzbb')));
return auth.fetch('/url-two');
}).then(() => {
const [[firstUrl], [secondUrl]] = fetch.args;
assert.equal(firstUrl, '/a/url-one?access_token=zbaz');
assert.equal(secondUrl, '/a/url-two?access_token=bzzbb');
done();
});
.onSecondCall()
.returns(false)
.onThirdCall()
.returns(true);
auth.fetch('/url-one')
.then(() => {
getToken.returns(Promise.resolve(makeToken('bzzbb')));
return auth.fetch('/url-two');
})
.then(() => {
const [[firstUrl], [secondUrl]] = fetch.args;
assert.equal(firstUrl, '/a/url-one?access_token=zbaz');
assert.equal(secondUrl, '/a/url-two?access_token=bzzbb');
done();
});
});
test('signed in token error falls back to anonymous', done => {

View File

@@ -815,15 +815,17 @@
}
getIsAdmin() {
return this.getLoggedIn().then(isLoggedIn => {
if (isLoggedIn) {
return this.getAccountCapabilities();
} else {
return Promise.resolve();
}
}).then(capabilities => {
return capabilities && capabilities.administrateServer;
});
return this.getLoggedIn()
.then(isLoggedIn => {
if (isLoggedIn) {
return this.getAccountCapabilities();
} else {
return Promise.resolve();
}
})
.then(capabilities => {
return capabilities && capabilities.administrateServer;
});
}
getDefaultPreferences() {

View File

@@ -650,15 +650,17 @@ limitations under the License.
['Innocuous', 'hello'],
]},
};
element._failForCreate200(Promise.resolve(result)).then(() => {
assert.isTrue(false, 'Promise should not resolve');
}).catch(e => {
assert.isOk(e);
assert.include(e.message, 'Saving draft resulted in HTTP 200');
assert.include(e.message, 'hello');
assert.notInclude(e.message, 'secret');
done();
});
element._failForCreate200(Promise.resolve(result))
.then(() => {
assert.isTrue(false, 'Promise should not resolve');
})
.catch(e => {
assert.isOk(e);
assert.include(e.message, 'Saving draft resulted in HTTP 200');
assert.include(e.message, 'hello');
assert.notInclude(e.message, 'secret');
done();
});
});
test('_failForCreate200 does not fail on 201', done => {
@@ -667,11 +669,13 @@ limitations under the License.
status: 201,
headers: {entries: () => []},
};
element._failForCreate200(Promise.resolve(result)).then(() => {
done();
}).catch(e => {
assert.isTrue(false, 'Promise should not fail');
});
element._failForCreate200(Promise.resolve(result))
.then(() => {
done();
})
.catch(e => {
assert.isTrue(false, 'Promise should not fail');
});
});
});
});

View File

@@ -180,20 +180,22 @@
fetchOptions: req.fetchOptions,
anonymizedUrl: req.reportUrlAsIs ? urlWithParams : req.anonymizedUrl,
};
return this.fetch(fetchReq).then(res => {
if (req.cancelCondition && req.cancelCondition()) {
res.body.cancel();
return;
}
return res;
}).catch(err => {
if (req.errFn) {
req.errFn.call(undefined, null, err);
} else {
this.fire('network-error', {error: err});
}
throw err;
});
return this.fetch(fetchReq)
.then(res => {
if (req.cancelCondition && req.cancelCondition()) {
res.body.cancel();
return;
}
return res;
})
.catch(err => {
if (req.errFn) {
req.errFn.call(undefined, null, err);
} else {
this.fire('network-error', {error: err});
}
throw err;
});
}
/**
@@ -309,16 +311,18 @@
return Promise.resolve(this._cache.get(req.url));
}
this._fetchPromisesCache.set(req.url,
this.fetchJSON(req).then(response => {
if (response !== undefined) {
this._cache.set(req.url, response);
}
this._fetchPromisesCache.set(req.url, undefined);
return response;
}).catch(err => {
this._fetchPromisesCache.set(req.url, undefined);
throw err;
})
this.fetchJSON(req)
.then(response => {
if (response !== undefined) {
this._cache.set(req.url, response);
}
this._fetchPromisesCache.set(req.url, undefined);
return response;
})
.catch(err => {
this._fetchPromisesCache.set(req.url, undefined);
throw err;
})
);
return this._fetchPromisesCache.get(req.url);
}
@@ -360,14 +364,15 @@
this.fire('server-error', {request: fetchReq, response});
}
return response;
}).catch(err => {
this.fire('network-error', {error: err});
if (req.errFn) {
return req.errFn.call(undefined, null, err);
} else {
throw err;
}
});
})
.catch(err => {
this.fire('network-error', {error: err});
if (req.errFn) {
return req.errFn.call(undefined, null, err);
} else {
throw err;
}
});
if (req.parseResponse) {
return xhr.then(res => this.getResponseObject(res));

View File

@@ -217,7 +217,9 @@
const timestamp = util.parseDate(update.date).getTime() -
GrReviewerUpdatesParser.MESSAGE_REVIEWERS_THRESHOLD_MILLIS;
update.date = new Date(timestamp)
.toISOString().replace('T', ' ').replace('Z', '000000');
.toISOString()
.replace('T', ' ')
.replace('Z', '000000');
}
if (nextMessageDate && date > nextMessageDate) {
break;

View File

@@ -255,7 +255,9 @@ limitations under the License.
const T0 = util.parseDate('2017-02-17 19:04:18.000000000').getTime();
const tplus = delta => {
return new Date(T0 + delta)
.toISOString().replace('T', ' ').replace('Z', '000000');
.toISOString()
.replace('T', ' ')
.replace('Z', '000000');
};
const change = {
reviewer_updates: [{