Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the ESLint no-shadow rule #11745

Merged
merged 3 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
"no-catch-shadow": "error",
"no-delete-var": "error",
"no-label-var": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-shadow": "off",
"no-undef-init": "error",
"no-undef": ["error", { "typeof": true, }],
"no-unused-vars": ["error", {
Expand Down
4 changes: 2 additions & 2 deletions external/builder/preprocessor2.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function traverseTree(ctx, node) {
for (var i in node) {
var child = node[i];
if (typeof child === "object" && child !== null && child.type) {
var result = traverseTree(ctx, child);
const result = traverseTree(ctx, child);
if (result !== child) {
node[i] = result;
}
Expand All @@ -300,7 +300,7 @@ function traverseTree(ctx, node) {
childItem !== null &&
childItem.type
) {
var result = traverseTree(ctx, childItem);
const result = traverseTree(ctx, childItem);
if (result !== childItem) {
child[index] = result;
}
Expand Down
54 changes: 26 additions & 28 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ function createStringSource(filename, content) {
}

function createWebpackConfig(defines, output) {
var path = require("path");

var versionInfo = getVersionJSON();
var bundleDefines = builder.merge(defines, {
BUNDLE_VERSION: versionInfo.version,
Expand Down Expand Up @@ -243,9 +241,9 @@ function createWebpackConfig(defines, output) {
};
}

function webpack2Stream(config) {
function webpack2Stream(webpackConfig) {
// Replacing webpack1 to webpack2 in the webpack-stream.
return webpackStream(config, webpack2);
return webpackStream(webpackConfig, webpack2);
}

function getVersionJSON() {
Expand Down Expand Up @@ -378,38 +376,38 @@ function createImageDecodersBundle(defines) {
.pipe(replaceJSRootName(imageDecodersAMDName, "pdfjsImageDecoders"));
}

function checkFile(path) {
function checkFile(filePath) {
try {
var stat = fs.lstatSync(path);
var stat = fs.lstatSync(filePath);
return stat.isFile();
} catch (e) {
return false;
}
}

function checkDir(path) {
function checkDir(dirPath) {
try {
var stat = fs.lstatSync(path);
var stat = fs.lstatSync(dirPath);
return stat.isDirectory();
} catch (e) {
return false;
}
}

function replaceInFile(path, find, replacement) {
var content = fs.readFileSync(path).toString();
function replaceInFile(filePath, find, replacement) {
var content = fs.readFileSync(filePath).toString();
content = content.replace(find, replacement);
fs.writeFileSync(path, content);
fs.writeFileSync(filePath, content);
}

function getTempFile(prefix, suffix) {
mkdirp.sync(BUILD_DIR + "tmp/");
var bytes = require("crypto")
.randomBytes(6)
.toString("hex");
var path = BUILD_DIR + "tmp/" + prefix + bytes + suffix;
fs.writeFileSync(path, "");
return path;
var filePath = BUILD_DIR + "tmp/" + prefix + bytes + suffix;
fs.writeFileSync(filePath, "");
return filePath;
}

function createTestSource(testsName, bot) {
Expand Down Expand Up @@ -527,10 +525,10 @@ gulp.task("buildnumber", function(done) {

var version = config.versionPrefix + buildNumber;

exec('git log --format="%h" -n 1', function(err, stdout, stderr) {
exec('git log --format="%h" -n 1', function(err2, stdout2, stderr2) {
var buildCommit = "";
if (!err) {
buildCommit = stdout.replace("\n", "");
if (!err2) {
buildCommit = stdout2.replace("\n", "");
}

createStringSource(
Expand Down Expand Up @@ -559,9 +557,9 @@ gulp.task("default_preferences-pre", function() {
function babelPluginReplaceNonWebPackRequire(babel) {
return {
visitor: {
Identifier(path, state) {
if (path.node.name === "__non_webpack_require__") {
path.replaceWith(babel.types.identifier("require"));
Identifier(curPath, state) {
if (curPath.node.name === "__non_webpack_require__") {
curPath.replaceWith(babel.types.identifier("require"));
}
},
},
Expand Down Expand Up @@ -643,8 +641,8 @@ gulp.task("locale", function() {
var locales = [];
for (var i = 0; i < subfolders.length; i++) {
var locale = subfolders[i];
var path = L10N_DIR + locale;
if (!checkDir(path)) {
var dirPath = L10N_DIR + locale;
if (!checkDir(dirPath)) {
continue;
}
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
Expand All @@ -656,7 +654,7 @@ gulp.task("locale", function() {

locales.push(locale);

if (checkFile(path + "/viewer.properties")) {
if (checkFile(dirPath + "/viewer.properties")) {
viewerOutput +=
"[" +
locale +
Expand Down Expand Up @@ -1163,9 +1161,9 @@ gulp.task(
function babelPluginReplaceNonWebPackRequire(babel) {
return {
visitor: {
Identifier(path, state) {
if (path.node.name === "__non_webpack_require__") {
path.replaceWith(babel.types.identifier("require"));
Identifier(curPath, state) {
if (curPath.node.name === "__non_webpack_require__") {
curPath.replaceWith(babel.types.identifier("require"));
}
},
},
Expand Down Expand Up @@ -1358,9 +1356,9 @@ gulp.task("baseline", function(done) {
}

exec("git checkout " + baselineCommit, { cwd: workingDirectory }, function(
error
error2
) {
if (error) {
if (error2) {
done(new Error("Baseline commit checkout failed."));
return;
}
Expand Down
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
Loading