Fix issues detected by 'JSHint' and 'JSCS'

Change-Id: Ic1437333fcf82473ac57f8bdea25ee8188ddbfee
This commit is contained in:
Urs Wolfer
2016-07-13 21:06:03 +02:00
parent 7bcc753296
commit 33df005810
23 changed files with 72 additions and 68 deletions

View File

@@ -18,7 +18,6 @@ limitations under the License.
(function(window) {
'use strict';
/** @polymerBehavior Gerrit.RESTClientBehavior */
var RESTClientBehavior = {
ChangeDiffType: {

View File

@@ -159,12 +159,13 @@ limitations under the License.
suite('gr-download-dialog tests', function() {
var element;
var getPrefsStub;
setup(function() {
stub('gr-rest-api-interface', { getPreferences: function() {
return Promise.resolve({download_scheme: 'repo'});
}});
stub('gr-rest-api-interface', {
getPreferences: function() {
return Promise.resolve({download_scheme: 'repo'});
},
});
element = fixture('loggedIn');
element.change = getChangeObject();

View File

@@ -74,7 +74,7 @@
this._sameTopic = response;
}.bind(this));
} else {
this._sameTopic = [];
this._sameTopic = [];
}
return this._sameTopic;
}.bind(this)).then(Promise.all(promises)).then(function() {

View File

@@ -81,6 +81,13 @@
page.redirect('/c/' + encodeURIComponent(ctx.params[0]));
});
function normalizePatchRangeParams(params) {
if (params.basePatchNum && !params.patchNum) {
params.patchNum = params.basePatchNum;
params.basePatchNum = null;
}
}
// Matches /c/<changeNum>/[<basePatchNum>..][<patchNum>].
page(/^\/c\/(\d+)\/?(((\d+)(\.\.(\d+))?))?$/, function(ctx) {
// Parameter order is based on the regex group number matched.
@@ -129,13 +136,6 @@
app.params = params;
});
function normalizePatchRangeParams(params) {
if (params.basePatchNum && !params.patchNum) {
params.patchNum = params.basePatchNum;
params.basePatchNum = null;
}
}
page(/^\/settings\/?/, function(data) {
restAPI.getLoggedIn().then(function(loggedIn) {
if (loggedIn) {

View File

@@ -178,8 +178,6 @@ limitations under the License.
},
getCommentThreadByLine: function(lineNumber, opt_side, opt_root) {
var root = Polymer.dom(opt_root || this.diffElement);
var sideSelector = !!opt_side ? ('.' + opt_side) : '';
var content = this.getContentByLine(lineNumber, opt_side, opt_root);
return this.getCommentThreadByContentEl(content);
},

View File

@@ -42,6 +42,7 @@ limitations under the License.
<script>
suite('gr-diff-builder tests', function() {
var element;
var builder;
setup(function() {
@@ -445,7 +446,7 @@ limitations under the License.
};
return builder;
});
element.render({ content: content }, {left: [], right: []}, prefs);
element.render({content: content}, {left: [], right: []}, prefs);
});
test('renderSection', function() {

View File

@@ -128,19 +128,21 @@ limitations under the License.
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); },
saveDiffDraft: function() { return Promise.resolve({
ok: true,
text: function() { return Promise.resolve(')]}\'\n' +
JSON.stringify({
id: '7afa4931_de3d65bd',
path: '/path/to/file.txt',
line: 5,
in_reply_to: 'baf0414d_60047215',
updated: '2015-12-21 02:01:10.850000000',
message: 'Done'
}));
},
})},
saveDiffDraft: function() {
return Promise.resolve({
ok: true,
text: function() { return Promise.resolve(')]}\'\n' +
JSON.stringify({
id: '7afa4931_de3d65bd',
path: '/path/to/file.txt',
line: 5,
in_reply_to: 'baf0414d_60047215',
updated: '2015-12-21 02:01:10.850000000',
message: 'Done'
}));
},
});
},
deleteDiffDraft: function() { return Promise.resolve({ok: true}); },
});
element = fixture('withComment');

View File

@@ -67,7 +67,8 @@ limitations under the License.
'Justo purus, semper eget et.',
],
},
{ 'a': [
{
'a': [
'Est amet, vestibulum pellentesque.',
'Erat ligula.',
'Justo eros.',

View File

@@ -151,8 +151,7 @@
var sectionEnd = null;
if (state.sectionIndex === 0) {
sectionEnd = 'first';
}
else if (state.sectionIndex === content.length - 1) {
} else if (state.sectionIndex === content.length - 1) {
sectionEnd = 'last';
}

View File

@@ -209,7 +209,7 @@ limitations under the License.
});
test('insert context groups', function(done) {
content = [
var content = [
{a: ['all work and no play make andybons a dull boy']},
{ab: []},
{b: ['elgoog elgoog elgoog']},

View File

@@ -379,7 +379,7 @@ limitations under the License.
// Set the actual value of the select, and simulate the change event.
select.value = newMode;
element.fire('change', {}, { node: select });
element.fire('change', {}, {node: select});
// Make sure the handler was called and the state is still coherent.
assert.equal(element._getDiffViewMode(), newMode);

View File

@@ -191,7 +191,6 @@
},
_addDraft: function(lineEl, opt_lineNum) {
var line = opt_lineNum || lineEl.getAttribute('data-value');
var contentText = this.$.diffBuilder.getContentByLineEl(lineEl);
var contentEl = contentText.parentElement;
var patchNum = this._getPatchNumByLineAndContent(lineEl, contentEl);

View File

@@ -293,6 +293,8 @@ limitations under the License.
element._handleTap(e);
assert.isTrue(selectStub.called);
assert.equal(selectStub.lastCall.args[0], lineEl);
selectStub.restore();
getLineStub.restore();
done();
});
content.click();

View File

@@ -56,7 +56,7 @@ limitations under the License.
username: 'user username',
registered: '2000-01-01 00:00:00.000000000',
};
config = {auth: {editable_account_fields: []}},
config = {auth: {editable_account_fields: []}};
stub('gr-rest-api-interface', {
getAccount: function() { return Promise.resolve(account); },

View File

@@ -91,7 +91,6 @@ limitations under the License.
});
test('delete email', function() {
var deleteSpy = sinon.spy(element, '_handleDeleteButton');
var buttons = element.$$('table').querySelectorAll('gr-button');
assert.isFalse(element.hasUnsavedChanges);

View File

@@ -48,7 +48,7 @@ limitations under the License.
});
element = fixture('basic');
element.loadData().then(function() { flush(done) });
element.loadData().then(function() { flush(done); });
});
test('loads data', function() {
@@ -111,7 +111,6 @@ limitations under the License.
setup(function(done) {
account = {username: 'user name'};
password = 'the password';
stub('gr-rest-api-interface', {
getAccount: function() { return Promise.resolve(account); },
@@ -122,7 +121,7 @@ limitations under the License.
});
element = fixture('basic');
element.loadData().then(function() { flush(done) });
element.loadData().then(function() { flush(done); });
});
test('loads data', function() {

View File

@@ -66,7 +66,7 @@ limitations under the License.
function stubAddAccountEmail(statusCode) {
return sinon.stub(element.$.restAPI, 'addAccountEmail',
function() { return Promise.resolve({ status: statusCode }); });
function() { return Promise.resolve({status: statusCode}); });
}
setup(function(done) {
@@ -103,8 +103,7 @@ limitations under the License.
theme: 'DEFAULT',
ignore_whitespace: 'IGNORE_NONE'
};
config = {auth: {editable_account_fields: []}},
watchedProjects = [];
config = {auth: {editable_account_fields: []}};
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(true); },
@@ -114,7 +113,7 @@ limitations under the License.
return Promise.resolve(diffPreferences);
},
getWatchedProjects: function() {
return Promise.resolve(watchedProjects);
return Promise.resolve([]);
},
getAccountEmails: function() { return Promise.resolve(); },
getConfig: function() { return Promise.resolve(config); },

View File

@@ -73,7 +73,7 @@ limitations under the License.
element = fixture('basic');
element.loadData().then(function() { flush(done) });
element.loadData().then(function() { flush(done); });
});
test('renders', function() {

View File

@@ -39,6 +39,14 @@ breaking changes to gr-change-actions wont be noticed.
var element;
var changeActions;
// Because deepEqual doesnt behave in Safari.
function assertArraysEqual(actual, expected) {
assert.equal(actual.length, expected.length);
for (var i = 0; i < actual.length; i++) {
assert.equal(actual[i], expected[i]);
}
}
setup(function() {
element = fixture('basic');
var plugin;
@@ -61,14 +69,6 @@ breaking changes to gr-change-actions wont be noticed.
});
});
// Because deepEqual doesnt behave in Safari.
function assertArraysEqual(actual, expected) {
assert.equal(actual.length, expected.length);
for (var i = 0; i < actual.length; i++) {
assert.equal(actual[i], expected[i]);
}
}
test('add/remove primary action keys', function() {
element.primaryActionKeys = [];
changeActions.addPrimaryActionKey('foo');

View File

@@ -61,7 +61,7 @@
*/
_awaitOpen: function(fn) {
var iters = 0;
function step() {
var step = function() {
this.async(function() {
if (this.style.display !== 'none') {
fn.call(this);
@@ -69,7 +69,7 @@
step.call(this);
}
}.bind(this), AWAIT_STEP);
};
}.bind(this);
step.call(this);
},
});

View File

@@ -468,7 +468,7 @@
},
getSuggestedProjects: function(inputVal, opt_errFn, opt_ctx) {
return this.fetchJSON('/projects/', opt_errFn, opt_ctx, { p: inputVal, });
return this.fetchJSON('/projects/', opt_errFn, opt_ctx, {p: inputVal});
},
addChangeReviewer: function(changeNum, reviewerID) {

View File

@@ -48,9 +48,12 @@ limitations under the License.
var testJSON = ')]}\'\n{"hello": "bonjour"}';
sandbox.stub(window, 'fetch', function() {
return Promise.resolve({ok: true, text: function() {
return Promise.resolve(testJSON);
}});
return Promise.resolve({
ok: true,
text: function() {
return Promise.resolve(testJSON);
},
});
});
element.fetchJSON('/dummy/url').then(function(obj) {
assert.deepEqual(obj, {hello: 'bonjour'});
@@ -110,9 +113,11 @@ limitations under the License.
test('request callbacks can be canceled', function(done) {
var cancelCalled = false;
sandbox.stub(window, 'fetch', function() {
return Promise.resolve({body: {
cancel: function() { cancelCalled = true; }
}});
return Promise.resolve({
body: {
cancel: function() { cancelCalled = true; }
},
});
});
element.fetchJSON('/dummy/url', null, function() { return true; }).then(
function(obj) {

View File

@@ -33,12 +33,6 @@ limitations under the License.
var element;
var storage;
setup(function() {
element = fixture('basic');
storage = element._storage;
cleanupStorage();
});
function cleanupStorage() {
// Make sure there are no entries in storage.
for (var key in window.localStorage) {
@@ -46,6 +40,12 @@ limitations under the License.
}
}
setup(function() {
element = fixture('basic');
storage = element._storage;
cleanupStorage();
});
test('storing, retrieving and erasing drafts', function() {
var changeNum = 1234;
var patchNum = 5;