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) { (function(window) {
'use strict'; 'use strict';
/** @polymerBehavior Gerrit.RESTClientBehavior */ /** @polymerBehavior Gerrit.RESTClientBehavior */
var RESTClientBehavior = { var RESTClientBehavior = {
ChangeDiffType: { ChangeDiffType: {

View File

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

View File

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

View File

@@ -178,8 +178,6 @@ limitations under the License.
}, },
getCommentThreadByLine: function(lineNumber, opt_side, opt_root) { 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); var content = this.getContentByLine(lineNumber, opt_side, opt_root);
return this.getCommentThreadByContentEl(content); return this.getCommentThreadByContentEl(content);
}, },

View File

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

View File

@@ -128,7 +128,8 @@ limitations under the License.
setup(function() { setup(function() {
stub('gr-rest-api-interface', { stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); }, getLoggedIn: function() { return Promise.resolve(false); },
saveDiffDraft: function() { return Promise.resolve({ saveDiffDraft: function() {
return Promise.resolve({
ok: true, ok: true,
text: function() { return Promise.resolve(')]}\'\n' + text: function() { return Promise.resolve(')]}\'\n' +
JSON.stringify({ JSON.stringify({
@@ -140,7 +141,8 @@ limitations under the License.
message: 'Done' message: 'Done'
})); }));
}, },
})}, });
},
deleteDiffDraft: function() { return Promise.resolve({ok: true}); }, deleteDiffDraft: function() { return Promise.resolve({ok: true}); },
}); });
element = fixture('withComment'); element = fixture('withComment');

View File

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

View File

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

View File

@@ -209,7 +209,7 @@ limitations under the License.
}); });
test('insert context groups', function(done) { test('insert context groups', function(done) {
content = [ var content = [
{a: ['all work and no play make andybons a dull boy']}, {a: ['all work and no play make andybons a dull boy']},
{ab: []}, {ab: []},
{b: ['elgoog elgoog elgoog']}, {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. // Set the actual value of the select, and simulate the change event.
select.value = newMode; 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. // Make sure the handler was called and the state is still coherent.
assert.equal(element._getDiffViewMode(), newMode); assert.equal(element._getDiffViewMode(), newMode);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -39,6 +39,14 @@ breaking changes to gr-change-actions wont be noticed.
var element; var element;
var changeActions; 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() { setup(function() {
element = fixture('basic'); element = fixture('basic');
var plugin; 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() { test('add/remove primary action keys', function() {
element.primaryActionKeys = []; element.primaryActionKeys = [];
changeActions.addPrimaryActionKey('foo'); changeActions.addPrimaryActionKey('foo');

View File

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

View File

@@ -468,7 +468,7 @@
}, },
getSuggestedProjects: function(inputVal, opt_errFn, opt_ctx) { 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) { addChangeReviewer: function(changeNum, reviewerID) {

View File

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

View File

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