Skip to content

Commit 19a363d

Browse files
Merge pull request #305 from justinkalland/fix-no-case-declarations
Wrap lexical declarations inside switch cases
2 parents e21a380 + dd86140 commit 19a363d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/client/udp-tracker.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class UDPTracker extends Tracker {
129129
const action = msg.readUInt32BE(0)
130130
debug('UDP response %s, action %s', self.announceUrl, action)
131131
switch (action) {
132-
case 0: // handshake
132+
case 0: { // handshake
133133
// Note: no check for `self.destroyed` so that pending messages to the
134134
// tracker can still be sent/received even after destroy() is called
135135

@@ -139,8 +139,8 @@ class UDPTracker extends Tracker {
139139
else announce(msg.slice(8, 16), opts)
140140

141141
break
142-
143-
case 1: // announce
142+
}
143+
case 1: { // announce
144144
cleanup()
145145
if (self.destroyed) return
146146

@@ -166,8 +166,8 @@ class UDPTracker extends Tracker {
166166
})
167167

168168
break
169-
170-
case 2: // scrape
169+
}
170+
case 2: { // scrape
171171
cleanup()
172172
if (self.destroyed) return
173173

@@ -189,16 +189,16 @@ class UDPTracker extends Tracker {
189189
}
190190

191191
break
192-
193-
case 3: // error
192+
}
193+
case 3: { // error
194194
cleanup()
195195
if (self.destroyed) return
196196

197197
if (msg.length < 8) return onError(new Error('invalid error message'))
198198
self.client.emit('warning', new Error(msg.slice(8).toString()))
199199

200200
break
201-
201+
}
202202
default:
203203
onError(new Error('tracker sent invalid action'))
204204
break

server.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,15 @@ Server.Swarm = Swarm
750750
function makeUdpPacket (params) {
751751
let packet
752752
switch (params.action) {
753-
case common.ACTIONS.CONNECT:
753+
case common.ACTIONS.CONNECT: {
754754
packet = Buffer.concat([
755755
common.toUInt32(common.ACTIONS.CONNECT),
756756
common.toUInt32(params.transactionId),
757757
params.connectionId
758758
])
759759
break
760-
case common.ACTIONS.ANNOUNCE:
760+
}
761+
case common.ACTIONS.ANNOUNCE: {
761762
packet = Buffer.concat([
762763
common.toUInt32(common.ACTIONS.ANNOUNCE),
763764
common.toUInt32(params.transactionId),
@@ -767,7 +768,8 @@ function makeUdpPacket (params) {
767768
params.peers
768769
])
769770
break
770-
case common.ACTIONS.SCRAPE:
771+
}
772+
case common.ACTIONS.SCRAPE: {
771773
const scrapeResponse = [
772774
common.toUInt32(common.ACTIONS.SCRAPE),
773775
common.toUInt32(params.transactionId)
@@ -782,13 +784,15 @@ function makeUdpPacket (params) {
782784
}
783785
packet = Buffer.concat(scrapeResponse)
784786
break
785-
case common.ACTIONS.ERROR:
787+
}
788+
case common.ACTIONS.ERROR: {
786789
packet = Buffer.concat([
787790
common.toUInt32(common.ACTIONS.ERROR),
788791
common.toUInt32(params.transactionId || 0),
789792
Buffer.from(String(params['failure reason']))
790793
])
791794
break
795+
}
792796
default:
793797
throw new Error(`Action not implemented: ${params.action}`)
794798
}

0 commit comments

Comments
 (0)