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

@ -14,7 +14,7 @@
*/
/* uses XRef */
import { assert } from '../shared/util';
import { assert } from "../shared/util";
var EOF = {};
@ -29,7 +29,7 @@ var Name = (function NameClosure() {
Name.get = function Name_get(name) {
var nameValue = nameCache[name];
return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
return nameValue ? nameValue : (nameCache[name] = new Name(name));
};
Name._clearCache = function() {
@ -50,7 +50,7 @@ var Cmd = (function CmdClosure() {
Cmd.get = function Cmd_get(cmd) {
var cmdValue = cmdCache[cmd];
return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
return cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd));
};
Cmd._clearCache = function() {
@ -193,9 +193,9 @@ var Ref = (function RefClosure() {
};
Ref.get = function(num, gen) {
const key = (gen === 0 ? `${num}R` : `${num}R${gen}`);
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
const refValue = refCache[key];
return (refValue ? refValue : (refCache[key] = new Ref(num, gen)));
return refValue ? refValue : (refCache[key] = new Ref(num, gen));
};
Ref._clearCache = function() {
@ -266,7 +266,7 @@ var RefSetCache = (function RefSetCacheClosure() {
})();
function isEOF(v) {
return (v === EOF);
return v === EOF;
}
function isName(v, name) {
@ -278,8 +278,9 @@ function isCmd(v, cmd) {
}
function isDict(v, type) {
return v instanceof Dict &&
(type === undefined || isName(v.get('Type'), type));
return (
v instanceof Dict && (type === undefined || isName(v.get("Type"), type))
);
}
function isRef(v) {
@ -287,16 +288,20 @@ function isRef(v) {
}
function isRefsEqual(v1, v2) {
if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || TESTING')) {
assert(v1 instanceof Ref && v2 instanceof Ref,
'isRefsEqual: Both parameters should be `Ref`s.');
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(
v1 instanceof Ref && v2 instanceof Ref,
"isRefsEqual: Both parameters should be `Ref`s."
);
}
return v1.num === v2.num && v1.gen === v2.gen;
}
function isStream(v) {
return typeof v === 'object' && v !== null && v.getBytes !== undefined;
return typeof v === "object" && v !== null && v.getBytes !== undefined;
}
function clearPrimitiveCaches() {