Fix issues detected by 'JSHint' and 'JSCS'

Change-Id: Id16d7abe53d5f65c97bf778dc532e404b41283d8
This commit is contained in:
Urs Wolfer
2016-10-19 22:30:42 +02:00
parent a690d72ba4
commit a010547eef
17 changed files with 30 additions and 52 deletions

View File

@@ -105,7 +105,6 @@
}, },
additions: function() { additions: function() {
var result = [];
return this.accounts.filter(function(account) { return this.accounts.filter(function(account) {
return account._pendingAdd; return account._pendingAdd;
}).map(function(account) { }).map(function(account) {
@@ -115,7 +114,6 @@
return {account: account}; return {account: account};
} }
}); });
return result;
}, },
}); });
})(); })();

View File

@@ -484,7 +484,7 @@
switch (action.__key) { switch (action.__key) {
case ChangeActions.REVERT: case ChangeActions.REVERT:
this._setLabelValuesOnRevert(obj.change_id); this._setLabelValuesOnRevert(obj.change_id);
// Fall through. /* falls through */
case RevisionActions.CHERRYPICK: case RevisionActions.CHERRYPICK:
page.show(this.changePath(obj._number)); page.show(this.changePath(obj._number));
break; break;

View File

@@ -334,15 +334,6 @@ limitations under the License.
test('branch name cleared when re-open cherrypick', function() { test('branch name cleared when re-open cherrypick', function() {
var cherryPickButton = var cherryPickButton =
element.$$('gr-button[data-action-key="cherrypick"]'); element.$$('gr-button[data-action-key="cherrypick"]');
var action = {
__key: 'cherrypick',
__type: 'revision',
__primary: false,
enabled: true,
label: 'Cherry Pick',
method: 'POST',
title: 'Cherry pick change to a different branch',
};
var emptyBranchName = ''; var emptyBranchName = '';
element.$.confirmCherrypick.branch = 'master'; element.$.confirmCherrypick.branch = 'master';

View File

@@ -540,6 +540,7 @@ limitations under the License.
suite('scroll related tests', function() { suite('scroll related tests', function() {
test('document scrolling calls function to set scroll height', test('document scrolling calls function to set scroll height',
function(done) { function(done) {
var originalHeight = document.body.scrollHeight;
var scrollStub = sandbox.stub(element, '_handleScroll', var scrollStub = sandbox.stub(element, '_handleScroll',
function() { function() {
assert.isTrue(scrollStub.called); assert.isTrue(scrollStub.called);
@@ -547,7 +548,6 @@ limitations under the License.
originalHeight + 'px'; originalHeight + 'px';
done(); done();
}); });
var originalHeight = document.body.scrollHeight;
document.body.style.height = '10000px'; document.body.style.height = '10000px';
document.body.scrollTop = TEST_SCROLL_TOP_PX; document.body.scrollTop = TEST_SCROLL_TOP_PX;
element._handleScroll(); element._handleScroll();

View File

@@ -150,9 +150,11 @@ limitations under the License.
var toggleLeftDiffStub = sandbox.stub(); var toggleLeftDiffStub = sandbox.stub();
// Property getter cannot be stubbed w/ sandbox due to a bug in Sinon. // Property getter cannot be stubbed w/ sandbox due to a bug in Sinon.
// https://github.com/sinonjs/sinon/issues/781 // https://github.com/sinonjs/sinon/issues/781
var diffsStub = sinon.stub(element, 'diffs', {get: function() { var diffsStub = sinon.stub(element, 'diffs', {
get: function() {
return [{toggleLeftDiff: toggleLeftDiffStub}]; return [{toggleLeftDiff: toggleLeftDiffStub}];
}}); },
});
MockInteractions.pressAndReleaseKeyOn(element, 65, 'shift'); // 'A' MockInteractions.pressAndReleaseKeyOn(element, 65, 'shift'); // 'A'
assert.isTrue(toggleLeftDiffStub.calledOnce); assert.isTrue(toggleLeftDiffStub.calledOnce);
diffsStub.restore(); diffsStub.restore();
@@ -401,7 +403,6 @@ limitations under the License.
}; };
element.selectedIndex = 0; element.selectedIndex = 0;
flushAsynchronousOperations(); flushAsynchronousOperations();
var select = element.$.modeSelect;
var diffDisplay = element.diffs[0]; var diffDisplay = element.diffs[0];
element._userPrefs = {diff_view: 'SIDE_BY_SIDE'}; element._userPrefs = {diff_view: 'SIDE_BY_SIDE'};
assert.equal(element._getDiffViewMode(), 'SIDE_BY_SIDE'); assert.equal(element._getDiffViewMode(), 'SIDE_BY_SIDE');

View File

@@ -116,11 +116,6 @@ limitations under the License.
}); });
test('messages', function() { test('messages', function() {
var dates = [
'2016-01-12 20:28:33.038000',
'2016-01-12 21:28:33.038000',
'2016-01-12 22:28:33.038000'
];
var author = { var author = {
_account_id: 42, _account_id: 42,
name: 'Marvin the Paranoid Android', name: 'Marvin the Paranoid Android',

View File

@@ -74,7 +74,7 @@ limitations under the License.
}); });
test('time and timeEnd', function() { test('time and timeEnd', function() {
var nowStub = sinon.stub(element, 'now').returns(0); var nowStub = sandbox.stub(element, 'now').returns(0);
element.time('foo'); element.time('foo');
nowStub.returns(1); nowStub.returns(1);
element.time('bar'); element.time('bar');
@@ -99,7 +99,7 @@ limitations under the License.
test('pluginsLoaded reports time', function() { test('pluginsLoaded reports time', function() {
Gerrit._arePluginsLoaded.returns(true); Gerrit._arePluginsLoaded.returns(true);
var nowStub = sinon.stub(element, 'now').returns(42); sandbox.stub(element, 'now').returns(42);
element.pluginsLoaded(); element.pluginsLoaded();
assert.isTrue(element.defaultReporter.calledWithExactly( assert.isTrue(element.defaultReporter.calledWithExactly(
'timing-report', 'UI Latency', 'PluginsLoaded', 42 'timing-report', 'UI Latency', 'PluginsLoaded', 42

View File

@@ -69,7 +69,6 @@
GrDiffBuilderSideBySide.prototype._getNextContentOnSide = function( GrDiffBuilderSideBySide.prototype._getNextContentOnSide = function(
content, side) { content, side) {
var tr = content.parentElement.parentElement; var tr = content.parentElement.parentElement;
var content;
while (tr = tr.nextSibling) { while (tr = tr.nextSibling) {
content = tr.querySelector( content = tr.querySelector(
'td.content .contentText[data-side="' + side + '"]'); 'td.content .contentText[data-side="' + side + '"]');

View File

@@ -62,7 +62,6 @@
GrDiffBuilderUnified.prototype._getNextContentOnSide = function( GrDiffBuilderUnified.prototype._getNextContentOnSide = function(
content, side) { content, side) {
var tr = content.parentElement.parentElement; var tr = content.parentElement.parentElement;
var content;
while (tr = tr.nextSibling) { while (tr = tr.nextSibling) {
if (tr.classList.contains('both') || ( if (tr.classList.contains('both') || (
(side === 'left' && tr.classList.contains('remove')) || (side === 'left' && tr.classList.contains('remove')) ||

View File

@@ -234,10 +234,6 @@ limitations under the License.
}); });
test('collapsible drafts', function() { test('collapsible drafts', function() {
element.addEventListener('reply', function(e) {
assert.ok(e.detail.comment);
done();
});
assert.isTrue(element.collapsed); assert.isTrue(element.collapsed);
assert.isFalse(isVisible(element.$$('gr-linked-text')), assert.isFalse(isVisible(element.$$('gr-linked-text')),
'gr-linked-text is not visible'); 'gr-linked-text is not visible');

View File

@@ -489,6 +489,7 @@ limitations under the License.
resolvePrefs({diff_view: 'UNIFIED'}); resolvePrefs({diff_view: 'UNIFIED'});
flushAsynchronousOperations(); flushAsynchronousOperations();
assert.equal(select.value, 'SIDE_BY_SIDE'); assert.equal(select.value, 'SIDE_BY_SIDE');
getPreferencesStub.restore();
}); });
test('unified view is always default on small screens', function() { test('unified view is always default on small screens', function() {
@@ -522,6 +523,7 @@ limitations under the License.
// On small screens, unified should override user perferences // On small screens, unified should override user perferences
assert.equal(select.value, 'UNIFIED_DIFF'); assert.equal(select.value, 'UNIFIED_DIFF');
getPreferencesStub.restore();
}); });
test('_loadHash', function() { test('_loadHash', function() {

View File

@@ -493,6 +493,7 @@ limitations under the License.
}); });
var spy = sinon.spy(element, '_handleShowDiff'); var spy = sinon.spy(element, '_handleShowDiff');
element.set('expanded', true); element.set('expanded', true);
assert.isTrue(spy.called);
}); });
}); });
}); });

View File

@@ -173,9 +173,6 @@ limitations under the License.
line.beforeNumber = 36; line.beforeNumber = 36;
el.setAttribute('data-side', 'right'); el.setAttribute('data-side', 'right');
var expectedStart = 6;
var expectedLength = line.text.length - expectedStart;
element.annotate(el, line); element.annotate(el, line);
assert.isFalse(annotateElementStub.called); assert.isFalse(annotateElementStub.called);

View File

@@ -47,7 +47,6 @@
'text/x-yaml': 'yaml', 'text/x-yaml': 'yaml',
}; };
var ASYNC_DELAY = 10; var ASYNC_DELAY = 10;
var HLJS_PATH = 'bower_components/highlightjs/highlight.min.js';
var CLASS_WHITELIST = { var CLASS_WHITELIST = {
'gr-diff gr-syntax gr-syntax-literal': true, 'gr-diff gr-syntax gr-syntax-literal': true,
@@ -278,8 +277,8 @@
* @param {!Object} state The processing state for the layer. * @param {!Object} state The processing state for the layer.
*/ */
_processNextLine: function(state) { _processNextLine: function(state) {
var baseLine = undefined; var baseLine;
var revisionLine = undefined; var revisionLine;
var section = this.diff.content[state.sectionIndex]; var section = this.diff.content[state.sectionIndex];
if (section.ab) { if (section.ab) {

View File

@@ -311,7 +311,7 @@ limitations under the License.
text: function() { return Promise.resolve(')]}\'{}'); } text: function() { return Promise.resolve(')]}\'{}'); }
}, },
]; ];
var fetchStub = sandbox.stub(window, 'fetch', function(url) { sandbox.stub(window, 'fetch', function(url) {
if (url === '/accounts/self/detail') { if (url === '/accounts/self/detail') {
return Promise.resolve(responses.shift()); return Promise.resolve(responses.shift());
} }