From f2244015659fd41d3d04dbef2beebc4a1b058330 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 1 Apr 2022 21:14:01 -0700 Subject: [PATCH 1/2] lib: prepare files for no-var lint rule --- lib/internal/crypto/util.js | 2 +- lib/internal/dns/promises.js | 12 ++++++------ lib/internal/http2/util.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 9492409e3a6437..854994277e5d30 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -71,7 +71,7 @@ function lazyRequire(name) { return ret; } -var defaultEncoding = 'buffer'; +let defaultEncoding = 'buffer'; function setDefaultEncoding(val) { defaultEncoding = val; diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 314b121be5d152..68fcb29745e92d 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -67,7 +67,7 @@ function onlookupall(err, addresses) { const family = this.family; - for (var i = 0; i < addresses.length; i++) { + for (let i = 0; i < addresses.length; i++) { const address = addresses[i]; addresses[i] = { @@ -121,10 +121,10 @@ function createLookupPromise(family, hostname, all, hints, verbatim) { } function lookup(hostname, options) { - var hints = 0; - var family = -1; - var all = false; - var verbatim = getDefaultVerbatim(); + let hints = 0; + let family = -1; + let all = false; + let verbatim = getDefaultVerbatim(); // Parse arguments if (hostname) { @@ -297,7 +297,7 @@ Resolver.prototype.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr'); Resolver.prototype.resolveSoa = resolveMap.SOA = resolver('querySoa'); Resolver.prototype.reverse = resolver('getHostByAddr'); Resolver.prototype.resolve = function resolve(hostname, rrtype) { - var resolver; + let resolver; if (rrtype !== undefined) { validateString(rrtype, 'rrtype'); diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 38578d2a151c52..962bdd753c2717 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -588,7 +588,7 @@ const assertWithinRange = hideStackFrames( function toHeaderObject(headers, sensitiveHeaders) { const obj = ObjectCreate(null); - for (var n = 0; n < headers.length; n += 2) { + for (let n = 0; n < headers.length; n += 2) { const name = headers[n]; let value = headers[n + 1]; if (name === HTTP2_HEADER_STATUS) From 0a6e197d8f6f3abb902f293b78d08ff3055a5873 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 1 Apr 2022 21:18:40 -0700 Subject: [PATCH 2/2] tools: enable no-var ESLint rule for lib --- .eslintrc.js | 1 + benchmark/.eslintrc.yaml | 1 - doc/.eslintrc.yaml | 1 - lib/internal/async_hooks.js | 2 ++ lib/internal/js_stream_socket.js | 1 + test/.eslintrc.yaml | 1 - tools/.eslintrc.yaml | 1 - 7 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d44e3f1414f438..97affb91c0c18e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -260,6 +260,7 @@ module.exports = { 'no-useless-concat': 'error', 'no-useless-constructor': 'error', 'no-useless-return': 'error', + 'no-var': 'error', 'no-void': 'error', 'no-whitespace-before-property': 'error', 'object-curly-newline': 'error', diff --git a/benchmark/.eslintrc.yaml b/benchmark/.eslintrc.yaml index 6871299adece7b..aa014eec4e3627 100644 --- a/benchmark/.eslintrc.yaml +++ b/benchmark/.eslintrc.yaml @@ -5,5 +5,4 @@ env: es6: true rules: - no-var: error prefer-arrow-callback: error diff --git a/doc/.eslintrc.yaml b/doc/.eslintrc.yaml index fbc115669a7166..e8d24adb6e00aa 100644 --- a/doc/.eslintrc.yaml +++ b/doc/.eslintrc.yaml @@ -9,7 +9,6 @@ rules: symbol-description: off # Add new ECMAScript features gradually - no-var: error prefer-const: error prefer-rest-params: error prefer-template: error diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index ebc9254d5c5109..107aab227e4637 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -196,6 +196,7 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) { try { // Using var here instead of let because "for (var ...)" is faster than let. // Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364 + // eslint-disable-next-line no-var for (var i = 0; i < active_hooks.array.length; i++) { if (typeof active_hooks.array[i][init_symbol] === 'function') { active_hooks.array[i][init_symbol]( @@ -228,6 +229,7 @@ function emitHook(symbol, asyncId) { try { // Using var here instead of let because "for (var ...)" is faster than let. // Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364 + // eslint-disable-next-line no-var for (var i = 0; i < active_hooks.array.length; i++) { if (typeof active_hooks.array[i][symbol] === 'function') { active_hooks.array[i][symbol](asyncId); diff --git a/lib/internal/js_stream_socket.js b/lib/internal/js_stream_socket.js index faad988e820ffa..f2a0ecaa1d8a65 100644 --- a/lib/internal/js_stream_socket.js +++ b/lib/internal/js_stream_socket.js @@ -171,6 +171,7 @@ class JSStreamSocket extends Socket { this.stream.cork(); // Use `var` over `let` for performance optimization. + // eslint-disable-next-line no-var for (var i = 0; i < bufs.length; ++i) this.stream.write(bufs[i], done); this.stream.uncork(); diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index 878ea7b975df11..e8295cd3e23621 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -6,7 +6,6 @@ env: rules: multiline-comment-style: [error, separate-lines] - no-var: error prefer-const: error symbol-description: off diff --git a/tools/.eslintrc.yaml b/tools/.eslintrc.yaml index de30cf6d123f33..d9a7929836d91f 100644 --- a/tools/.eslintrc.yaml +++ b/tools/.eslintrc.yaml @@ -12,4 +12,3 @@ rules: - error - args: after-used prefer-arrow-callback: error - no-var: error