Skip to content

Commit

Permalink
Whitelist closure related cases to address the remaining no-shadow
Browse files Browse the repository at this point in the history
…linting errors

Given the way that "classes" were previously implemented in PDF.js, using regular functions and closures, there's a fair number of false positives when the `no-shadow` ESLint rule was enabled.

Note that while *some* of these `eslint-disable` statements can be removed if/when the relevant code is converted to proper `class`es, we'll probably never be able to get rid of all of them given our naming/coding conventions (however I don't really see this being a problem).
  • Loading branch information
Snuffleupagus committed Mar 25, 2020
1 parent 1d2f787 commit dcb16af
Show file tree
Hide file tree
Showing 32 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/ccitt.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ const CCITTFaxDecoder = (function CCITTFaxDecoder() {
* @param {CCITTFaxDecoderSource} source - The data which should be decoded.
* @param {Object} [options] - Decoding options.
*/
// eslint-disable-next-line no-shadow
function CCITTFaxDecoder(source, options = {}) {
if (!source || typeof source.next !== "function") {
throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
Expand Down
1 change: 1 addition & 0 deletions src/core/ccitt_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CCITTFaxDecoder } from "./ccitt.js";
import { DecodeStream } from "./stream.js";

var CCITTFaxStream = (function CCITTFaxStreamClosure() {
// eslint-disable-next-line no-shadow
function CCITTFaxStream(str, maybeLength, params) {
this.str = str;
this.dict = str.dict;
Expand Down
15 changes: 15 additions & 0 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var CFFParser = (function CFFParserClosure() {
{ id: "flex1", min: 11, resetStack: true },
];

// eslint-disable-next-line no-shadow
function CFFParser(file, properties, seacAnalysisEnabled) {
this.bytes = file.getBytes();
this.properties = properties;
Expand Down Expand Up @@ -964,6 +965,7 @@ var CFFParser = (function CFFParserClosure() {

// Compact Font Format
var CFF = (function CFFClosure() {
// eslint-disable-next-line no-shadow
function CFF() {
this.header = null;
this.names = [];
Expand Down Expand Up @@ -1009,6 +1011,7 @@ var CFF = (function CFFClosure() {
})();

var CFFHeader = (function CFFHeaderClosure() {
// eslint-disable-next-line no-shadow
function CFFHeader(major, minor, hdrSize, offSize) {
this.major = major;
this.minor = minor;
Expand All @@ -1019,6 +1022,7 @@ var CFFHeader = (function CFFHeaderClosure() {
})();

var CFFStrings = (function CFFStringsClosure() {
// eslint-disable-next-line no-shadow
function CFFStrings() {
this.strings = [];
}
Expand Down Expand Up @@ -1054,6 +1058,7 @@ var CFFStrings = (function CFFStringsClosure() {
})();

var CFFIndex = (function CFFIndexClosure() {
// eslint-disable-next-line no-shadow
function CFFIndex() {
this.objects = [];
this.length = 0;
Expand All @@ -1078,6 +1083,7 @@ var CFFIndex = (function CFFIndexClosure() {
})();

var CFFDict = (function CFFDictClosure() {
// eslint-disable-next-line no-shadow
function CFFDict(tables, strings) {
this.keyToNameMap = tables.keyToNameMap;
this.nameToKeyMap = tables.nameToKeyMap;
Expand Down Expand Up @@ -1205,6 +1211,8 @@ var CFFTopDict = (function CFFTopDictClosure() {
[[12, 38], "FontName", "sid", null],
];
var tables = null;

// eslint-disable-next-line no-shadow
function CFFTopDict(strings) {
if (tables === null) {
tables = CFFDict.createTables(layout);
Expand Down Expand Up @@ -1238,6 +1246,8 @@ var CFFPrivateDict = (function CFFPrivateDictClosure() {
[19, "Subrs", "offset", null],
];
var tables = null;

// eslint-disable-next-line no-shadow
function CFFPrivateDict(strings) {
if (tables === null) {
tables = CFFDict.createTables(layout);
Expand All @@ -1255,6 +1265,7 @@ var CFFCharsetPredefinedTypes = {
EXPERT_SUBSET: 2,
};
var CFFCharset = (function CFFCharsetClosure() {
// eslint-disable-next-line no-shadow
function CFFCharset(predefined, format, charset, raw) {
this.predefined = predefined;
this.format = format;
Expand All @@ -1265,6 +1276,7 @@ var CFFCharset = (function CFFCharsetClosure() {
})();

var CFFEncoding = (function CFFEncodingClosure() {
// eslint-disable-next-line no-shadow
function CFFEncoding(predefined, format, encoding, raw) {
this.predefined = predefined;
this.format = format;
Expand All @@ -1275,6 +1287,7 @@ var CFFEncoding = (function CFFEncodingClosure() {
})();

var CFFFDSelect = (function CFFFDSelectClosure() {
// eslint-disable-next-line no-shadow
function CFFFDSelect(format, fdSelect) {
this.format = format;
this.fdSelect = fdSelect;
Expand All @@ -1293,6 +1306,7 @@ var CFFFDSelect = (function CFFFDSelectClosure() {
// Helper class to keep track of where an offset is within the data and helps
// filling in that offset once it's known.
var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
// eslint-disable-next-line no-shadow
function CFFOffsetTracker() {
this.offsets = Object.create(null);
}
Expand Down Expand Up @@ -1352,6 +1366,7 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {

// Takes a CFF and converts it to the binary representation.
var CFFCompiler = (function CFFCompilerClosure() {
// eslint-disable-next-line no-shadow
function CFFCompiler(cff) {
this.cff = cff;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
});
}

// eslint-disable-next-line no-shadow
function BinaryCMapReader() {}

BinaryCMapReader.prototype = {
Expand Down
4 changes: 4 additions & 0 deletions src/core/colorspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ const DeviceCmykCS = (function DeviceCmykCSClosure() {
k * (-22.33816807309886 * k - 180.12613974708367);
}

// eslint-disable-next-line no-shadow
class DeviceCmykCS extends ColorSpace {
constructor() {
super("DeviceCMYK", 4);
Expand Down Expand Up @@ -902,6 +903,7 @@ const CalGrayCS = (function CalGrayCSClosure() {
dest[destOffset + 2] = val;
}

// eslint-disable-next-line no-shadow
class CalGrayCS extends ColorSpace {
constructor(whitePoint, blackPoint, gamma) {
super("CalGray", 1);
Expand Down Expand Up @@ -1190,6 +1192,7 @@ const CalRGBCS = (function CalRGBCSClosure() {
dest[destOffset + 2] = sRGBTransferFunction(SRGB[2]) * 255;
}

// eslint-disable-next-line no-shadow
class CalRGBCS extends ColorSpace {
constructor(whitePoint, blackPoint, gamma, matrix) {
super("CalRGB", 3);
Expand Down Expand Up @@ -1371,6 +1374,7 @@ const LabCS = (function LabCSClosure() {
dest[destOffset + 2] = Math.sqrt(b) * 255;
}

// eslint-disable-next-line no-shadow
class LabCS extends ColorSpace {
constructor(whitePoint, blackPoint, range) {
super("Lab", 3);
Expand Down
7 changes: 7 additions & 0 deletions src/core/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { isDict, isName, Name } from "./primitives.js";
import { DecryptStream } from "./stream.js";

var ARCFourCipher = (function ARCFourCipherClosure() {
// eslint-disable-next-line no-shadow
function ARCFourCipher(key) {
this.a = 0;
this.b = 0;
Expand Down Expand Up @@ -177,6 +178,7 @@ var calculateMD5 = (function calculateMD5Closure() {
return hash;
})();
var Word64 = (function Word64Closure() {
// eslint-disable-next-line no-shadow
function Word64(highInteger, lowInteger) {
this.high = highInteger | 0;
this.low = lowInteger | 0;
Expand Down Expand Up @@ -690,6 +692,7 @@ var calculateSHA384 = (function calculateSHA384Closure() {
return hash;
})();
var NullCipher = (function NullCipherClosure() {
// eslint-disable-next-line no-shadow
function NullCipher() {}

NullCipher.prototype = {
Expand Down Expand Up @@ -1265,6 +1268,7 @@ var PDF17 = (function PDF17Closure() {
return true;
}

// eslint-disable-next-line no-shadow
function PDF17() {}

PDF17.prototype = {
Expand Down Expand Up @@ -1372,6 +1376,7 @@ var PDF20 = (function PDF20Closure() {
return k.subarray(0, 32);
}

// eslint-disable-next-line no-shadow
function PDF20() {}

function compareByteArrays(array1, array2) {
Expand Down Expand Up @@ -1446,6 +1451,7 @@ var PDF20 = (function PDF20Closure() {
})();

var CipherTransform = (function CipherTransformClosure() {
// eslint-disable-next-line no-shadow
function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
this.StringCipherConstructor = stringCipherConstructor;
this.StreamCipherConstructor = streamCipherConstructor;
Expand Down Expand Up @@ -1661,6 +1667,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {

var identityName = Name.get("Identity");

// eslint-disable-next-line no-shadow
function CipherTransformFactory(dict, fileId, password) {
var filter = dict.get("Filter");
if (!isName(filter, "Standard")) {
Expand Down
6 changes: 6 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
isEvalSupported: true,
};

// eslint-disable-next-line no-shadow
function PartialEvaluator({
xref,
handler,
Expand Down Expand Up @@ -3266,6 +3267,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
})();

var TranslatedFont = (function TranslatedFontClosure() {
// eslint-disable-next-line no-shadow
function TranslatedFont(loadedName, font, dict) {
this.loadedName = loadedName;
this.font = font;
Expand Down Expand Up @@ -3367,6 +3369,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
})();

var StateManager = (function StateManagerClosure() {
// eslint-disable-next-line no-shadow
function StateManager(initialState) {
this.state = initialState;
this.stateStack = [];
Expand All @@ -3391,6 +3394,7 @@ var StateManager = (function StateManagerClosure() {
})();

var TextState = (function TextStateClosure() {
// eslint-disable-next-line no-shadow
function TextState() {
this.ctm = new Float32Array(IDENTITY_MATRIX);
this.fontName = null;
Expand Down Expand Up @@ -3496,6 +3500,7 @@ var TextState = (function TextStateClosure() {
})();

var EvalState = (function EvalStateClosure() {
// eslint-disable-next-line no-shadow
function EvalState() {
this.ctm = new Float32Array(IDENTITY_MATRIX);
this.font = null;
Expand Down Expand Up @@ -3637,6 +3642,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {

const MAX_INVALID_PATH_OPS = 20;

// eslint-disable-next-line no-shadow
function EvaluatorPreprocessor(stream, xref, stateManager) {
this.opMap = getOPMap();
// TODO(mduan): pass array of knownCommands rather than this.opMap
Expand Down
8 changes: 8 additions & 0 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function recoverGlyphName(name, glyphsUnicodeMap) {
}

var Glyph = (function GlyphClosure() {
// eslint-disable-next-line no-shadow
function Glyph(
fontChar,
unicode,
Expand Down Expand Up @@ -268,6 +269,7 @@ var Glyph = (function GlyphClosure() {
})();

var ToUnicodeMap = (function ToUnicodeMapClosure() {
// eslint-disable-next-line no-shadow
function ToUnicodeMap(cmap = []) {
// The elements of this._map can be integers or strings, depending on how
// `cmap` was created.
Expand Down Expand Up @@ -319,6 +321,7 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
})();

var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
// eslint-disable-next-line no-shadow
function IdentityToUnicodeMap(firstChar, lastChar) {
this.firstChar = firstChar;
this.lastChar = lastChar;
Expand Down Expand Up @@ -389,6 +392,7 @@ var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
}
}

// eslint-disable-next-line no-shadow
function OpenTypeFileBuilder(sfnt) {
this.sfnt = sfnt;
this.tables = Object.create(null);
Expand Down Expand Up @@ -512,6 +516,7 @@ var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
* type1Font.bind();
*/
var Font = (function FontClosure() {
// eslint-disable-next-line no-shadow
function Font(name, file, properties) {
var charCode;

Expand Down Expand Up @@ -3305,6 +3310,7 @@ var Font = (function FontClosure() {
})();

var ErrorFont = (function ErrorFontClosure() {
// eslint-disable-next-line no-shadow
function ErrorFont(error) {
this.error = error;
this.loadedName = "g_font_error";
Expand Down Expand Up @@ -3518,6 +3524,7 @@ var Type1Font = (function Type1FontClosure() {
};
}

// eslint-disable-next-line no-shadow
function Type1Font(name, file, properties) {
// Some bad generators embed pfb file as is, we have to strip 6-byte header.
// Also, length1 and length2 might be off by 6 bytes as well.
Expand Down Expand Up @@ -3784,6 +3791,7 @@ var Type1Font = (function Type1FontClosure() {
})();

var CFFFont = (function CFFFontClosure() {
// eslint-disable-next-line no-shadow
function CFFFont(file, properties) {
this.properties = properties;

Expand Down
4 changes: 4 additions & 0 deletions src/core/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ function isPDFFunction(v) {

var PostScriptStack = (function PostScriptStackClosure() {
var MAX_STACK_SIZE = 100;

// eslint-disable-next-line no-shadow
function PostScriptStack(initialStack) {
this.stack = !initialStack
? []
Expand Down Expand Up @@ -625,6 +627,7 @@ var PostScriptStack = (function PostScriptStackClosure() {
return PostScriptStack;
})();
var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
// eslint-disable-next-line no-shadow
function PostScriptEvaluator(operators) {
this.operators = operators;
}
Expand Down Expand Up @@ -1084,6 +1087,7 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
return new AstMin(num1, max);
}

// eslint-disable-next-line no-shadow
function PostScriptCompiler() {}
PostScriptCompiler.prototype = {
compile: function PostScriptCompiler_compile(code, domain, range) {
Expand Down
1 change: 1 addition & 0 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var PDFImage = (function PDFImageClosure() {
return dest;
}

// eslint-disable-next-line no-shadow
function PDFImage({
xref,
res,
Expand Down
1 change: 1 addition & 0 deletions src/core/jbig2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
return bitmap;
}

// eslint-disable-next-line no-shadow
function Jbig2Image() {}

Jbig2Image.prototype = {
Expand Down
1 change: 1 addition & 0 deletions src/core/jbig2_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { shadow } from "../shared/util.js";
* the stream behaves like all the other DecodeStreams.
*/
const Jbig2Stream = (function Jbig2StreamClosure() {
// eslint-disable-next-line no-shadow
function Jbig2Stream(stream, maybeLength, dict, params) {
this.stream = stream;
this.maybeLength = maybeLength;
Expand Down
1 change: 1 addition & 0 deletions src/core/jpeg_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { JpegImage } from "./jpg.js";
* DecodeStreams.
*/
const JpegStream = (function JpegStreamClosure() {
// eslint-disable-next-line no-shadow
function JpegStream(stream, maybeLength, dict, params) {
// Some images may contain 'junk' before the SOI (start-of-image) marker.
// Note: this seems to mainly affect inline images.
Expand Down
1 change: 1 addition & 0 deletions src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var JpegImage = (function JpegImageClosure() {
var dctSqrt2 = 5793; // sqrt(2)
var dctSqrt1d2 = 2896; // sqrt(2) / 2

// eslint-disable-next-line no-shadow
function JpegImage({ decodeTransform = null, colorTransform = -1 } = {}) {
this._decodeTransform = decodeTransform;
this._colorTransform = colorTransform;
Expand Down
Loading

0 comments on commit dcb16af

Please sign in to comment.