1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Enable auto-formatting of the entire code-base using Prettier (issue 11444)

Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).

Prettier is being used for a couple of reasons:

 - To be consistent with `mozilla-central`, where Prettier is already in use across the tree.

 - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.

Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.

*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.

(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
This commit is contained in:
Jonas Jenwald 2019-12-25 15:59:37 +01:00
parent 8ec1dfde49
commit de36b2aaba
205 changed files with 40024 additions and 31859 deletions

View file

@ -13,39 +13,40 @@
* limitations under the License.
*/
'use strict';
"use strict";
if (!pdfjsImageDecoders.JpegImage) {
alert('Please build the pdfjs-dist library using `gulp dist-install`');
alert("Please build the pdfjs-dist library using `gulp dist-install`");
}
var JPEG_IMAGE = 'fish.jpg';
var JPEG_IMAGE = "fish.jpg";
var jpegCanvas = document.getElementById('jpegCanvas');
var jpegCtx = jpegCanvas.getContext('2d');
var jpegCanvas = document.getElementById("jpegCanvas");
var jpegCtx = jpegCanvas.getContext("2d");
// Load the image data, and convert it to a Uint8Array.
//
var nonBinaryRequest = false;
var request = new XMLHttpRequest();
request.open('GET', JPEG_IMAGE, false);
request.open("GET", JPEG_IMAGE, false);
try {
request.responseType = 'arraybuffer';
nonBinaryRequest = request.responseType !== 'arraybuffer';
request.responseType = "arraybuffer";
nonBinaryRequest = request.responseType !== "arraybuffer";
} catch (e) {
nonBinaryRequest = true;
}
if (nonBinaryRequest && request.overrideMimeType) {
request.overrideMimeType('text/plain; charset=x-user-defined');
request.overrideMimeType("text/plain; charset=x-user-defined");
}
request.send(null);
var typedArrayImage;
if (nonBinaryRequest) {
var str = request.responseText, length = str.length;
var str = request.responseText,
length = str.length;
var bytes = new Uint8Array(length);
for (var i = 0; i < length; ++i) {
bytes[i] = str.charCodeAt(i) & 0xFF;
bytes[i] = str.charCodeAt(i) & 0xff;
}
typedArrayImage = bytes;
} else {
@ -57,7 +58,8 @@ if (nonBinaryRequest) {
var jpegImage = new pdfjsImageDecoders.JpegImage();
jpegImage.parse(typedArrayImage);
var width = jpegImage.width, height = jpegImage.height;
var width = jpegImage.width,
height = jpegImage.height;
var jpegData = jpegImage.getData({
width: width,
height: height,
@ -68,7 +70,7 @@ var jpegData = jpegImage.getData({
//
var imageData = jpegCtx.createImageData(width, height);
var imageBytes = imageData.data;
for (var j = 0, k = 0, jj = width * height * 4; j < jj;) {
for (var j = 0, k = 0, jj = width * height * 4; j < jj; ) {
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = jpegData[k++];