Skip to content

Commit

Permalink
JS: Require curly braces in switch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Dec 15, 2023
1 parent bc55f22 commit c276707
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 1 deletion.
10 changes: 10 additions & 0 deletions node/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ const eslintConfig =
'computed-property-spacing' : 2,
'constructor-super' : 2,
'curly' : [ 2, 'all' ],
// Unfortunatelly `curly` does not apply to blocks in `switch` cases so
// this is needed.
// NOTE: We disable this rule since it's producing false positives:
// link
// 'no-restricted-syntax' : [ 2,
// {
// 'selector' : 'SwitchCase:has(*.consequent[type!="BlockStatement"])',
// 'message' : 'Switch cases without blocks are disallowed'
// }
// ],
'func-call-spacing' : 2,
'generator-star-spacing' : 2,
'guard-for-in' : 2,
Expand Down
22 changes: 21 additions & 1 deletion node/src/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ export class Channel extends EnhancedEventEmitter
}

default:
{
// eslint-disable-next-line no-console
console.warn(
`worker[pid:${pid}] unexpected data: %s`,
payload.toString('utf8', 1));
payload.toString('utf8', 1)
);
}
}
}
catch (error)
Expand Down Expand Up @@ -432,11 +435,16 @@ export class Channel extends EnhancedEventEmitter
switch (response.error()!)
{
case 'TypeError':
{
sent.reject(new TypeError(response.reason()!));

break;
}

default:
{
sent.reject(new Error(response.reason()!));
}
}
}
else
Expand Down Expand Up @@ -470,24 +478,36 @@ export class Channel extends EnhancedEventEmitter
{
// 'D' (a debug log).
case 'D':
{
logger.debug(`[pid:${pid}] ${logData.slice(1)}`);

break;
}

// 'W' (a warn log).
case 'W':
{
logger.warn(`[pid:${pid}] ${logData.slice(1)}`);

break;
}

// 'E' (a error log).
case 'E':
{
logger.error(`[pid:${pid}] ${logData.slice(1)}`);

break;
}

// 'X' (a dump log).
case 'X':
{
// eslint-disable-next-line no-console
console.log(logData.slice(1));

break;
}
}
}
}
34 changes: 34 additions & 0 deletions node/src/Consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,17 +999,34 @@ function consumerTraceEventTypeToFbs(eventType: ConsumerTraceEventType)
switch (eventType)
{
case 'keyframe':
{
return FbsConsumer.TraceEventType.KEYFRAME;
}

case 'fir':
{
return FbsConsumer.TraceEventType.FIR;
}

case 'nack':
{
return FbsConsumer.TraceEventType.NACK;
}

case 'pli':
{
return FbsConsumer.TraceEventType.PLI;
}

case 'rtp':
{
return FbsConsumer.TraceEventType.RTP;
}

default:
{
throw new TypeError(`invalid ConsumerTraceEventType: ${eventType}`);
}
}
}

Expand All @@ -1019,17 +1036,34 @@ function consumerTraceEventTypeFromFbs(traceType: FbsConsumer.TraceEventType)
switch (traceType)
{
case FbsConsumer.TraceEventType.KEYFRAME:
{
return 'keyframe';
}

case FbsConsumer.TraceEventType.FIR:
{
return 'fir';
}

case FbsConsumer.TraceEventType.NACK:
{
return 'nack';
}

case FbsConsumer.TraceEventType.PLI:
{
return 'pli';
}

case FbsConsumer.TraceEventType.RTP:
{
return 'rtp';
}

default:
{
throw new TypeError(`invalid FbsConsumer.TraceEventType: ${traceType}`);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions node/src/DataConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,19 @@ export function dataConsumerTypeToFbs(type: DataConsumerType): FbsDataProducer.T
switch (type)
{
case 'sctp':
{
return FbsDataProducer.Type.SCTP;
}

case 'direct':
{
return FbsDataProducer.Type.DIRECT;
}

default:
{
throw new TypeError('invalid DataConsumerType: ${type}');
}
}
}

Expand All @@ -775,9 +783,14 @@ export function dataConsumerTypeFromFbs(type: FbsDataProducer.Type): DataConsume
switch (type)
{
case FbsDataProducer.Type.SCTP:
{
return 'sctp';
}

case FbsDataProducer.Type.DIRECT:
{
return 'direct';
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions node/src/DataProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,19 @@ export function dataProducerTypeToFbs(type: DataProducerType): FbsDataProducer.T
switch (type)
{
case 'sctp':
{
return FbsDataProducer.Type.SCTP;
}

case 'direct':
{
return FbsDataProducer.Type.DIRECT;
}

default:
{
throw new TypeError('invalid DataConsumerType: ${type}');
}
}
}

Expand All @@ -488,9 +496,14 @@ export function dataProducerTypeFromFbs(type: FbsDataProducer.Type): DataProduce
switch (type)
{
case FbsDataProducer.Type.SCTP:
{
return 'sctp';
}

case FbsDataProducer.Type.DIRECT:
{
return 'direct';
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions node/src/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,24 @@ export function producerTypeFromFbs(type: FbsRtpParameters.Type): ProducerType
switch (type)
{
case FbsRtpParameters.Type.SIMPLE:
{
return 'simple';
}

case FbsRtpParameters.Type.SIMULCAST:
{
return 'simulcast';
}

case FbsRtpParameters.Type.SVC:
{
return 'svc';
}

default:
{
throw new TypeError(`invalid FbsRtpParameters.Type: ${type}`);
}
}
}

Expand All @@ -645,13 +656,19 @@ export function producerTypeToFbs(type: ProducerType): FbsRtpParameters.Type
switch (type)
{
case 'simple':
{
return FbsRtpParameters.Type.SIMPLE;
}

case 'simulcast':
{
return FbsRtpParameters.Type.SIMULCAST;
}

case 'svc':
{
return FbsRtpParameters.Type.SVC;
}
}
}

Expand All @@ -661,17 +678,34 @@ function producerTraceEventTypeToFbs(eventType: ProducerTraceEventType)
switch (eventType)
{
case 'keyframe':
{
return FbsProducer.TraceEventType.KEYFRAME;
}

case 'fir':
{
return FbsProducer.TraceEventType.FIR;
}

case 'nack':
{
return FbsProducer.TraceEventType.NACK;
}

case 'pli':
{
return FbsProducer.TraceEventType.PLI;
}

case 'rtp':
{
return FbsProducer.TraceEventType.RTP;
}

default:
{
throw new TypeError(`invalid ProducerTraceEventType: ${eventType}`);
}
}
}

Expand All @@ -681,15 +715,29 @@ function producerTraceEventTypeFromFbs(eventType: FbsProducer.TraceEventType)
switch (eventType)
{
case FbsProducer.TraceEventType.KEYFRAME:
{
return 'keyframe';
}

case FbsProducer.TraceEventType.FIR:
{
return 'fir';
}

case FbsProducer.TraceEventType.NACK:
{
return 'nack';
}

case FbsProducer.TraceEventType.PLI:
{
return 'pli';
}

case FbsProducer.TraceEventType.RTP:
{
return 'rtp';
}
}
}

Expand Down
Loading

0 comments on commit c276707

Please sign in to comment.