GeezerVison is showing github.com — tools,benchmark,lib,test: enable no-case-declarations lint rule · nodejs/node@800640a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -175,6 +175,7 @@ module.exports = { | 175 | 175 | }], | 176 | 176 | 'new-parens': 'error', | 177 | 177 | 'no-async-promise-executor': 'error', | | 178 | + 'no-case-declarations': 'error', | 178 | 179 | 'no-class-assign': 'error', | 179 | 180 | 'no-confusing-arrow': 'error', | 180 | 181 | 'no-const-assign': 'error', | |
Collapse file Copy file name to clipboardExpand all lines: benchmark/zlib/inflate.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ function main({ n, method, inputLen }) { | 16 | 16 | let i = 0; | 17 | 17 | switch (method) { | 18 | 18 | // Performs `n` single inflate operations | 19 | | - case 'inflate': | | 19 | + case 'inflate': { | 20 | 20 | const inflate = zlib.inflate; | 21 | 21 | bench.start(); | 22 | 22 | (function next(err, result) { | @@ -25,14 +25,16 @@ function main({ n, method, inputLen }) { | 25 | 25 | inflate(chunk, next); | 26 | 26 | })(); | 27 | 27 | break; | | 28 | + } | 28 | 29 | // Performs `n` single inflateSync operations | 29 | | - case 'inflateSync': | | 30 | + case 'inflateSync': { | 30 | 31 | const inflateSync = zlib.inflateSync; | 31 | 32 | bench.start(); | 32 | 33 | for (; i < n; ++i) | 33 | 34 | inflateSync(chunk); | 34 | 35 | bench.end(n); | 35 | 36 | break; | | 37 | + } | 36 | 38 | default: | 37 | 39 | throw new Error('Unsupported inflate method'); | 38 | 40 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_server.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -411,7 +411,7 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) { | 411 | 411 |
| 412 | 412 | Server.prototype[EE.captureRejectionSymbol] = function(err, event, ...args) { | 413 | 413 | switch (event) { | 414 | | - case 'request': | | 414 | + case 'request': { | 415 | 415 | const { 1: res } = args; | 416 | 416 | if (!res.headersSent && !res.writableEnded) { | 417 | 417 | // Don't leak headers. | @@ -425,6 +425,7 @@ Server.prototype[EE.captureRejectionSymbol] = function(err, event, ...args) { | 425 | 425 | res.destroy(); | 426 | 426 | } | 427 | 427 | break; | | 428 | + } | 428 | 429 | default: | 429 | 430 | net.Server.prototype[SymbolFor('nodejs.rejection')] | 430 | 431 | .apply(this, arguments); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/is_main_thread.js +16-8Lines changed: 16 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,20 +42,22 @@ function createWritableStdioStream(fd) { | 42 | 42 | let stream; | 43 | 43 | // Note stream._type is used for test-module-load-list.js | 44 | 44 | switch (guessHandleType(fd)) { | 45 | | - case 'TTY': | | 45 | + case 'TTY': { | 46 | 46 | const tty = require('tty'); | 47 | 47 | stream = new tty.WriteStream(fd); | 48 | 48 | stream._type = 'tty'; | 49 | 49 | break; | | 50 | + } | 50 | 51 |
| 51 | | - case 'FILE': | | 52 | + case 'FILE': { | 52 | 53 | const SyncWriteStream = require('internal/fs/sync_write_stream'); | 53 | 54 | stream = new SyncWriteStream(fd, { autoClose: false }); | 54 | 55 | stream._type = 'fs'; | 55 | 56 | break; | | 57 | + } | 56 | 58 |
| 57 | 59 | case 'PIPE': | 58 | | - case 'TCP': | | 60 | + case 'TCP': { | 59 | 61 | const net = require('net'); | 60 | 62 |
| 61 | 63 | // If fd is already being used for the IPC channel, libuv will return | @@ -78,8 +80,9 @@ function createWritableStdioStream(fd) { | 78 | 80 |
| 79 | 81 | stream._type = 'pipe'; | 80 | 82 | break; | | 83 | + } | 81 | 84 |
| 82 | | - default: | | 85 | + default: { | 83 | 86 | // Provide a dummy black-hole output for e.g. non-console | 84 | 87 | // Windows applications. | 85 | 88 | const { Writable } = require('stream'); | @@ -88,6 +91,7 @@ function createWritableStdioStream(fd) { | 88 | 91 | cb(); | 89 | 92 | } | 90 | 93 | }); | | 94 | + } | 91 | 95 | } | 92 | 96 |
| 93 | 97 | // For supporting legacy API we put the FD here. | @@ -147,18 +151,20 @@ function getStdin() { | 147 | 151 | const fd = 0; | 148 | 152 |
| 149 | 153 | switch (guessHandleType(fd)) { | 150 | | - case 'TTY': | | 154 | + case 'TTY': { | 151 | 155 | const tty = require('tty'); | 152 | 156 | stdin = new tty.ReadStream(fd); | 153 | 157 | break; | | 158 | + } | 154 | 159 |
| 155 | | - case 'FILE': | | 160 | + case 'FILE': { | 156 | 161 | const fs = require('fs'); | 157 | 162 | stdin = new fs.ReadStream(null, { fd: fd, autoClose: false }); | 158 | 163 | break; | | 164 | + } | 159 | 165 |
| 160 | 166 | case 'PIPE': | 161 | | - case 'TCP': | | 167 | + case 'TCP': { | 162 | 168 | const net = require('net'); | 163 | 169 |
| 164 | 170 | // It could be that process has been started with an IPC channel | @@ -183,13 +189,15 @@ function getStdin() { | 183 | 189 | // Make sure the stdin can't be `.end()`-ed | 184 | 190 | stdin._writableState.ended = true; | 185 | 191 | break; | | 192 | + } | 186 | 193 |
| 187 | | - default: | | 194 | + default: { | 188 | 195 | // Provide a dummy contentless input for e.g. non-console | 189 | 196 | // Windows applications. | 190 | 197 | const { Readable } = require('stream'); | 191 | 198 | stdin = new Readable({ read() {} }); | 192 | 199 | stdin.push(null); | | 200 | + } | 193 | 201 | } | 194 | 202 |
| 195 | 203 | // For supporting legacy API we put the FD here. | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/aes.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -189,7 +189,7 @@ function asyncAesGcmCipher( | 189 | 189 | const tagByteLength = MathFloor(tagLength / 8); | 190 | 190 | let tag; | 191 | 191 | switch (mode) { | 192 | | - case kWebCryptoCipherDecrypt: | | 192 | + case kWebCryptoCipherDecrypt: { | 193 | 193 | const slice = ArrayBufferIsView(data) ? | 194 | 194 | TypedArrayPrototypeSlice : ArrayBufferPrototypeSlice; | 195 | 195 | tag = slice(data, -tagByteLength); | @@ -206,6 +206,7 @@ function asyncAesGcmCipher( | 206 | 206 |
| 207 | 207 | data = slice(data, 0, -tagByteLength); | 208 | 208 | break; | | 209 | + } | 209 | 210 | case kWebCryptoCipherEncrypt: | 210 | 211 | tag = tagByteLength; | 211 | 212 | break; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/webcrypto.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -427,7 +427,7 @@ async function importGenericSecretKey( | 427 | 427 |
| 428 | 428 | break; | 429 | 429 | } | 430 | | - case 'raw': | | 430 | + case 'raw': { | 431 | 431 | if (hasAnyNotIn(usagesSet, ['deriveKey', 'deriveBits'])) { | 432 | 432 | throw lazyDOMException( | 433 | 433 | `Unsupported key usage for a ${name} key`, | @@ -449,6 +449,7 @@ async function importGenericSecretKey( | 449 | 449 |
| 450 | 450 | const keyObject = createSecretKey(keyData); | 451 | 451 | return new InternalCryptoKey(keyObject, { name }, keyUsages, false); | | 452 | + } | 452 | 453 | } | 453 | 454 |
| 454 | 455 | throw lazyDOMException( | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/error_serdes.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -120,21 +120,23 @@ let deserialize; | 120 | 120 | function deserializeError(error) { | 121 | 121 | if (!deserialize) deserialize = require('v8').deserialize; | 122 | 122 | switch (error[0]) { | 123 | | - case kSerializedError: | | 123 | + case kSerializedError: { | 124 | 124 | const { constructor, properties } = deserialize(error.subarray(1)); | 125 | 125 | const ctor = errors[constructor]; | 126 | 126 | ObjectDefineProperty(properties, SymbolToStringTag, { | 127 | 127 | value: { value: 'Error', configurable: true }, | 128 | 128 | enumerable: true | 129 | 129 | }); | 130 | 130 | return ObjectCreate(ctor.prototype, properties); | | 131 | + } | 131 | 132 | case kSerializedObject: | 132 | 133 | return deserialize(error.subarray(1)); | 133 | | - case kInspectedError: | | 134 | + case kInspectedError: { | 134 | 135 | const buf = Buffer.from(error.buffer, | 135 | 136 | error.byteOffset + 1, | 136 | 137 | error.byteLength - 1); | 137 | 138 | return buf.toString('utf8'); | | 139 | + } | 138 | 140 | } | 139 | 141 | require('assert').fail('This should not happen'); | 140 | 142 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js +10-5Lines changed: 10 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -217,28 +217,31 @@ const proxySocketHandler = { | 217 | 217 | case 'writable': | 218 | 218 | case 'destroyed': | 219 | 219 | return stream[prop]; | 220 | | - case 'readable': | | 220 | + case 'readable': { | 221 | 221 | if (stream.destroyed) | 222 | 222 | return false; | 223 | 223 | const request = stream[kRequest]; | 224 | 224 | return request ? request.readable : stream.readable; | 225 | | - case 'setTimeout': | | 225 | + } | | 226 | + case 'setTimeout': { | 226 | 227 | const session = stream.session; | 227 | 228 | if (session !== undefined) | 228 | 229 | return FunctionPrototypeBind(session.setTimeout, session); | 229 | 230 | return FunctionPrototypeBind(stream.setTimeout, stream); | | 231 | + } | 230 | 232 | case 'write': | 231 | 233 | case 'read': | 232 | 234 | case 'pause': | 233 | 235 | case 'resume': | 234 | 236 | throw new ERR_HTTP2_NO_SOCKET_MANIPULATION(); | 235 | | - default: | | 237 | + default: { | 236 | 238 | const ref = stream.session !== undefined ? | 237 | 239 | stream.session[kSocket] : stream; | 238 | 240 | const value = ref[prop]; | 239 | 241 | return typeof value === 'function' ? | 240 | 242 | FunctionPrototypeBind(value, ref) : | 241 | 243 | value; | | 244 | + } | 242 | 245 | } | 243 | 246 | }, | 244 | 247 | getPrototypeOf(stream) { | @@ -258,23 +261,25 @@ const proxySocketHandler = { | 258 | 261 | case 'destroy': | 259 | 262 | stream[prop] = value; | 260 | 263 | return true; | 261 | | - case 'setTimeout': | | 264 | + case 'setTimeout': { | 262 | 265 | const session = stream.session; | 263 | 266 | if (session !== undefined) | 264 | 267 | session.setTimeout = value; | 265 | 268 | else | 266 | 269 | stream.setTimeout = value; | 267 | 270 | return true; | | 271 | + } | 268 | 272 | case 'write': | 269 | 273 | case 'read': | 270 | 274 | case 'pause': | 271 | 275 | case 'resume': | 272 | 276 | throw new ERR_HTTP2_NO_SOCKET_MANIPULATION(); | 273 | | - default: | | 277 | + default: { | 274 | 278 | const ref = stream.session !== undefined ? | 275 | 279 | stream.session[kSocket] : stream; | 276 | 280 | ref[prop] = value; | 277 | 281 | return true; | | 282 | + } | 278 | 283 | } | 279 | 284 | } | 280 | 285 | }; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js +10-5Lines changed: 10 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -867,14 +867,15 @@ const proxySocketHandler = { | 867 | 867 | case 'setKeepAlive': | 868 | 868 | case 'setNoDelay': | 869 | 869 | throw new ERR_HTTP2_NO_SOCKET_MANIPULATION(); | 870 | | - default: | | 870 | + default: { | 871 | 871 | const socket = session[kSocket]; | 872 | 872 | if (socket === undefined) | 873 | 873 | throw new ERR_HTTP2_SOCKET_UNBOUND(); | 874 | 874 | const value = socket[prop]; | 875 | 875 | return typeof value === 'function' ? | 876 | 876 | FunctionPrototypeBind(value, socket) : | 877 | 877 | value; | | 878 | + } | 878 | 879 | } | 879 | 880 | }, | 880 | 881 | getPrototypeOf(session) { | @@ -901,12 +902,13 @@ const proxySocketHandler = { | 901 | 902 | case 'setKeepAlive': | 902 | 903 | case 'setNoDelay': | 903 | 904 | throw new ERR_HTTP2_NO_SOCKET_MANIPULATION(); | 904 | | - default: | | 905 | + default: { | 905 | 906 | const socket = session[kSocket]; | 906 | 907 | if (socket === undefined) | 907 | 908 | throw new ERR_HTTP2_SOCKET_UNBOUND(); | 908 | 909 | socket[prop] = value; | 909 | 910 | return true; | | 911 | + } | 910 | 912 | } | 911 | 913 | } | 912 | 914 | }; | @@ -1558,10 +1560,11 @@ class Http2Session extends EventEmitter { | 1558 | 1560 |
| 1559 | 1561 | [EventEmitter.captureRejectionSymbol](err, event, ...args) { | 1560 | 1562 | switch (event) { | 1561 | | - case 'stream': | | 1563 | + case 'stream': { | 1562 | 1564 | const stream = args[0]; | 1563 | 1565 | stream.destroy(err); | 1564 | 1566 | break; | | 1567 | + } | 1565 | 1568 | default: | 1566 | 1569 | this.destroy(err); | 1567 | 1570 | } | @@ -3184,7 +3187,7 @@ Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function( | 3184 | 3187 | err, event, ...args) { | 3185 | 3188 |
| 3186 | 3189 | switch (event) { | 3187 | | - case 'stream': | | 3190 | + case 'stream': { | 3188 | 3191 | // TODO(mcollina): we might want to match this with what we do on | 3189 | 3192 | // the compat side. | 3190 | 3193 | const { 0: stream } = args; | @@ -3195,7 +3198,8 @@ Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function( | 3195 | 3198 | stream.end(); | 3196 | 3199 | } | 3197 | 3200 | break; | 3198 | | - case 'request': | | 3201 | + } | | 3202 | + case 'request': { | 3199 | 3203 | const { 1: res } = args; | 3200 | 3204 | if (!res.headersSent && !res.finished) { | 3201 | 3205 | // Don't leak headers. | @@ -3208,6 +3212,7 @@ Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function( | 3208 | 3212 | res.destroy(); | 3209 | 3213 | } | 3210 | 3214 | break; | | 3215 | + } | 3211 | 3216 | default: | 3212 | 3217 | ArrayPrototypeUnshift(args, err, event); | 3213 | 3218 | ReflectApply(net.Server.prototype[EventEmitter.captureRejectionSymbol], | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/repl/utils.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,14 +110,15 @@ function isRecoverableError(e, code) { | 110 | 110 | recoverable = true; | 111 | 111 | break; | 112 | 112 |
| 113 | | - case 'Unterminated string constant': | | 113 | + case 'Unterminated string constant': { | 114 | 114 | const token = StringPrototypeSlice(this.input, | 115 | 115 | this.lastTokStart, this.pos); | 116 | 116 | // See https://www.ecma-international.org/ecma-262/#sec-line-terminators | 117 | 117 | if (RegExpPrototypeTest(/\\(?:\r\n?|\n|\u2028|\u2029)$/, | 118 | 118 | token)) { | 119 | 119 | recoverable = true; | 120 | 120 | } | | 121 | + } | 121 | 122 | } | 122 | 123 | super.raise(pos, message); | 123 | 124 | } | |
|