Adjust the brace-style ESLint rule to disallow single lines (and also enable no-iterator)

See http://eslint.org/docs/rules/brace-style.
Having the opening/closing braces on the same line can often make the code slightly more difficult to read, in particular for `if`/`else if` statements, compared to using new lines.

This patch also, for consistency with `mozilla-central`, enables the [`no-iterator`](http://eslint.org/docs/rules/no-iterator) rule. Note that this rule didn't require a single code change.
This commit is contained in:
Jonas Jenwald 2017-02-03 12:58:08 +01:00
parent 92e5fb099e
commit bc736fdc7d
18 changed files with 129 additions and 46 deletions

View File

@ -56,6 +56,7 @@
"no-floating-decimal": "error", "no-floating-decimal": "error",
"no-global-assign": "error", "no-global-assign": "error",
"no-implied-eval": "error", "no-implied-eval": "error",
"no-iterator": "error",
"no-lone-blocks": "error", "no-lone-blocks": "error",
"no-multi-spaces": "error", "no-multi-spaces": "error",
"no-multi-str": "error", "no-multi-str": "error",
@ -92,7 +93,9 @@
// Stylistic Issues // Stylistic Issues
"array-bracket-spacing": ["error", "never"], "array-bracket-spacing": ["error", "never"],
"block-spacing": ["error", "always"], "block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true, }], "brace-style": ["error", "1tbs", {
"allowSingleLine": false,
}],
"comma-spacing": ["error", { "before": false, "after": true, }], "comma-spacing": ["error", { "before": false, "after": true, }],
"comma-style": ["error", "last"], "comma-style": ["error", "last"],
"eol-last": "error", "eol-last": "error",
@ -127,7 +130,7 @@
"balanced": true, "balanced": true,
} }
}], }],
},
// ECMAScript 6 // ECMAScript 6
},
} }

View File

@ -125,7 +125,9 @@ function bundle(filename, outfilename, pathPrefix, initFiles, amdName, defines,
// readDependencies returns AMD module names: removing 'pdfjs' prefix and // readDependencies returns AMD module names: removing 'pdfjs' prefix and
// adding '.js' extensions to the name. // adding '.js' extensions to the name.
var umd = require('./external/umdutils/verifier.js'); var umd = require('./external/umdutils/verifier.js');
initFiles = initFiles.map(function (p) { return pathPrefix + p; }); initFiles = initFiles.map(function (p) {
return pathPrefix + p;
});
var files = umd.readDependencies(initFiles).loadOrder.map(function (name) { var files = umd.readDependencies(initFiles).loadOrder.map(function (name) {
return pathPrefix + name.replace(/^[\w\-]+\//, '') + '.js'; return pathPrefix + name.replace(/^[\w\-]+\//, '') + '.js';
}); });
@ -166,7 +168,9 @@ function bundle(filename, outfilename, pathPrefix, initFiles, amdName, defines,
var templateContent = fs.readFileSync(filename).toString(); var templateContent = fs.readFileSync(filename).toString();
templateContent = templateContent.replace( templateContent = templateContent.replace(
/\/\/#expand\s+__BUNDLE__\s*\n/, function (all) { return bundleContent; }); /\/\/#expand\s+__BUNDLE__\s*\n/, function (all) {
return bundleContent;
});
bundleContent = null; bundleContent = null;
templateContent = p2.preprocessPDFJSCode(ctx, templateContent); templateContent = p2.preprocessPDFJSCode(ctx, templateContent);

View File

@ -430,7 +430,9 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
} }
} }
chunksToRequest.sort(function(a, b) { return a - b; }); chunksToRequest.sort(function(a, b) {
return a - b;
});
return this._requestChunks(chunksToRequest); return this._requestChunks(chunksToRequest);
}, },

View File

