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

tools: enable block-scoped-var eslint rule #27616

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = {
'array-callback-return': 'error',
'arrow-parens': ['error', 'always'],
'arrow-spacing': ['error', { before: true, after: true }],
'block-scoped-var': 'error',
silverwind marked this conversation as resolved.
Show resolved Hide resolved
'block-spacing': 'error',
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
'capitalized-comments': ['error', 'always', {
Expand Down
3 changes: 2 additions & 1 deletion benchmark/fixtures/simple-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const storedUnicode = Object.create(null);
const useDomains = process.env.NODE_USE_DOMAINS;

// Set up one global domain.
let domain;

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

if (useDomains) {
var domain = require('domain');
domain = require('domain');
const gdom = domain.create();
gdom.on('error', (er) => {
console.error('Error on global domain', er);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/http/_chunky_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function main({ len, n }) {
const headers = [];
// Chose 7 because 9 showed "Connection error" / "Connection closed"
// An odd number could result in a better length dispersion.
for (var i = 7; i <= 7 * 7 * 7; i *= 7)
for (let i = 7; i <= 7 * 7 * 7; i *= 7)
headers.push('o'.repeat(i));

function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) {
Expand All @@ -31,7 +31,7 @@ function main({ len, n }) {
'Chrome/39.0.2171.71 Safari/537.36');
todo.push('Accept-Encoding: gzip, deflate, sdch');
todo.push('Accept-Language: en-US,en;q=0.8');
for (var i = 0; i < extra_header_count; i++) {
for (let i = 0; i < extra_header_count; i++) {
// Utilize first three powers of a small integer for an odd cycle and
// because the fourth power of some integers overloads the server.
todo.push(`X-Header-${i}: ${headers[i % 3]}`);
Expand All @@ -41,7 +41,7 @@ function main({ len, n }) {
todo = todo.join('\r\n');
// Using odd numbers in many places may increase length coverage.
const chunksize = 37;
for (i = 0; i < todo.length; i += chunksize) {
for (let i = 0; i < todo.length; i += chunksize) {
const cur = todo.slice(i, i + chunksize);
channel.write(cur);
}
Expand Down
3 changes: 2 additions & 1 deletion benchmark/http/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const common = require('../common.js');
const PORT = common.PORT;

const cluster = require('cluster');
let bench;
if (cluster.isMaster) {
var bench = common.createBenchmark(main, {
bench = common.createBenchmark(main, {
// Unicode confuses ab on os x.
type: ['bytes', 'buffer'],
len: [4, 1024, 102400],
Expand Down
3 changes: 2 additions & 1 deletion benchmark/napi/function_call/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const common = require('../../common.js');
// which is quite common for benchmarks. so in that case, just
// abort quietly.

let binding;
try {
var binding = require(`./build/${common.buildType}/binding`);
binding = require(`./build/${common.buildType}/binding`);
} catch {
console.error('misc/function_call.js Binding failed to load');
process.exit(0);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/util/priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ function main({ n, type }) {
const PriorityQueue = require('internal/priority_queue');
const queue = new PriorityQueue();
bench.start();
for (var i = 0; i < n; i++)
for (let i = 0; i < n; i++)
queue.insert(Math.random() * 1e7 | 0);
for (i = 0; i < n; i++)
for (let i = 0; i < n; i++)
queue.shift();
bench.end(n);
}
3 changes: 2 additions & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ function Socket(type, listener) {
let recvBufferSize;
let sendBufferSize;

let options;
if (type !== null && typeof type === 'object') {
var options = type;
options = type;
type = options.type;
lookup = options.lookup;
recvBufferSize = options.recvBufferSize;
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ function setupChannel(target, channel) {
options = { swallowErrors: options };
}

let obj;

// Package messages with a handle object
if (handle) {
// This message will be handled by an internalMessage event handler
Expand Down Expand Up @@ -727,7 +729,7 @@ function setupChannel(target, channel) {
return this._handleQueue.length === 1;
}

var obj = handleConversion[message.type];
obj = handleConversion[message.type];

// convert TCP object to native handle object
handle = handleConversion[message.type].send.call(target,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ promisify.custom = kCustomPromisifiedSymbol;
function join(output, separator) {
let str = '';
if (output.length !== 0) {
for (var i = 0; i < output.length - 1; i++) {
let i;
for (i = 0; i < output.length - 1; i++) {
silverwind marked this conversation as resolved.
Show resolved Hide resolved
// It is faster not to use a template string here
str += output[i];
str += separator;
Expand Down
9 changes: 6 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ function strEscape(str) {

let result = '';
let last = 0;
for (var i = 0; i < str.length; i++) {
let i;
for (i = 0; i < str.length; i++) {
const point = str.charCodeAt(i);
if (point === singleQuote || point === 92 || point < 32) {
if (last === i) {
Expand Down Expand Up @@ -1061,7 +1062,8 @@ function formatPrimitive(fn, value, ctx) {
if (matches.length > 1) {
const indent = ' '.repeat(ctx.indentationLvl);
let res = `${fn(strEscape(matches[0]), 'string')} +\n`;
for (var i = 1; i < matches.length - 1; i++) {
let i;
for (i = 1; i < matches.length - 1; i++) {
res += `${indent} ${fn(strEscape(matches[i]), 'string')} +\n`;
}
res += `${indent} ${fn(strEscape(matches[i]), 'string')}`;
Expand Down Expand Up @@ -1187,7 +1189,8 @@ function formatTypedArray(ctx, value, recurseTimes) {
const elementFormatter = value.length > 0 && typeof value[0] === 'number' ?
formatNumber :
formatBigInt;
for (var i = 0; i < maxLength; ++i)
let i;
for (i = 0; i < maxLength; ++i)
output[i] = elementFormatter(ctx.stylize, value[i]);
if (remaining > 0) {
output[i] = `... ${remaining} more item${remaining > 1 ? 's' : ''}`;
Expand Down
5 changes: 3 additions & 2 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
// user@server is *always* interpreted as a hostname, and url
// resolution will treat //foo/bar as host=foo,path=bar because that's
// how the browser resolves relative URLs.
let slashes;
if (slashesDenoteHost || proto || hostPattern.test(rest)) {
var slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
if (slashes && !(proto && hostlessProtocol.has(lowerProto))) {
rest = rest.slice(2);
this.slashes = true;
Expand Down