Skip to content

Commit

Permalink
tools: replace var to let/const
Browse files Browse the repository at this point in the history
PR-URL: #26398
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Masashi Hirano authored and BridgeAR committed Mar 14, 2019
1 parent 81c5382 commit 57198f2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions tools/eslint-rules/crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const bindingModules = cryptoModules.concat(['tls_wrap']);
module.exports = function(context) {
const missingCheckNodes = [];
const requireNodes = [];
var commonModuleNode = null;
var hasSkipCall = false;
let commonModuleNode = null;
let hasSkipCall = false;

function testCryptoUsage(node) {
if (utils.isRequired(node, requireModules) ||
Expand Down
4 changes: 2 additions & 2 deletions tools/eslint-rules/eslint-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const msg = 'Please add a skipIfEslintMissing() call to allow this test to ' +

module.exports = function(context) {
const missingCheckNodes = [];
var commonModuleNode = null;
var hasEslintCheck = false;
let commonModuleNode = null;
let hasEslintCheck = false;

function testEslintUsage(context, node) {
if (utils.isRequired(node, ['../../tools/node_modules/eslint'])) {
Expand Down
4 changes: 2 additions & 2 deletions tools/eslint-rules/inspector-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' +

module.exports = function(context) {
const missingCheckNodes = [];
var commonModuleNode = null;
var hasInspectorCheck = false;
let commonModuleNode = null;
let hasInspectorCheck = false;

function testInspectorUsage(context, node) {
if (utils.isRequired(node, ['inspector'])) {
Expand Down
16 changes: 8 additions & 8 deletions tools/eslint-rules/no-unescaped-regexp-dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
module.exports = function(context) {
const sourceCode = context.getSourceCode();
const regexpStack = [];
var regexpBuffer = [];
var inRegExp = false;
let regexpBuffer = [];
let inRegExp = false;

function report(node, startOffset) {
const indexOfDot = sourceCode.getIndexFromLoc(node.loc.start) + startOffset;
Expand All @@ -25,13 +25,13 @@ module.exports = function(context) {

const allowedModifiers = ['+', '*', '?', '{'];
function checkRegExp(nodes) {
var escaping = false;
var inCharClass = false;
for (var n = 0; n < nodes.length; ++n) {
let escaping = false;
let inCharClass = false;
for (let n = 0; n < nodes.length; ++n) {
const pair = nodes[n];
const node = pair[0];
const str = pair[1];
for (var i = 0; i < str.length; ++i) {
for (let i = 0; i < str.length; ++i) {
switch (str[i]) {
case '[':
if (!escaping)
Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = function(context) {
node.quasis.length);
if (inRegExp &&
(isTemplate || (typeof node.value === 'string' && node.value.length))) {
var p = node.parent;
let p = node.parent;
while (p && p.type === 'BinaryExpression') {
p = p.parent;
}
Expand All @@ -105,7 +105,7 @@ module.exports = function(context) {
p.callee.name === 'RegExp') {
if (isTemplate) {
const quasis = node.quasis;
for (var i = 0; i < quasis.length; ++i) {
for (let i = 0; i < quasis.length; ++i) {
const el = quasis[i];
if (el.type === 'TemplateElement' && el.value && el.value.cooked)
regexpBuffer.push([el, el.value.cooked]);
Expand Down
2 changes: 1 addition & 1 deletion tools/eslint-rules/prefer-assert-iferror.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const utils = require('./rules-utils.js');
module.exports = {
create(context) {
const sourceCode = context.getSourceCode();
var assertImported = false;
let assertImported = false;

function hasSameTokens(nodeA, nodeB) {
const aTokens = sourceCode.getTokens(nodeA);
Expand Down
10 changes: 5 additions & 5 deletions tools/eslint-rules/required-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const path = require('path');

module.exports = function(context) {
// trim required module names
var requiredModules = context.options;
const requiredModules = context.options;
const isESM = context.parserOptions.sourceType === 'module';

const foundModules = [];
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = function(context) {
* @returns {undefined|String} required module name or undefined
*/
function getRequiredModuleName(str) {
var value = path.basename(str);
const value = path.basename(str);

// Check if value is in required modules array
return requiredModules.indexOf(value) !== -1 ? value : undefined;
Expand All @@ -70,7 +70,7 @@ module.exports = function(context) {
const rules = {
'Program:exit'(node) {
if (foundModules.length < requiredModules.length) {
var missingModules = requiredModules.filter(
const missingModules = requiredModules.filter(
(module) => foundModules.indexOf(module) === -1
);
missingModules.forEach((moduleName) => {
Expand All @@ -86,15 +86,15 @@ module.exports = function(context) {

if (isESM) {
rules.ImportDeclaration = (node) => {
var requiredModuleName = getRequiredModuleName(node.source.value);
const requiredModuleName = getRequiredModuleName(node.source.value);
if (requiredModuleName) {
foundModules.push(requiredModuleName);
}
};
} else {
rules.CallExpression = (node) => {
if (isRequireCall(node)) {
var requiredModuleName = getRequiredModuleNameFromCall(node);
const requiredModuleName = getRequiredModuleNameFromCall(node);

if (requiredModuleName) {
foundModules.push(requiredModuleName);
Expand Down
4 changes: 2 additions & 2 deletions tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports.isRequired = function(node, modules) {
* Return true if common module is required
* in AST Node under inspection
*/
var commonModuleRegExp = new RegExp(/^(\.\.\/)*common(\.js)?$/);
const commonModuleRegExp = new RegExp(/^(\.\.\/)*common(\.js)?$/);
module.exports.isCommonModule = function(node) {
return node.callee.name === 'require' &&
node.arguments.length !== 0 &&
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports.usesCommonProperty = function(node, properties) {
* and the block also has a call to skip.
*/
module.exports.inSkipBlock = function(node) {
var hasSkipBlock = false;
let hasSkipBlock = false;
if (node.test &&
node.test.type === 'UnaryExpression' &&
node.test.operator === '!') {
Expand Down
40 changes: 20 additions & 20 deletions tools/lint-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ if (process.argv.indexOf('-F') !== -1)
const cli = new CLIEngine(cliOptions);

if (cluster.isMaster) {
var numCPUs = 1;
let numCPUs = 1;
const paths = [];
var files = null;
var totalPaths = 0;
var failures = 0;
var successes = 0;
var lastLineLen = 0;
var curPath = 'Starting ...';
var showProgress = true;
let files = null;
let totalPaths = 0;
let failures = 0;
let successes = 0;
let lastLineLen = 0;
let curPath = 'Starting ...';
let showProgress = true;
const globOptions = {
nodir: true
};
const workerConfig = {};
var startTime;
var formatter;
var outFn;
var fd;
var i;
let startTime;
let formatter;
let outFn;
let fd;
let i;

// Check if spreading work among all cores/cpus
if (process.argv.indexOf('-J') !== -1)
Expand Down Expand Up @@ -169,7 +169,7 @@ if (cluster.isMaster) {
// We either just started or we have no more files to lint for the current
// path. Find the next path that has some files to be linted.
while (paths.length) {
var dir = paths.shift();
let dir = paths.shift();
curPath = dir;
const patterns = cli.resolveFileGlobPatterns([dir]);
dir = path.resolve(patterns[0]);
Expand All @@ -188,7 +188,7 @@ if (cluster.isMaster) {
// workers busy most of the time instead of only a minority doing most of
// the work.
const sliceLen = Math.min(maxWorkload, Math.ceil(files.length / numCPUs));
var slice;
let slice;
if (sliceLen === files.length) {
// Micro-optimization to avoid splicing to an empty array
slice = files;
Expand All @@ -212,10 +212,10 @@ if (cluster.isMaster) {
const secs = `${elapsed % 60}`.padStart(2, '0');
const passed = `${successes}`.padStart(6);
const failed = `${failures}`.padStart(6);
var pct = Math.ceil(((totalPaths - paths.length) / totalPaths) * 100);
pct = `${pct}`.padStart(3);
let pct = `${Math.ceil(((totalPaths - paths.length) / totalPaths) * 100)}`;
pct = pct.padStart(3);

var line = `[${mins}:${secs}|%${pct}|+${passed}|-${failed}]: ${curPath}`;
let line = `[${mins}:${secs}|%${pct}|+${passed}|-${failed}]: ${curPath}`;

// Truncate line like cpplint does in case it gets too long
if (line.length > 75)
Expand All @@ -229,7 +229,7 @@ if (cluster.isMaster) {
} else {
// Worker

var config = {};
let config = {};
process.on('message', (files) => {
if (files instanceof Array) {
// Lint some files
Expand All @@ -246,7 +246,7 @@ if (cluster.isMaster) {
// Silence warnings for files with no errors while keeping the "ok"
// status
if (report.warningCount > 0) {
for (var i = 0; i < results.length; ++i) {
for (let i = 0; i < results.length; ++i) {
const result = results[i];
if (result.errorCount === 0 && result.warningCount > 0) {
result.warningCount = 0;
Expand Down

0 comments on commit 57198f2

Please sign in to comment.