@ -1010,7 +1010,9 @@ var Font = (function FontClosure() {
var i, ii, j, jj; var i, ii, j, jj;
for (i = ranges.length - 1; i >= 0; --i) { for (i = ranges.length - 1; i >= 0; --i) {
if (ranges[i][0] <= 0xFFFF) { break; } if (ranges[i][0] <= 0xFFFF) {
break;
}
} }
var bmpLength = i + 1; var bmpLength = i + 1;

View File

@ -94,7 +94,9 @@ IPDFStream.prototype = {
* Gets a reader for the entire PDF data. * Gets a reader for the entire PDF data.
* @returns {IPDFStreamReader} * @returns {IPDFStreamReader}
*/ */
getFullReader: function () { return null; }, getFullReader: function () {
return null;
},
/** /**
* Gets a reader for the range of the PDF data. * Gets a reader for the range of the PDF data.
@ -102,7 +104,9 @@ IPDFStream.prototype = {
* @param {number} end - the end offset of the data. * @param {number} end - the end offset of the data.
* @returns {IPDFStreamRangeReader} * @returns {IPDFStreamRangeReader}
*/ */
getRangeReader: function (begin, end) { return null; }, getRangeReader: function (begin, end) {
return null;
},
/** /**
* Cancels all opened reader and closes all their opened requests. * Cancels all opened reader and closes all their opened requests.
@ -123,14 +127,18 @@ IPDFStreamReader.prototype = {
* the PDF data stream are available. * the PDF data stream are available.
* @returns {Promise} * @returns {Promise}
*/ */
get headersReady() { return null; }, get headersReady() {
return null;
},
/** /**
* Gets PDF binary data length. It is defined after the headersReady promise * Gets PDF binary data length. It is defined after the headersReady promise
* is resolved. * is resolved.
* @returns {number} The data length (or 0 if unknown). * @returns {number} The data length (or 0 if unknown).
*/ */
get contentLength() { return 0; }, get contentLength() {
return 0;
},
/** /**
* Gets ability of the stream to handle range requests. It is defined after * Gets ability of the stream to handle range requests. It is defined after
@ -138,14 +146,18 @@ IPDFStreamReader.prototype = {
* or an error occurs. * or an error occurs.
* @returns {boolean} * @returns {boolean}
*/ */
get isRangeSupported() { return false; }, get isRangeSupported() {
return false;
},
/** /**
* Gets ability of the stream to progressively load binary data. It is defined * Gets ability of the stream to progressively load binary data. It is defined
* after the headersReady promise is resolved. * after the headersReady promise is resolved.
* @returns {boolean} * @returns {boolean}
*/ */
get isStreamingSupported() { return false; }, get isStreamingSupported() {
return false;
},
/** /**
* Requests a chunk of the binary data. The method returns the promise, which * Requests a chunk of the binary data. The method returns the promise, which
@ -183,7 +195,9 @@ IPDFStreamRangeReader.prototype = {
* Gets ability of the stream to progressively load binary data. * Gets ability of the stream to progressively load binary data.
* @returns {boolean} * @returns {boolean}
*/ */
get isStreamingSupported() { return false; }, get isStreamingSupported() {
return false;
},
/** /**
* Requests a chunk of the binary data. The method returns the promise, which * Requests a chunk of the binary data. The method returns the promise, which

View File

@ -98,7 +98,9 @@ if (typeof PDFJSDev === 'undefined' ||
return (typeof imageData.data.buffer !== 'undefined'); return (typeof imageData.data.buffer !== 'undefined');
}; };
} else { } else {
hasCanvasTypedArrays = function () { return true; }; hasCanvasTypedArrays = function () {
return true;
};
} }
var LinkTarget = { var LinkTarget = {

View File

@ -68,8 +68,12 @@
} }
delete PDFJS.verbosity; delete PDFJS.verbosity;
Object.defineProperty(PDFJS, 'verbosity', { Object.defineProperty(PDFJS, 'verbosity', {
get: function () { return sharedUtil.getVerbosityLevel(); }, get: function () {
set: function (level) { sharedUtil.setVerbosityLevel(level); }, return sharedUtil.getVerbosityLevel();
},
set: function (level) {
sharedUtil.setVerbosityLevel(level);
},
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });

View File

@ -347,7 +347,9 @@ var renderTextLayer = (function renderTextLayerClosure() {
function expandBoundsLTR(width, bounds) { function expandBoundsLTR(width, bounds) {
// Sorting by x1 coordinate and walk by the bounds in the same order. // Sorting by x1 coordinate and walk by the bounds in the same order.
bounds.sort(function (a, b) { return a.x1 - b.x1 || a.index - b.index; }); bounds.sort(function (a, b) {
return a.x1 - b.x1 || a.index - b.index;
});
// First we see on the horizon is a fake boundary. // First we see on the horizon is a fake boundary.
var fakeBoundary = { var fakeBoundary = {

View File

@ -1193,7 +1193,9 @@ function createPromiseCapability() {
} }
if (typeof globalScope.Promise.resolve !== 'function') { if (typeof globalScope.Promise.resolve !== 'function') {
globalScope.Promise.resolve = function (value) { globalScope.Promise.resolve = function (value) {
return new globalScope.Promise(function (resolve) { resolve(value); }); return new globalScope.Promise(function (resolve) {
resolve(value);
});
}; };
} }
if (typeof globalScope.Promise.reject !== 'function') { if (typeof globalScope.Promise.reject !== 'function') {
@ -1401,7 +1403,9 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
* @returns {Promise} * @returns {Promise}
*/ */
Promise.resolve = function Promise_resolve(value) { Promise.resolve = function Promise_resolve(value) {
return new Promise(function (resolve) { resolve(value); }); return new Promise(function (resolve) {
resolve(value);
});
}; };
/** /**
@ -1410,7 +1414,9 @@ if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) {
* @returns {Promise} * @returns {Promise}
*/ */
Promise.reject = function Promise_reject(reason) { Promise.reject = function Promise_reject(reason) {
return new Promise(function (resolve, reject) { reject(reason); }); return new Promise(function (resolve, reject) {
reject(reason);
});
}; };
Promise.prototype = { Promise.prototype = {

View File

@ -84,7 +84,9 @@ function createExtensionGlobal() {
// Network-related mocks. // Network-related mocks.
window.Request = {}; window.Request = {};
window.Request.prototype = { window.Request.prototype = {
get mode() { throw new TypeError('Illegal invocation'); }, get mode() {
throw new TypeError('Illegal invocation');
},
}; };
window.fetch = function(url, options) { window.fetch = function(url, options) {
assert.equal(url, LOG_URL); assert.equal(url, LOG_URL);
@ -339,7 +341,9 @@ var tests = [
var window = createExtensionGlobal(); var window = createExtensionGlobal();
var didWarn = false; var didWarn = false;
window.console = {}; window.console = {};
window.console.warn = function() { didWarn = true; }; window.console.warn = function() {
didWarn = true;
};
window.chrome.runtime.id = 'abcdefghijklmnopabcdefghijklmnop'; window.chrome.runtime.id = 'abcdefghijklmnopabcdefghijklmnop';
telemetryScript.runInNewContext(window); telemetryScript.runInNewContext(window);
assert.deepEqual(window.test_requests, []); assert.deepEqual(window.test_requests, []);
@ -373,7 +377,9 @@ var tests = [
function test_fetch_mode_not_supported() { function test_fetch_mode_not_supported() {
var window = createExtensionGlobal(); var window = createExtensionGlobal();
delete window.Request.prototype.mode; delete window.Request.prototype.mode;
window.fetch = function() { throw new Error('Unexpected call to fetch!'); }; window.fetch = function() {
throw new Error('Unexpected call to fetch!');
};
telemetryScript.runInNewContext(window); telemetryScript.runInNewContext(window);
assert.deepEqual(window.test_requests, [{ assert.deepEqual(window.test_requests, [{
'Deduplication-Id': '4242424242', 'Deduplication-Id': '4242424242',

View File

@ -67,7 +67,9 @@ function initializePDFJS(callback) {
// Runner Parameters // Runner Parameters
var queryString = new jasmine.QueryString({ var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; } getWindowLocation: function() {
return window.location;
}
}); });
var catchingExceptions = queryString.getParam('catch'); var catchingExceptions = queryString.getParam('catch');
@ -101,7 +103,9 @@ function initializePDFJS(callback) {
addToExistingQueryString: function(key, value) { addToExistingQueryString: function(key, value) {
return queryString.fullStringWithNewParam(key, value); return queryString.fullStringWithNewParam(key, value);
}, },
getContainer: function() { return document.body; }, getContainer: function() {
return document.body;
},
createElement: function() { createElement: function() {
return document.createElement.apply(document, arguments); return document.createElement.apply(document, arguments);
}, },
@ -122,7 +126,9 @@ function initializePDFJS(callback) {
// Filter which specs will be run by matching the start of the full name // Filter which specs will be run by matching the start of the full name
// against the `spec` query param. // against the `spec` query param.
var specFilter = new jasmine.HtmlSpecFilter({ var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() { return queryString.getParam('spec'); } filterString: function() {
return queryString.getParam('spec');
}
}); });
env.specFilter = function(spec) { env.specFilter = function(spec) {

View File

@ -66,7 +66,9 @@ function flatten(stats) {
}); });
// Use only overall results if not grouped by 'stat' // Use only overall results if not grouped by 'stat'
if (options.groupBy.indexOf('stat') < 0) { if (options.groupBy.indexOf('stat') < 0) {
rows = rows.filter(function(s) { return s.stat === 'Overall'; }); rows = rows.filter(function(s) {
return s.stat === 'Overall';
});
} }
return rows; return rows;
} }
@ -129,7 +131,9 @@ function stat(baseline, current) {
} }
var i, row, rows = []; var i, row, rows = [];
// collect rows and measure column widths // collect rows and measure column widths
var width = labels.map(function(s) { return s.length; }); var width = labels.map(function(s) {
return s.length;
});
rows.push(labels); rows.push(labels);
for (var k = 0; k < keys.length; k++) { for (var k = 0; k < keys.length; k++) {
var key = keys[k]; var key = keys[k];
@ -157,7 +161,9 @@ function stat(baseline, current) {
} }
// add horizontal line // add horizontal line
var hline = width.map(function(w) { return new Array(w + 1).join('-'); }); var hline = width.map(function(w) {
return new Array(w + 1).join('-');
});
rows.splice(1, 0, hline); rows.splice(1, 0, hline);
// print output // print output

View File

@ -1092,8 +1092,12 @@ describe('api', function() {
var xhr = new XMLHttpRequest(pdfPath); var xhr = new XMLHttpRequest(pdfPath);
xhr.open('GET', pdfPath); xhr.open('GET', pdfPath);
xhr.responseType = 'arraybuffer'; xhr.responseType = 'arraybuffer';
xhr.onload = function () { resolve(new Uint8Array(xhr.response)); }; xhr.onload = function () {
xhr.onerror = function () { reject(new Error('PDF is not loaded')); }; resolve(new Uint8Array(xhr.response));
};
xhr.onerror = function () {
reject(new Error('PDF is not loaded'));
};
xhr.send(); xhr.send();
}); });
return loadPromise; return loadPromise;

View File

@ -211,8 +211,9 @@ describe('cmap', function() {
expect(cmap instanceof IdentityCMap).toEqual(true); expect(cmap instanceof IdentityCMap).toEqual(true);
expect(cmap.vertical).toEqual(false); expect(cmap.vertical).toEqual(false);
expect(cmap.length).toEqual(0x10000); expect(cmap.length).toEqual(0x10000);
expect(function() { return cmap.isIdentityCMap; }).toThrow( expect(function() {
new Error('should not access .isIdentityCMap')); return cmap.isIdentityCMap;
}).toThrow(new Error('should not access .isIdentityCMap'));
done(); done();
}).catch(function (reason) { }).catch(function (reason) {
done.fail(reason); done.fail(reason);

View File

@ -124,8 +124,9 @@ describe('function', function() {
expect(program).toMatchArray(expectedProgram); expect(program).toMatchArray(expectedProgram);
}); });
it('handles missing brackets', function() { it('handles missing brackets', function() {
expect(function() { parse('{'); }).toThrow( expect(function() {
new Error('Unexpected symbol: found undefined expected 1.')); parse('{');
}).toThrow(new Error('Unexpected symbol: found undefined expected 1.'));
}); });
it('handles junk after the end', function() { it('handles junk after the end', function() {
var number = 3.3; var number = 3.3;

View File

@ -83,7 +83,9 @@ function initializePDFJS(callback) {
// Runner Parameters // Runner Parameters
var queryString = new jasmine.QueryString({ var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; } getWindowLocation: function() {
return window.location;
}
}); });
var catchingExceptions = queryString.getParam('catch'); var catchingExceptions = queryString.getParam('catch');
@ -117,7 +119,9 @@ function initializePDFJS(callback) {
addToExistingQueryString: function(key, value) { addToExistingQueryString: function(key, value) {
return queryString.fullStringWithNewParam(key, value); return queryString.fullStringWithNewParam(key, value);
}, },
getContainer: function() { return document.body; }, getContainer: function() {
return document.body;
},
createElement: function() { createElement: function() {
return document.createElement.apply(document, arguments); return document.createElement.apply(document, arguments);
}, },
@ -138,7 +142,9 @@ function initializePDFJS(callback) {
// Filter which specs will be run by matching the start of the full name // Filter which specs will be run by matching the start of the full name
// against the `spec` query param. // against the `spec` query param.
var specFilter = new jasmine.HtmlSpecFilter({ var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() { return queryString.getParam('spec'); } filterString: function() {
return queryString.getParam('spec');
}
}); });
env.specFilter = function(spec) { env.specFilter = function(spec) {

View File

@ -419,13 +419,19 @@ if (typeof PDFJS === 'undefined') {
} else if (!('bind' in console.log)) { } else if (!('bind' in console.log)) {
// native functions in IE9 might not have bind // native functions in IE9 might not have bind
console.log = (function(fn) { console.log = (function(fn) {
return function(msg) { return fn(msg); }; return function(msg) {
return fn(msg);
};
})(console.log); })(console.log);
console.error = (function(fn) { console.error = (function(fn) {
return function(msg) { return fn(msg); }; return function(msg) {
return fn(msg);
};
})(console.error); })(console.error);
console.warn = (function(fn) { console.warn = (function(fn) {
return function(msg) { return fn(msg); }; return function(msg) {
return fn(msg);
};
})(console.warn); })(console.warn);
} }
})(); })();
@ -606,7 +612,9 @@ if (typeof PDFJS === 'undefined') {
var inputProto = el.constructor.prototype; var inputProto = el.constructor.prototype;
var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type'); var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
Object.defineProperty(inputProto, 'type', { Object.defineProperty(inputProto, 'type', {
get: function () { return typeProperty.get.call(this); }, get: function () {
return typeProperty.get.call(this);
},
set: function (value) { set: function (value) {
typeProperty.set.call(this, value === 'number' ? 'text' : value); typeProperty.set.call(this, value === 'number' ? 'text' : value);
}, },
@ -630,7 +638,9 @@ if (typeof PDFJS === 'undefined') {
var value = readyStateProto.get.call(this); var value = readyStateProto.get.call(this);
return value === 'interactive' ? 'loading' : value; return value === 'interactive' ? 'loading' : value;
}, },
set: function (value) { readyStateProto.set.call(this, value); }, set: function (value) {
readyStateProto.set.call(this, value);
},
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });

View File

@ -387,7 +387,9 @@ var Stepper = (function StepperClosure() {
this.table.appendChild(chunk); this.table.appendChild(chunk);
}, },
getNextBreakPoint: function getNextBreakPoint() { getNextBreakPoint: function getNextBreakPoint() {
this.breakPoints.sort(function(a, b) { return a - b; }); this.breakPoints.sort(function(a, b) {
return a - b;
});
for (var i = 0; i < this.breakPoints.length; i++) { for (var i = 0; i < this.breakPoints.length; i++) {
if (this.breakPoints[i] > this.currentIdx) { if (this.breakPoints[i] > this.currentIdx) {
return this.breakPoints[i]; return this.breakPoints[i];
@ -484,7 +486,9 @@ var Stats = (function Stats() {
wrapper.appendChild(title); wrapper.appendChild(title);
wrapper.appendChild(statsDiv); wrapper.appendChild(statsDiv);
stats.push({ pageNumber: pageNumber, div: wrapper }); stats.push({ pageNumber: pageNumber, div: wrapper });
stats.sort(function(a, b) { return a.pageNumber - b.pageNumber; }); stats.sort(function(a, b) {
return a.pageNumber - b.pageNumber;
});
clear(this.panel); clear(this.panel);
for (var i = 0, ii = stats.length; i < ii; ++i) { for (var i = 0, ii = stats.length; i < ii; ++i) {
this.panel.appendChild(stats[i].div); this.panel.appendChild(stats[i].div);