From 73e94b84a08a1de168e2e94d3e1fec45f3276223 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 28 Apr 2017 13:40:47 +0200 Subject: [PATCH] Enable the `object-shorthand` ESLint rule Please see http://eslint.org/docs/rules/object-shorthand. Unfortunately, based on commit https://github.com/mozilla/pdf.js/commit/9276d1dcd97b4b0dc45342608a7f1b1a7f1e9c5b, it seems that we still need to maintain compatibility with old Node.js versions, hence certain files/directories that are executed in Node.js are currently exempt from this rule. Furthermore, since the files specific to the Chromium extension are not run through Babel, the `/extensions/chromium/` directory is also exempt from this rule. --- .eslintrc | 2 +- extensions/chromium/.eslintrc | 4 ++++ external/.eslintrc | 4 ++++ gulpfile.js | 1 + test/chromium/test-telemetry.js | 1 + test/downloadutils.js | 1 + test/driver.js | 36 ++++++++++++++++----------------- test/font/jasmine-boot.js | 20 +++++++++--------- test/test.js | 1 + test/unit/annotation_spec.js | 26 ++++++++++++------------ test/unit/api_spec.js | 18 ++++++++--------- test/unit/cmap_spec.js | 12 +++++------ test/unit/evaluator_spec.js | 10 ++++----- test/unit/fonts_spec.js | 4 ++-- test/unit/function_spec.js | 4 ++-- test/unit/jasmine-boot.js | 20 +++++++++--------- test/unit/primitives_spec.js | 8 ++++---- test/unit/stream_spec.js | 4 ++-- test/unit/testreporter.js | 6 +++--- test/webbrowser.js | 1 + test/webserver.js | 1 + 21 files changed, 99 insertions(+), 85 deletions(-) diff --git a/.eslintrc b/.eslintrc index f59deaa13977e..a6baa9e66b990 100644 --- a/.eslintrc +++ b/.eslintrc @@ -154,7 +154,7 @@ "no-useless-computed-key": "error", "no-useless-constructor": "error", "no-useless-rename": "error", - "object-shorthand": ["off", "always", { + "object-shorthand": ["error", "always", { "avoidQuotes": true, }], "rest-spread-spacing": ["error", "never"], diff --git a/extensions/chromium/.eslintrc b/extensions/chromium/.eslintrc index c3e4625482e90..bbeb5c495aea6 100644 --- a/extensions/chromium/.eslintrc +++ b/extensions/chromium/.eslintrc @@ -6,4 +6,8 @@ "parserOptions": { "sourceType": "script" }, + + "rules": { + "object-shorthand": "off", + }, } diff --git a/external/.eslintrc b/external/.eslintrc index 3692bbae957b3..b60ef2b5e05dd 100644 --- a/external/.eslintrc +++ b/external/.eslintrc @@ -7,4 +7,8 @@ "node": true, "shelljs": true, }, + + "rules": { + "object-shorthand": "off", + }, } diff --git a/gulpfile.js b/gulpfile.js index 1edd8d963b6de..61de724c92e3a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ * limitations under the License. */ /* eslint-env node */ +/* eslint-disable object-shorthand */ /* globals target */ 'use strict'; diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js index 5f846ca55c493..987533df83a64 100755 --- a/test/chromium/test-telemetry.js +++ b/test/chromium/test-telemetry.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable object-shorthand */ 'use strict'; diff --git a/test/downloadutils.js b/test/downloadutils.js index 10e8f4e71679a..9e6a90b955dbc 100644 --- a/test/downloadutils.js +++ b/test/downloadutils.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable object-shorthand */ 'use strict'; diff --git a/test/driver.js b/test/driver.js index 5bad1fee6ae30..196e54cc31a92 100644 --- a/test/driver.js +++ b/test/driver.js @@ -32,23 +32,23 @@ var LinkServiceMock = (function LinkServiceMockClosure() { set page(value) {}, - navigateTo: function (dest) {}, + navigateTo(dest) {}, - getDestinationHash: function (dest) { + getDestinationHash(dest) { return '#'; }, - getAnchorUrl: function (hash) { + getAnchorUrl(hash) { return '#'; }, - setHash: function (hash) {}, + setHash(hash) {}, - executeNamedAction: function (action) {}, + executeNamedAction(action) {}, - onFileAttachmentAnnotation: function (params) {}, + onFileAttachmentAnnotation(params) {}, - cachePageRef: function (pageNum, pageRef) {}, + cachePageRef(pageNum, pageRef) {}, }; return LinkServiceMock; @@ -101,10 +101,10 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() { // Rendering text layer as HTML. var task = PDFJS.renderTextLayer({ - textContent: textContent, + textContent, container: div, - viewport: viewport, - enhanceTextSelection: enhanceTextSelection, + viewport, + enhanceTextSelection, }); Promise.all([stylePromise, task.promise]).then(function (results) { task.expandTextDivs(true); @@ -200,11 +200,11 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() { var annotation_viewport = viewport.clone({ dontFlip: true }); var parameters = { viewport: annotation_viewport, - div: div, - annotations: annotations, - page: page, + div, + annotations, + page, linkService: new LinkServiceMock(), - renderInteractiveForms: renderInteractiveForms, + renderInteractiveForms, }; PDFJS.AnnotationLayer.render(parameters); @@ -527,7 +527,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars var renderContext = { canvasContext: ctx, - viewport: viewport, + viewport, renderInteractiveForms: renderForms, }; var completeRender = (function(error) { @@ -605,7 +605,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars _info: function Driver_info(message) { this._send('/info', JSON.stringify({ browser: this.browser, - message: message + message, })); }, @@ -641,11 +641,11 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars numPages: task.pdfDoc ? (task.lastPage || task.pdfDoc.numPages) : 0, lastPageNum: this._getLastPageNumber(task), - failure: failure, + failure, file: task.file, round: task.round, page: task.pageNum, - snapshot: snapshot, + snapshot, stats: task.stats.times }); this._send('/submit_task_results', result, callback); diff --git a/test/font/jasmine-boot.js b/test/font/jasmine-boot.js index 50a0e8f41912f..4be550fb67b5f 100644 --- a/test/font/jasmine-boot.js +++ b/test/font/jasmine-boot.js @@ -71,7 +71,7 @@ function initializePDFJS(callback) { // Runner Parameters var queryString = new jasmine.QueryString({ - getWindowLocation: function() { + getWindowLocation() { return window.location; } }); @@ -93,27 +93,27 @@ function initializePDFJS(callback) { // Reporters var htmlReporter = new jasmine.HtmlReporter({ - env: env, - onRaiseExceptionsClick: function() { + env, + onRaiseExceptionsClick() { queryString.navigateWithNewParam('catch', !env.catchingExceptions()); }, - onThrowExpectationsClick: function() { + onThrowExpectationsClick() { queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures()); }, - onRandomClick: function() { + onRandomClick() { queryString.navigateWithNewParam('random', !env.randomTests()); }, - addToExistingQueryString: function(key, value) { + addToExistingQueryString(key, value) { return queryString.fullStringWithNewParam(key, value); }, - getContainer: function() { + getContainer() { return document.body; }, - createElement: function() { + createElement() { return document.createElement.apply(document, arguments); }, - createTextNode: function() { + createTextNode() { return document.createTextNode.apply(document, arguments); }, timer: new jasmine.Timer() @@ -130,7 +130,7 @@ function initializePDFJS(callback) { // Filter which specs will be run by matching the start of the full name // against the `spec` query param. var specFilter = new jasmine.HtmlSpecFilter({ - filterString: function() { + filterString() { return queryString.getParam('spec'); } }); diff --git a/test/test.js b/test/test.js index 2dcdeeec1e59a..ff026f269285f 100644 --- a/test/test.js +++ b/test/test.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable object-shorthand */ 'use strict'; diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 3626ad0862a3f..55cfffdfcd11a 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -34,10 +34,10 @@ describe('annotation', function() { } } XRefMock.prototype = { - fetch: function (ref) { + fetch(ref) { return this.map[ref.toString()]; }, - fetchIfRef: function (obj) { + fetchIfRef(obj) { if (!isRef(obj)) { return obj; } @@ -56,7 +56,7 @@ describe('annotation', function() { obj: params.startObjId || 0, }; return { - createObjId: function () { + createObjId() { return uniquePrefix + (++idCounters.obj); }, }; @@ -153,7 +153,7 @@ describe('annotation', function() { }); it('should set and get flags', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setFlags(13); expect(annotation.hasFlag(AnnotationFlag.INVISIBLE)).toEqual(true); @@ -163,63 +163,63 @@ describe('annotation', function() { }); it('should be viewable and not printable by default', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); expect(annotation.viewable).toEqual(true); expect(annotation.printable).toEqual(false); }); it('should set and get a valid rectangle', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setRectangle([117, 694, 164.298, 720]); expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]); }); it('should not set and get an invalid rectangle', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setRectangle([117, 694, 164.298]); expect(annotation.rectangle).toEqual([0, 0, 0, 0]); }); it('should reject a color if it is not an array', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setColor('red'); expect(annotation.color).toEqual(new Uint8Array([0, 0, 0])); }); it('should set and get a transparent color', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setColor([]); expect(annotation.color).toEqual(null); }); it('should set and get a grayscale color', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setColor([0.4]); expect(annotation.color).toEqual(new Uint8Array([102, 102, 102])); }); it('should set and get an RGB color', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setColor([0, 0, 1]); expect(annotation.color).toEqual(new Uint8Array([0, 0, 255])); }); it('should set and get a CMYK color', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setColor([0.1, 0.92, 0.84, 0.02]); expect(annotation.color).toEqual(new Uint8Array([233, 59, 47])); }); it('should not set and get an invalid color', function() { - var annotation = new Annotation({ dict: dict, ref: ref }); + var annotation = new Annotation({ dict, ref, }); annotation.setColor([0.4, 0.6]); expect(annotation.color).toEqual(new Uint8Array([0, 0, 0])); diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 22ebd04b2ed34..76adbc04eaeb6 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -216,7 +216,7 @@ describe('api', function() { var url = new URL('../pdfs/pr6531_2.pdf', window.location).href; var passwordNeededLoadingTask = PDFJS.getDocument({ - url: url, password: '', + url, password: '', }); var result1 = passwordNeededLoadingTask.promise.then(function () { done.fail('shall fail with no password'); @@ -228,7 +228,7 @@ describe('api', function() { }); var passwordIncorrectLoadingTask = PDFJS.getDocument({ - url: url, password: 'qwerty', + url, password: 'qwerty', }); var result2 = passwordIncorrectLoadingTask.promise.then(function () { done.fail('shall fail with wrong password'); @@ -240,7 +240,7 @@ describe('api', function() { }); var passwordAcceptedLoadingTask = PDFJS.getDocument({ - url: url, password: 'asdfasdf', + url, password: 'asdfasdf', }); var result3 = passwordAcceptedLoadingTask.promise.then(function (data) { @@ -259,7 +259,7 @@ describe('api', function() { var url = new URL('../pdfs/issue3371.pdf', window.location).href; var passwordNeededLoadingTask = PDFJS.getDocument(url); var passwordIncorrectLoadingTask = PDFJS.getDocument({ - url: url, password: 'qwerty', + url, password: 'qwerty', }); passwordNeededLoadingTask.onPassword = function (callback, reason) { @@ -342,7 +342,7 @@ describe('api', function() { }); it('worker created and can be used in getDocument', function (done) { var worker = new PDFJS.PDFWorker('test1'); - var loadingTask = PDFJS.getDocument({url: basicApiUrl, worker: worker}); + var loadingTask = PDFJS.getDocument({ url: basicApiUrl, worker, }); loadingTask.promise.then(function () { var docWorker = loadingTask._worker; expect(!!docWorker).toEqual(false); @@ -893,7 +893,7 @@ describe('api', function() { }); var docBaseUrlLoadingTask = PDFJS.getDocument({ - url: url, + url, docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf', }); var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then( @@ -904,7 +904,7 @@ describe('api', function() { }); var invalidDocBaseUrlLoadingTask = PDFJS.getDocument({ - url: url, + url, docBaseUrl: 'qwerty.pdf', }); var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then( @@ -1001,7 +1001,7 @@ describe('api', function() { var renderTask = page.render({ canvasContext: canvasAndCtx.context, - viewport: viewport, + viewport, }); renderTask.cancel(); @@ -1041,7 +1041,7 @@ describe('api', function() { viewport.height); return page.render({ canvasContext: canvasAndCtx.context, - viewport: viewport, + viewport, }).then(function() { var data = canvasAndCtx.canvas.toDataURL(); CanvasFactory.destroy(canvasAndCtx); diff --git a/test/unit/cmap_spec.js b/test/unit/cmap_spec.js index 955eab6100cbb..9a0d0364962c6 100644 --- a/test/unit/cmap_spec.js +++ b/test/unit/cmap_spec.js @@ -46,7 +46,7 @@ describe('cmap', function() { fetchBuiltInCMap = function (name) { return CMapReaderFactory.fetch({ - name: name, + name, }); }; done(); @@ -175,7 +175,7 @@ describe('cmap', function() { var stream = new StringStream(str); var cmapPromise = CMapFactory.create({ encoding: stream, - fetchBuiltInCMap: fetchBuiltInCMap, + fetchBuiltInCMap, useCMap: null, }); cmapPromise.then(function (cmap) { @@ -214,7 +214,7 @@ describe('cmap', function() { it('loads built in cmap', function(done) { var cmapPromise = CMapFactory.create({ encoding: Name.get('Adobe-Japan1-1'), - fetchBuiltInCMap: fetchBuiltInCMap, + fetchBuiltInCMap, useCMap: null, }); cmapPromise.then(function (cmap) { @@ -231,7 +231,7 @@ describe('cmap', function() { it('loads built in identity cmap', function(done) { var cmapPromise = CMapFactory.create({ encoding: Name.get('Identity-H'), - fetchBuiltInCMap: fetchBuiltInCMap, + fetchBuiltInCMap, useCMap: null, }); cmapPromise.then(function (cmap) { @@ -250,7 +250,7 @@ describe('cmap', function() { it('attempts to load a non-existent built-in CMap', function(done) { var cmapPromise = CMapFactory.create({ encoding: Name.get('null'), - fetchBuiltInCMap: fetchBuiltInCMap, + fetchBuiltInCMap, useCMap: null, }); cmapPromise.then(function () { @@ -268,7 +268,7 @@ describe('cmap', function() { var CMapReaderFactory = isNodeJS() ? new NodeCMapReaderFactory({ }) : new DOMCMapReaderFactory({ }); return CMapReaderFactory.fetch({ - name: name, + name, }); } diff --git a/test/unit/evaluator_spec.js b/test/unit/evaluator_spec.js index 58bb6733adc0c..820f121d38112 100644 --- a/test/unit/evaluator_spec.js +++ b/test/unit/evaluator_spec.js @@ -24,7 +24,7 @@ describe('evaluator', function() { this.queue = queue || []; } XrefMock.prototype = { - fetchIfRef: function() { + fetchIfRef() { return this.queue.shift(); } }; @@ -32,13 +32,13 @@ describe('evaluator', function() { this.inputs = []; } HandlerMock.prototype = { - send: function(name, data) { - this.inputs.push({name: name, data: data}); + send(name, data) { + this.inputs.push({ name, data, }); } }; function ResourcesMock() { } ResourcesMock.prototype = { - get: function(name) { + get(name) { return this[name]; } }; @@ -319,7 +319,7 @@ describe('evaluator', function() { describe('operator list', function () { function MessageHandlerMock() { } MessageHandlerMock.prototype = { - send: function () { }, + send() { }, }; it('should get correct total length after flushing', function () { diff --git a/test/unit/fonts_spec.js b/test/unit/fonts_spec.js index 730f87f58aab7..c5e6e858e47fd 100644 --- a/test/unit/fonts_spec.js +++ b/test/unit/fonts_spec.js @@ -76,8 +76,8 @@ var checkProblematicCharRanges = function checkProblematicCharRanges() { throw new Error('Total number of chars must not exceed the PUA length.'); } return { - numChars: numChars, - puaLength: puaLength, + numChars, + puaLength, percentage: 100 * (numChars / puaLength), }; }; diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js index 4c0d1644b3533..602e167abfb27 100644 --- a/test/unit/function_spec.js +++ b/test/unit/function_spec.js @@ -23,9 +23,9 @@ import { StringStream } from '../../src/core/stream'; describe('function', function() { beforeEach(function() { jasmine.addMatchers({ - toMatchArray: function(util, customEqualityTesters) { + toMatchArray(util, customEqualityTesters) { return { - compare: function (actual, expected) { + compare(actual, expected) { var result = {}; if (actual.length !== expected.length) { result.pass = false; diff --git a/test/unit/jasmine-boot.js b/test/unit/jasmine-boot.js index 94da82b5a9284..83e4b51a70b0c 100644 --- a/test/unit/jasmine-boot.js +++ b/test/unit/jasmine-boot.js @@ -79,7 +79,7 @@ function initializePDFJS(callback) { // Runner Parameters var queryString = new jasmine.QueryString({ - getWindowLocation: function() { + getWindowLocation() { return window.location; } }); @@ -101,27 +101,27 @@ function initializePDFJS(callback) { // Reporters var htmlReporter = new jasmine.HtmlReporter({ - env: env, - onRaiseExceptionsClick: function() { + env, + onRaiseExceptionsClick() { queryString.navigateWithNewParam('catch', !env.catchingExceptions()); }, - onThrowExpectationsClick: function() { + onThrowExpectationsClick() { queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures()); }, - onRandomClick: function() { + onRandomClick() { queryString.navigateWithNewParam('random', !env.randomTests()); }, - addToExistingQueryString: function(key, value) { + addToExistingQueryString(key, value) { return queryString.fullStringWithNewParam(key, value); }, - getContainer: function() { + getContainer() { return document.body; }, - createElement: function() { + createElement() { return document.createElement.apply(document, arguments); }, - createTextNode: function() { + createTextNode() { return document.createTextNode.apply(document, arguments); }, timer: new jasmine.Timer() @@ -138,7 +138,7 @@ function initializePDFJS(callback) { // Filter which specs will be run by matching the start of the full name // against the `spec` query param. var specFilter = new jasmine.HtmlSpecFilter({ - filterString: function() { + filterString() { return queryString.getParam('spec'); } }); diff --git a/test/unit/primitives_spec.js b/test/unit/primitives_spec.js index b5a65914fb3a0..9090ce173cf40 100644 --- a/test/unit/primitives_spec.js +++ b/test/unit/primitives_spec.js @@ -27,19 +27,19 @@ describe('primitives', function() { } } XRefMock.prototype = { - fetch: function (ref) { + fetch(ref) { return this.map[ref.toString()]; }, - fetchIfRef: function (obj) { + fetchIfRef(obj) { if (!isRef(obj)) { return obj; } return this.fetch(obj); }, - fetchAsync: function (ref) { + fetchAsync(ref) { return Promise.resolve(this.fetch(ref)); }, - fetchIfRefAsync: function (obj) { + fetchIfRefAsync(obj) { return Promise.resolve(this.fetchIfRef(obj)); }, }; diff --git a/test/unit/stream_spec.js b/test/unit/stream_spec.js index ca90709246651..dbbe7f2ac28f3 100644 --- a/test/unit/stream_spec.js +++ b/test/unit/stream_spec.js @@ -19,9 +19,9 @@ import { Dict } from '../../src/core/primitives'; describe('stream', function() { beforeEach(function() { jasmine.addMatchers({ - toMatchTypedArray: function(util, customEqualityTesters) { + toMatchTypedArray(util, customEqualityTesters) { return { - compare: function (actual, expected) { + compare(actual, expected) { var result = {}; if (actual.length !== expected.length) { result.pass = false; diff --git a/test/unit/testreporter.js b/test/unit/testreporter.js index c2b3bd6ee862c..2b99d3fc9e71f 100644 --- a/test/unit/testreporter.js +++ b/test/unit/testreporter.js @@ -24,13 +24,13 @@ var TestReporter = function(browser, appPath) { } function sendInfo(message) { - send('/info', {message: message}); + send('/info', { message, }); } function sendResult(status, description, error) { var message = { - status: status, - description: description + status, + description, }; if (typeof error !== 'undefined') { message['error'] = error; diff --git a/test/webbrowser.js b/test/webbrowser.js index 4cb1b4d1bfe7e..465f44f59430f 100644 --- a/test/webbrowser.js +++ b/test/webbrowser.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable object-shorthand */ 'use strict'; diff --git a/test/webserver.js b/test/webserver.js index 8f72760f8656f..4ae9baea0e43f 100644 --- a/test/webserver.js +++ b/test/webserver.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable object-shorthand */ 'use strict';