1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Fix the linting errors, from the Prettier auto-formatting, that ESLint --fix couldn't handle

This patch makes the follow changes:
 - Remove no longer necessary inline `// eslint-disable-...` comments.
 - Fix `// eslint-disable-...` comments that Prettier moved down, thus causing new linting errors.
 - Concatenate strings which now fit on just one line.
 - Fix comments that are now too long.
 - Finally, and most importantly, adjust comments that Prettier moved down, since the new positions often is confusing or outright wrong.
This commit is contained in:
Jonas Jenwald 2019-12-25 20:03:46 +01:00
parent de36b2aaba
commit a63f7ad486
46 changed files with 179 additions and 219 deletions

View file

@ -401,8 +401,8 @@ class IdentityCMap extends CMap {
return 0x10000;
}
// eslint-disable-next-line getter-return
get isIdentityCMap() {
// eslint-disable-line getter-return
unreachable("should not access .isIdentityCMap");
}
}

View file

@ -591,8 +591,7 @@ class PDFDocument {
ch = stream.getByte();
} while (isSpace(ch));
let str = "";
while (ch >= 0x20 && ch <= 0x39) {
// < '9'
while (ch >= /* Space = */ 0x20 && ch <= /* '9' = */ 0x39) {
str += String.fromCharCode(ch);
ch = stream.getByte();
}
@ -622,8 +621,7 @@ class PDFDocument {
const MAX_PDF_VERSION_LENGTH = 12;
let version = "",
ch;
while ((ch = stream.getByte()) > 0x20) {
// Space
while ((ch = stream.getByte()) > /* Space = */ 0x20) {
if (version.length >= MAX_PDF_VERSION_LENGTH) {
break;
}

View file

@ -524,8 +524,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
])
.then(
function() {
// Only add the dependency once we know that the native JPEG decoding
// succeeded, to ensure that rendering will always complete.
// Only add the dependency once we know that the native JPEG
// decoding succeeded, to ensure that rendering will always
// complete.
operatorList.addDependency(objId);
args = [objId, w, h];
@ -755,7 +756,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return translated;
})
.catch(reason => {
// Error in the font data -- sending unsupported feature notification.
// Error in the font data -- sending unsupported feature
// notification.
this.handler.send("UnsupportedFeature", {
featureId: UNSUPPORTED_FEATURES.font,
});
@ -2160,9 +2162,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return;
}
// Use a new `StateManager` to prevent incorrect positioning of
// textItems *after* the Form XObject, since errors in the data
// can otherwise prevent `restore` operators from executing.
// Use a new `StateManager` to prevent incorrect positioning
// of textItems *after* the Form XObject, since errors in the
// data can otherwise prevent `restore` operators from
// executing.
// NOTE: Only an issue when `options.ignoreErrors === true`.
let currentState = stateManager.state.clone();
let xObjStateManager = new StateManager(currentState);

View file

@ -929,9 +929,8 @@ var Font = (function FontClosure() {
return true;
}
// ... obviously some fonts violate that part of the specification,
// please refer to the comment in |Type1Font| below.
// please refer to the comment in |Type1Font| below (pfb file header).
if (header[0] === 0x80 && header[1] === 0x01) {
// pfb file header.
return true;
}
return false;
@ -1085,7 +1084,6 @@ var Font = (function FontClosure() {
var ranges = [];
var length = codes.length;
for (var n = 0; n < length; ) {
// eslint-disable-line space-in-parens
var start = codes[n].fontCharCode;
var codeIndices = [codes[n].glyphId];
++n;

View file

@ -142,7 +142,7 @@ var PDFImage = (function PDFImageClosure() {
}
if (width < 1 || height < 1) {
throw new FormatError(
`Invalid image width: ${width} or ` + `height: ${height}`
`Invalid image width: ${width} or height: ${height}`
);
}
this.width = width;
@ -617,11 +617,11 @@ var PDFImage = (function PDFImageClosure() {
var drawWidth = this.drawWidth;
var drawHeight = this.drawHeight;
var imgData = {
// other fields are filled in below
width: drawWidth,
height: drawHeight,
kind: 0,
data: null,
// Other fields are filled in below.
};
var numComps = this.numComps;

View file

@ -31,8 +31,8 @@ let JpegStream = (function JpegStreamClosure() {
// Note: this seems to mainly affect inline images.
let ch;
while ((ch = stream.getByte()) !== -1) {
// Find the first byte of the SOI marker (0xFFD8).
if (ch === 0xff) {
// Find the first byte of the SOI marker (0xFFD8).
stream.skip(-1); // Reset the stream position to the SOI.
break;
}

View file

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-multi-spaces */
import { assert, BaseException, warn } from "../shared/util";
@ -149,7 +148,6 @@ var JpegImage = (function JpegImageClosure() {
var nextByte = data[offset++];
if (nextByte) {
if (nextByte === 0xdc && parseDNLMarker) {
// DNL == 0xFFDC
offset += 2; // Skip data length.
const scanLines = (data[offset++] << 8) | data[offset++];
if (scanLines > 0 && scanLines !== frame.scanLines) {
@ -159,7 +157,6 @@ var JpegImage = (function JpegImageClosure() {
);
}
} else if (nextByte === 0xd9) {
// EOI == 0xFFD9
throw new EOIMarkerError(
"Found EOI marker (0xFFD9) while parsing scan data"
);
@ -746,14 +743,12 @@ var JpegImage = (function JpegImageClosure() {
var huffmanTablesAC = [],
huffmanTablesDC = [];
var fileMarker = readUint16();
if (fileMarker !== 0xffd8) {
// SOI (Start of Image)
if (fileMarker !== /* SOI (Start of Image) = */ 0xffd8) {
throw new JpegError("SOI not found");
}
fileMarker = readUint16();
markerLoop: while (fileMarker !== 0xffd9) {
// EOI (End of image)
markerLoop: while (fileMarker !== /* EOI (End of Image) = */ 0xffd9) {
var i, j, l;
switch (fileMarker) {
case 0xffe0: // APP0 (Application Specific)
@ -776,6 +771,7 @@ var JpegImage = (function JpegImageClosure() {
var appData = readDataBlock();
if (fileMarker === 0xffe0) {
// 'JFIF\x00'
if (
appData[0] === 0x4a &&
appData[1] === 0x46 &&
@ -783,7 +779,6 @@ var JpegImage = (function JpegImageClosure() {
appData[3] === 0x46 &&
appData[4] === 0
) {
// 'JFIF\x00'
jfif = {
version: { major: appData[5], minor: appData[6] },
densityUnits: appData[7],
@ -800,6 +795,7 @@ var JpegImage = (function JpegImageClosure() {
}
// TODO APP1 - Exif
if (fileMarker === 0xffee) {
// 'Adobe'
if (
appData[0] === 0x41 &&
appData[1] === 0x64 &&
@ -807,7 +803,6 @@ var JpegImage = (function JpegImageClosure() {
appData[3] === 0x62 &&
appData[4] === 0x65
) {
// 'Adobe'
adobe = {
version: (appData[5] << 8) | appData[6],
flags0: (appData[7] << 8) | appData[8],

View file

@ -404,7 +404,7 @@ var JpxImage = (function JpxImageClosure() {
break;
case 0xff53: // Coding style component (COC)
throw new Error(
"Codestream code 0xFF53 (COC) is " + "not implemented"
"Codestream code 0xFF53 (COC) is not implemented"
);
default:
throw new Error("Unknown codestream code: " + code.toString(16));

View file

@ -813,12 +813,13 @@ const specialChars = [
];
function toHexDigit(ch) {
if (ch >= 0x30 && ch <= 0x39) {
// '0'-'9'
if (ch >= /* '0' = */ 0x30 && ch /* '9' = */ <= 0x39) {
return ch & 0x0f;
}
if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
// 'A'-'F', 'a'-'f'
if (
(ch >= /* 'A' = */ 0x41 && ch <= /* 'F' = */ 0x46) ||
(ch >= /* 'a' = */ 0x61 && ch <= /* 'f' = */ 0x66)
) {
return (ch & 0x0f) + 9;
}
return -1;
@ -862,35 +863,29 @@ class Lexer {
let divideBy = 0; // Different from 0 if it's a floating point value.
let sign = 0;
if (ch === 0x2d) {
// '-'
if (ch === /* '-' = */ 0x2d) {
sign = -1;
ch = this.nextChar();
if (ch === 0x2d) {
// '-'
if (ch === /* '-' = */ 0x2d) {
// Ignore double negative (this is consistent with Adobe Reader).
ch = this.nextChar();
}
} else if (ch === 0x2b) {
// '+'
} else if (ch === /* '+' = */ 0x2b) {
sign = 1;
ch = this.nextChar();
}
if (ch === 0x0a || ch === 0x0d) {
// LF, CR
if (ch === /* LF = */ 0x0a || ch === /* CR = */ 0x0d) {
// Ignore line-breaks (this is consistent with Adobe Reader).
do {
ch = this.nextChar();
} while (ch === 0x0a || ch === 0x0d);
}
if (ch === 0x2e) {
// '.'
if (ch === /* '.' = */ 0x2e) {
divideBy = 10;
ch = this.nextChar();
}
if (ch < 0x30 || ch > 0x39) {
// '0' - '9'
if (ch < /* '0' = */ 0x30 || ch > /* '9' = */ 0x39) {
if (
divideBy === 10 &&
sign === 0 &&
@ -911,8 +906,7 @@ class Lexer {
let powerValueSign = 1;
while ((ch = this.nextChar()) >= 0) {
if (0x30 <= ch && ch <= 0x39) {
// '0' - '9'
if (ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) {
const currentDigit = ch - 0x30; // '0'
if (eNotation) {
// We are after an 'e' or 'E'.
@ -924,30 +918,25 @@ class Lexer {
}
baseValue = baseValue * 10 + currentDigit;
}
} else if (ch === 0x2e) {
// '.'
} else if (ch === /* '.' = */ 0x2e) {
if (divideBy === 0) {
divideBy = 1;
} else {
// A number can have only one dot.
break;
}
} else if (ch === 0x2d) {
// '-'
} else if (ch === /* '-' = */ 0x2d) {
// Ignore minus signs in the middle of numbers to match
// Adobe's behavior.
warn("Badly formatted number: minus sign in the middle");
} else if (ch === 0x45 || ch === 0x65) {
// 'E', 'e'
} else if (ch === /* 'E' = */ 0x45 || ch === /* 'e' = */ 0x65) {
// 'E' can be either a scientific notation or the beginning of a new
// operator.
ch = this.peekChar();
if (ch === 0x2b || ch === 0x2d) {
// '+', '-'
if (ch === /* '+' = */ 0x2b || ch === /* '-' = */ 0x2d) {
powerValueSign = ch === 0x2d ? -1 : 1;
this.nextChar(); // Consume the sign character.
} else if (ch < 0x30 || ch > 0x39) {
// '0' - '9'
} else if (ch < /* '0' = */ 0x30 || ch > /* '9' = */ 0x39) {
// The 'E' must be the beginning of a new operator.
break;
}
@ -1020,23 +1009,21 @@ class Lexer {
case 0x29: // ')'
strBuf.push(String.fromCharCode(ch));
break;
case 0x30:
case 0x31:
case 0x32:
case 0x33: // '0'-'3'
case 0x34:
case 0x35:
case 0x36:
case 0x37: // '4'-'7'
case 0x30: // '0'
case 0x31: // '1'
case 0x32: // '2'
case 0x33: // '3'
case 0x34: // '4'
case 0x35: // '5'
case 0x36: // '6'
case 0x37: // '7'
let x = ch & 0x0f;
ch = this.nextChar();
charBuffered = true;
if (ch >= 0x30 && ch <= 0x37) {
// '0'-'7'
if (ch >= /* '0' = */ 0x30 && ch <= /* '7' = */ 0x37) {
x = (x << 3) + (ch & 0x0f);
ch = this.nextChar();
if (ch >= 0x30 && ch <= 0x37) {
// '0'-'7'
if (ch >= /* '0' = */ 0x30 && ch /* '7' = */ <= 0x37) {
charBuffered = false;
x = (x << 3) + (ch & 0x0f);
}
@ -1044,8 +1031,7 @@ class Lexer {
strBuf.push(String.fromCharCode(x));
break;
case 0x0d: // CR
if (this.peekChar() === 0x0a) {
// LF
if (this.peekChar() === /* LF = */ 0x0a) {
this.nextChar();
}
break;
@ -1076,8 +1062,7 @@ class Lexer {
strBuf.length = 0;
while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
if (ch === 0x23) {
// '#'
if (ch === /* '#' = */ 0x23) {
ch = this.nextChar();
if (specialChars[ch]) {
warn(
@ -1129,8 +1114,7 @@ class Lexer {
if (ch < 0) {
warn("Unterminated hex string");
break;
} else if (ch === 0x3e) {
// '>'
} else if (ch === /* '>' = */ 0x3e) {
this.nextChar();
break;
} else if (specialChars[ch] === 1) {
@ -1169,12 +1153,10 @@ class Lexer {
return EOF;
}
if (comment) {
if (ch === 0x0a || ch === 0x0d) {
// LF, CR
if (ch === /* LF = */ 0x0a || ch === /* CR = */ 0x0d) {
comment = false;
}
} else if (ch === 0x25) {
// '%'
} else if (ch === /* '%' = */ 0x25) {
comment = true;
} else if (specialChars[ch] !== 1) {
break;
@ -1184,19 +1166,19 @@ class Lexer {
// Start reading a token.
switch (ch | 0) {
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34: // '0'-'4'
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39: // '5'-'9'
case 0x2b:
case 0x2d:
case 0x2e: // '+', '-', '.'
case 0x30: // '0'
case 0x31: // '1'
case 0x32: // '2'
case 0x33: // '3'
case 0x34: // '4'
case 0x35: // '5'
case 0x36: // '6'
case 0x37: // '7'
case 0x38: // '8'
case 0x39: // '9'
case 0x2b: // '+'
case 0x2d: // '-'
case 0x2e: // '.'
return this.getNumber();
case 0x28: // '('
return this.getString();
@ -1280,16 +1262,13 @@ class Lexer {
skipToNextLine() {
let ch = this.currentChar;
while (ch >= 0) {
if (ch === 0x0d) {
// CR
if (ch === /* CR = */ 0x0d) {
ch = this.nextChar();
if (ch === 0x0a) {
// LF
if (ch === /* LF = */ 0x0a) {
this.nextChar();
}
break;
} else if (ch === 0x0a) {
// LF
} else if (ch === /* LF = */ 0x0a) {
this.nextChar();
break;
}
@ -1323,7 +1302,7 @@ class Linearization {
const hint = hints[index];
if (!(Number.isInteger(hint) && hint > 0)) {
throw new Error(
`Hint (${index}) in the linearization dictionary ` + "is invalid."
`Hint (${index}) in the linearization dictionary is invalid.`
);
}
}

View file

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-multi-spaces */
import {
assert,

View file

@ -190,8 +190,7 @@ class PostScriptLexer {
if (ch === 0x0a || ch === 0x0d) {
comment = false;
}
} else if (ch === 0x25) {
// '%'
} else if (ch === /* '%' = */ 0x25) {
comment = true;
} else if (!isSpace(ch)) {
break;
@ -199,19 +198,19 @@ class PostScriptLexer {
ch = this.nextChar();
}
switch (ch | 0) {
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34: // '0'-'4'
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39: // '5'-'9'
case 0x2b:
case 0x2d:
case 0x2e: // '+', '-', '.'
case 0x30: // '0'
case 0x31: // '1'
case 0x32: // '2'
case 0x33: // '3'
case 0x34: // '4'
case 0x35: // '5'
case 0x36: // '6'
case 0x37: // '7'
case 0x38: // '8'
case 0x39: // '9'
case 0x2b: // '+'
case 0x2d: // '-'
case 0x2e: // '.'
return new PostScriptToken(
PostScriptTokenTypes.NUMBER,
this.getNumber()
@ -229,8 +228,9 @@ class PostScriptLexer {
strBuf[0] = String.fromCharCode(ch);
while (
(ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
((ch >= 0x41 && ch <= 0x5a) || (ch >= 0x61 && ch <= 0x7a))
(ch = this.nextChar()) >= 0 &&
((ch >= /* 'A' = */ 0x41 && ch <= /* 'Z' = */ 0x5a) ||
(ch >= /* 'a' = */ 0x61 && ch <= /* 'z' = */ 0x7a))
) {
strBuf.push(String.fromCharCode(ch));
}
@ -253,11 +253,10 @@ class PostScriptLexer {
while ((ch = this.nextChar()) >= 0) {
if (
(ch >= 0x30 && ch <= 0x39) || // '0'-'9'
ch === 0x2d ||
ch === 0x2e
(ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) ||
ch === /* '-' = */ 0x2d ||
ch === /* '.' = */ 0x2e
) {
// '-', '.'
strBuf.push(String.fromCharCode(ch));
} else {
break;

View file

@ -1098,19 +1098,19 @@ var AsciiHexStream = (function AsciiHexStreamClosure() {
for (var i = 0, ii = bytes.length; i < ii; i++) {
var ch = bytes[i],
digit;
if (ch >= 0x30 && ch <= 0x39) {
// '0'-'9'
if (ch >= /* '0' = */ 0x30 && ch <= /* '9' = */ 0x39) {
digit = ch & 0x0f;
} else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
// 'A'-'Z', 'a'-'z'
} else if (
(ch >= /* 'A' = */ 0x41 && ch <= /* 'Z' = */ 0x46) ||
(ch >= /* 'a' = */ 0x61 && ch <= /* 'z' = */ 0x66)
) {
digit = (ch & 0x0f) + 9;
} else if (ch === 0x3e) {
// '>'
} else if (ch === /* '>' = */ 0x3e) {
this.eof = true;
break;
} else {
// probably whitespace
continue; // ignoring
// Probably whitespace, ignoring.
continue;
}
if (firstDigit < 0) {
firstDigit = digit;

View file

@ -385,8 +385,8 @@ var Type1Parser = (function Type1ParserClosure() {
return (
(code >= 48 && code <= 57) || // '0'-'9'
(code >= 65 && code <= 70) || // 'A'-'F'
(code >= 97 && code <= 102)
); // 'a'-'f'
(code >= 97 && code <= 102) // 'a'-'f'
);
}
function decrypt(data, key, discardNumber) {
@ -521,8 +521,7 @@ var Type1Parser = (function Type1ParserClosure() {
if (ch === 0x0a || ch === 0x0d) {
comment = false;
}
} else if (ch === 0x25) {
// '%'
} else if (ch === /* '%' = */ 0x25) {
comment = true;
} else if (!isSpace(ch)) {
break;

View file

@ -52,8 +52,7 @@ function mapSpecialUnicodeValues(code) {
return 0;
} else if (code >= 0xf600 && code <= 0xf8ff) {
return getSpecialPUASymbols()[code] || code;
} else if (code === 0x00ad) {
// softhyphen
} else if (code === /* softhyphen = */ 0x00ad) {
return 0x002d; // hyphen
}
return code;

View file

@ -527,8 +527,9 @@ var WorkerMessageHandler = {
sink.error(reason);
// TODO: Should `reason` be re-thrown here (currently that casues
// "Uncaught exception: ..." messages in the console)?
// TODO: Should `reason` be re-thrown here (currently that
// casues "Uncaught exception: ..." messages in the
// console)?
}
);
});

View file

@ -381,8 +381,8 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
? PDFJSDev.eval("BUNDLE_VERSION")
: null,
// Only send the required properties, and *not* the entire object.
source: {
// Only send the required properties, and *not* the entire object.
data: source.data,
url: source.url,
password: source.password,
@ -1087,8 +1087,8 @@ class PDFPageProxy {
const internalRenderTask = new InternalRenderTask({
callback: complete,
// Only include the required properties, and *not* the entire object.
params: {
// Include the required properties, and *not* the entire object.
canvasContext,
viewport,
transform,
@ -1641,8 +1641,8 @@ const PDFWorker = (function PDFWorkerClosure() {
if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC") &&
// eslint-disable-next-line no-undef
isNodeJS &&
// eslint-disable-next-line no-undef
typeof __non_webpack_require__ === "function"
) {
// Since bundlers, such as Webpack, cannot be told to leave `require`

View file

@ -113,18 +113,18 @@ class BaseFontLoader {
unreachable("Abstract method `_queueLoadingCallback`.");
}
// eslint-disable-next-line getter-return
get isFontLoadingAPISupported() {
// eslint-disable-line getter-return
unreachable("Abstract method `isFontLoadingAPISupported`.");
}
// eslint-disable-next-line getter-return
get isSyncFontLoadingSupported() {
// eslint-disable-line getter-return
unreachable("Abstract method `isSyncFontLoadingSupported`.");
}
// eslint-disable-next-line getter-return
get _loadTestFont() {
// eslint-disable-line getter-return
unreachable("Abstract method `_loadTestFont`.");
}
@ -225,8 +225,8 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
get _loadTestFont() {
const getLoadTestFont = function() {
// This is a CFF font with 1 glyph for '.' that fills its entire width and
// height.
// This is a CFF font with 1 glyph for '.' that fills its entire width
// and height.
return atob(
"T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" +
"FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" +

View file

@ -125,8 +125,8 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
function deflateSync(literals) {
if (!isNodeJS) {
// zlib is certainly not available outside of Node.js. We can either use
// the pako library for client-side DEFLATE compression, or use the canvas
// API of the browser to obtain a more optimal PNG file.
// the pako library for client-side DEFLATE compression, or use the
// canvas API of the browser to obtain a more optimal PNG file.
return deflateSyncUncompressed(literals);
}
try {

View file

@ -248,7 +248,8 @@ if (
return;
}
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
// The `URL` constructor is assumed to be available in the extension builds.
// The `URL` constructor is assumed to be available in the extension
// builds.
return;
}
globalThis.URL = require("core-js/web/url");

View file

@ -73,7 +73,7 @@ function readCharstringEncoding(aString) {
var charstringTokens = [];
var count = aString.length;
for (var i = 0; i < count; ) { // eslint-disable-line space-in-parens
for (var i = 0; i < count; ) {
var value = aString[i++] | 0;
var token = null;