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

JS: Require curly braces in switch cases #1268

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions node/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ 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.
'no-restricted-syntax' : [ 2,
{
'selector' : 'SwitchCase > *.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