Skip to content

Commit c6ab6b2

Browse files
silverwindtargos
authored andcommitted
tools: enable block-scoped-var eslint rule
PR-URL: #27616 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent f6642e9 commit c6ab6b2

File tree

11 files changed

+31
-20
lines changed

11 files changed

+31
-20
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = {
5959
'array-callback-return': 'error',
6060
'arrow-parens': ['error', 'always'],
6161
'arrow-spacing': ['error', { before: true, after: true }],
62+
'block-scoped-var': 'error',
6263
'block-spacing': 'error',
6364
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
6465
'capitalized-comments': ['error', 'always', {

benchmark/fixtures/simple-http-server.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const storedUnicode = Object.create(null);
1010
const useDomains = process.env.NODE_USE_DOMAINS;
1111

1212
// Set up one global domain.
13+
let domain;
1314
if (useDomains) {
14-
var domain = require('domain');
15+
domain = require('domain');
1516
const gdom = domain.create();
1617
gdom.on('error', (er) => {
1718
console.error('Error on global domain', er);

benchmark/http/_chunky_http_client.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function main({ len, n }) {
1616
const headers = [];
1717
// Chose 7 because 9 showed "Connection error" / "Connection closed"
1818
// An odd number could result in a better length dispersion.
19-
for (var i = 7; i <= 7 * 7 * 7; i *= 7)
19+
for (let i = 7; i <= 7 * 7 * 7; i *= 7)
2020
headers.push('o'.repeat(i));
2121

2222
function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) {
@@ -31,7 +31,7 @@ function main({ len, n }) {
3131
'Chrome/39.0.2171.71 Safari/537.36');
3232
todo.push('Accept-Encoding: gzip, deflate, sdch');
3333
todo.push('Accept-Language: en-US,en;q=0.8');
34-
for (var i = 0; i < extra_header_count; i++) {
34+
for (let i = 0; i < extra_header_count; i++) {
3535
// Utilize first three powers of a small integer for an odd cycle and
3636
// because the fourth power of some integers overloads the server.
3737
todo.push(`X-Header-${i}: ${headers[i % 3]}`);
@@ -41,7 +41,7 @@ function main({ len, n }) {
4141
todo = todo.join('\r\n');
4242
// Using odd numbers in many places may increase length coverage.
4343
const chunksize = 37;
44-
for (i = 0; i < todo.length; i += chunksize) {
44+
for (let i = 0; i < todo.length; i += chunksize) {
4545
const cur = todo.slice(i, i + chunksize);
4646
channel.write(cur);
4747
}

benchmark/http/cluster.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ const common = require('../common.js');
33
const PORT = common.PORT;
44

55
const cluster = require('cluster');
6+
let bench;
67
if (cluster.isMaster) {
7-
var bench = common.createBenchmark(main, {
8+
bench = common.createBenchmark(main, {
89
// Unicode confuses ab on os x.
910
type: ['bytes', 'buffer'],
1011
len: [4, 1024, 102400],

benchmark/napi/function_call/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const common = require('../../common.js');
1111
// which is quite common for benchmarks. so in that case, just
1212
// abort quietly.
1313

14+
let binding;
1415
try {
15-
var binding = require(`./build/${common.buildType}/binding`);
16+
binding = require(`./build/${common.buildType}/binding`);
1617
} catch {
1718
console.error('misc/function_call.js Binding failed to load');
1819
process.exit(0);

benchmark/util/priority-queue.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ function main({ n, type }) {
1010
const PriorityQueue = require('internal/priority_queue');
1111
const queue = new PriorityQueue();
1212
bench.start();
13-
for (var i = 0; i < n; i++)
13+
for (let i = 0; i < n; i++)
1414
queue.insert(Math.random() * 1e7 | 0);
15-
for (i = 0; i < n; i++)
15+
for (let i = 0; i < n; i++)
1616
queue.shift();
1717
bench.end(n);
1818
}

lib/dgram.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ function Socket(type, listener) {
9191
let recvBufferSize;
9292
let sendBufferSize;
9393

94+
let options;
9495
if (type !== null && typeof type === 'object') {
95-
var options = type;
96+
options = type;
9697
type = options.type;
9798
lookup = options.lookup;
9899
recvBufferSize = options.recvBufferSize;

lib/internal/child_process.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ function setupChannel(target, channel) {
693693
options = { swallowErrors: options };
694694
}
695695

696+
let obj;
697+
696698
// Package messages with a handle object
697699
if (handle) {
698700
// This message will be handled by an internalMessage event handler
@@ -727,7 +729,7 @@ function setupChannel(target, channel) {
727729
return this._handleQueue.length === 1;
728730
}
729731

730-
var obj = handleConversion[message.type];
732+
obj = handleConversion[message.type];
731733

732734
// convert TCP object to native handle object
733735
handle = handleConversion[message.type].send.call(target,

lib/internal/util.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,13 @@ promisify.custom = kCustomPromisifiedSymbol;
316316
function join(output, separator) {
317317
let str = '';
318318
if (output.length !== 0) {
319-
for (var i = 0; i < output.length - 1; i++) {
319+
const lastIndex = output.length - 1;
320+
for (let i = 0; i < lastIndex; i++) {
320321
// It is faster not to use a template string here
321322
str += output[i];
322323
str += separator;
323324
}
324-
str += output[i];
325+
str += output[lastIndex];
325326
}
326327
return str;
327328
}

lib/internal/util/inspect.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ function strEscape(str) {
312312

313313
let result = '';
314314
let last = 0;
315-
for (var i = 0; i < str.length; i++) {
315+
const lastIndex = str.length;
316+
for (let i = 0; i < lastIndex; i++) {
316317
const point = str.charCodeAt(i);
317318
if (point === singleQuote || point === 92 || point < 32) {
318319
if (last === i) {
@@ -324,7 +325,7 @@ function strEscape(str) {
324325
}
325326
}
326327

327-
if (last !== i) {
328+
if (last !== lastIndex) {
328329
result += str.slice(last);
329330
}
330331
return addQuotes(result, singleQuote);
@@ -1059,10 +1060,11 @@ function formatPrimitive(fn, value, ctx) {
10591060
if (matches.length > 1) {
10601061
const indent = ' '.repeat(ctx.indentationLvl);
10611062
let res = `${fn(strEscape(matches[0]), 'string')} +\n`;
1062-
for (var i = 1; i < matches.length - 1; i++) {
1063+
const lastIndex = matches.length - 1;
1064+
for (let i = 1; i < lastIndex; i++) {
10631065
res += `${indent} ${fn(strEscape(matches[i]), 'string')} +\n`;
10641066
}
1065-
res += `${indent} ${fn(strEscape(matches[i]), 'string')}`;
1067+
res += `${indent} ${fn(strEscape(matches[lastIndex]), 'string')}`;
10661068
return res;
10671069
}
10681070
}
@@ -1185,10 +1187,10 @@ function formatTypedArray(ctx, value, recurseTimes) {
11851187
const elementFormatter = value.length > 0 && typeof value[0] === 'number' ?
11861188
formatNumber :
11871189
formatBigInt;
1188-
for (var i = 0; i < maxLength; ++i)
1190+
for (let i = 0; i < maxLength; ++i)
11891191
output[i] = elementFormatter(ctx.stylize, value[i]);
11901192
if (remaining > 0) {
1191-
output[i] = `... ${remaining} more item${remaining > 1 ? 's' : ''}`;
1193+
output[maxLength] = `... ${remaining} more item${remaining > 1 ? 's' : ''}`;
11921194
}
11931195
if (ctx.showHidden) {
11941196
// .buffer goes last, it's not a primitive like the others.

lib/url.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
267267
// user@server is *always* interpreted as a hostname, and url
268268
// resolution will treat //foo/bar as host=foo,path=bar because that's
269269
// how the browser resolves relative URLs.
270+
let slashes;
270271
if (slashesDenoteHost || proto || hostPattern.test(rest)) {
271-
var slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
272-
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
272+
slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
273+
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
273274
if (slashes && !(proto && hostlessProtocol.has(lowerProto))) {
274275
rest = rest.slice(2);
275276
this.slashes = true;

0 commit comments

Comments
 (0)