Skip to content

Commit

Permalink
fix lint after aegir upgrade (libp2p#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckousik authored Feb 22, 2023
1 parent 7e0b1c0 commit b962b2e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"@protobuf-ts/plugin": "^2.8.0",
"@protobuf-ts/protoc": "^2.8.0",
"aegir": "^38.1.6",
"eslint-plugin-etc": "^2.0.2",
"it-first": "^2.0.0",
"libp2p": "^0.41.0"
}
Expand Down
18 changes: 9 additions & 9 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ConnectionClosedError extends WebRTCTransportError {
}
}

export function connectionClosedError (state: RTCPeerConnectionState, msg: string) {
export function connectionClosedError (state: RTCPeerConnectionState, msg: string): Error {
return errCode(new ConnectionClosedError(state, msg), codes.ERR_CONNECTION_CLOSED)
}

Expand All @@ -39,7 +39,7 @@ export class DataChannelError extends WebRTCTransportError {
}
}

export function dataChannelError (streamLabel: string, msg: string) {
export function dataChannelError (streamLabel: string, msg: string): Error {
return errCode(new DataChannelError(streamLabel, msg), codes.ERR_DATA_CHANNEL)
}

Expand All @@ -50,7 +50,7 @@ export class InappropriateMultiaddrError extends WebRTCTransportError {
}
}

export function inappropriateMultiaddr (msg: string) {
export function inappropriateMultiaddr (msg: string): Error {
return errCode(new InappropriateMultiaddrError(msg), codes.ERR_INVALID_MULTIADDR)
}

Expand All @@ -61,7 +61,7 @@ export class InvalidArgumentError extends WebRTCTransportError {
}
}

export function invalidArgument (msg: string) {
export function invalidArgument (msg: string): Error {
return errCode(new InvalidArgumentError(msg), codes.ERR_INVALID_PARAMETERS)
}

Expand All @@ -72,7 +72,7 @@ export class InvalidFingerprintError extends WebRTCTransportError {
}
}

export function invalidFingerprint (fingerprint: string, source: string) {
export function invalidFingerprint (fingerprint: string, source: string): Error {
return errCode(new InvalidFingerprintError(fingerprint, source), codes.ERR_INVALID_FINGERPRINT)
}

Expand All @@ -83,7 +83,7 @@ export class OperationAbortedError extends WebRTCTransportError {
}
}

export function operationAborted (context: string, reason: string) {
export function operationAborted (context: string, reason: string): Error {
return errCode(new OperationAbortedError(context, reason), codes.ERR_ALREADY_ABORTED)
}

Expand All @@ -94,7 +94,7 @@ export class OverStreamLimitError extends WebRTCTransportError {
}
}

export function overStreamLimit (dir: Direction, proto: string) {
export function overStreamLimit (dir: Direction, proto: string): Error {
const code = dir === 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS
return errCode(new OverStreamLimitError(`${dir} stream limit reached for protocol - ${proto}`), code)
}
Expand All @@ -106,7 +106,7 @@ export class UnimplementedError extends WebRTCTransportError {
}
}

export function unimplemented (methodName: string) {
export function unimplemented (methodName: string): Error {
return errCode(new UnimplementedError(methodName), codes.ERR_NOT_IMPLEMENTED)
}

Expand All @@ -118,6 +118,6 @@ export class UnsupportedHashAlgorithmError extends WebRTCTransportError {
}
}

export function unsupportedHashAlgorithm (algorithm: string) {
export function unsupportedHashAlgorithm (algorithm: string): Error {
return errCode(new UnsupportedHashAlgorithmError(algorithm), codes.ERR_HASH_NOT_SUPPORTED)
}
8 changes: 4 additions & 4 deletions src/maconn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
/**
* WebRTC Peer Connection
*/
readonly peerConnection: RTCPeerConnection;
readonly peerConnection: RTCPeerConnection

/**
* The multiaddr address used to communicate with the remote peer
*/
remoteAddr: Multiaddr;
remoteAddr: Multiaddr

/**
* Holds the lifecycle times of the connection
*/
timeline: MultiaddrConnectionTimeline;
timeline: MultiaddrConnectionTimeline

/**
* The stream source, a no-op as the transport natively supports multiplexing
Expand All @@ -48,7 +48,7 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
sink: Sink<Uint8Array, Promise<void>> = nopSink;
sink: Sink<Uint8Array, Promise<void>> = nopSink

constructor (init: WebRTCMultiaddrConnectionInit) {
this.remoteAddr = init.remoteAddr
Expand Down
4 changes: 2 additions & 2 deletions src/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class DataChannelMuxer implements StreamMuxer {
/**
* The stream source, a no-op as the transport natively supports multiplexing
*/
source: Source<Uint8Array> = nopSource;
source: Source<Uint8Array> = nopSource

/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
sink: Sink<Uint8Array, Promise<void>> = nopSink;
sink: Sink<Uint8Array, Promise<void>> = nopSink

constructor (peerConnection: RTCPeerConnection, init?: StreamMuxerInit) {
/**
Expand Down
3 changes: 2 additions & 1 deletion src/sdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '@libp2p/logger'
import type { Multiaddr } from '@multiformats/multiaddr'
import { bases } from 'multiformats/basics'
import * as multihashes from 'multihashes'
import type { HashCode, HashName } from 'multihashes'

import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithm } from './error.js'
import { CERTHASH_CODE } from './transport.js'
Expand Down Expand Up @@ -44,7 +45,7 @@ export function certhash (ma: Multiaddr): string {
/**
* Convert a certhash into a multihash
*/
export function decodeCerthash (certhash: string) {
export function decodeCerthash (certhash: string): { code: HashCode, name: HashName, length: number, digest: Uint8Array } {
const mbdecoded = mbdecoder.decode(certhash)
return multihashes.decode(mbdecoded)
}
Expand Down
22 changes: 11 additions & 11 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,55 +156,55 @@ export class WebRTCStream implements Stream {
/**
* Unique identifier for a stream
*/
id: string;
id: string

/**
* Stats about this stream
*/
stat: StreamStat;
stat: StreamStat

/**
* User defined stream metadata
*/
metadata: Record<string, any>;
metadata: Record<string, any>

/**
* The data channel used to send and receive data
*/
private readonly channel: RTCDataChannel;
private readonly channel: RTCDataChannel

/**
* The current state of the stream
*/
streamState = new StreamState();
streamState = new StreamState()

/**
* Read unwrapped protobuf data from the underlying datachannel.
* _src is exposed to the user via the `source` getter to .
*/
private readonly _src: Source<Uint8ArrayList>;
private readonly _src: Source<Uint8ArrayList>

/**
* push data from the underlying datachannel to the length prefix decoder
* and then the protobuf decoder.
*/
private readonly _innersrc = pushable();
private readonly _innersrc = pushable()

/**
* Deferred promise that resolves when the underlying datachannel is in the
* open state.
*/
opened: DeferredPromise<void> = defer();
opened: DeferredPromise<void> = defer()

/**
* sinkCreated is set to true once the sinkFunction is invoked
*/
_sinkCalled: boolean = false;
_sinkCalled: boolean = false

/**
* Triggers a generator which can be used to close the sink.
*/
closeWritePromise: DeferredPromise<void> = defer();
closeWritePromise: DeferredPromise<void> = defer()

/**
* Callback to invoke when the stream is closed.
Expand Down Expand Up @@ -436,7 +436,7 @@ export class WebRTCStream implements Stream {
private _sendFlag (flag: pb.Message_Flag): void {
try {
log.trace('Sending flag: %s', flag.toString())
const msgbuf = pb.Message.toBinary({ flag: flag })
const msgbuf = pb.Message.toBinary({ flag })
this.channel.send(lengthPrefixed.encode.single(msgbuf).subarray())
} catch (err) {
if (err instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const nopSource = {
async * [Symbol.asyncIterator] () {}
}

export const nopSink = async (_: any) => {}
export const nopSink = async (_: any): Promise<void> => {}

const charset = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')
export const genUfrag = (len: number): string => [...Array(len)].map(() => charset.at(Math.floor(Math.random() * charset.length))).join('')
2 changes: 1 addition & 1 deletion test/maconn.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Multiaddr Connection', () => {
peerConnection.createDataChannel('whatever', { negotiated: true, id: 91 })
const remoteAddr = multiaddr('/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ')
const maConn = new WebRTCMultiaddrConnection({
peerConnection: peerConnection,
peerConnection,
remoteAddr,
timeline: {
open: (new Date()).getTime()
Expand Down
2 changes: 1 addition & 1 deletion test/stream.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function setup (): { peerConnection: RTCPeerConnection, datachannel: RTCDataChan

function generatePbByFlag (flag?: pb.Message_Flag): Uint8Array {
const testPb: pb.Message = {
flag: flag,
flag,
message: bytes.fromString(TEST_MESSAGE)
}
return pb.Message.toBinary(testPb)
Expand Down
2 changes: 1 addition & 1 deletion test/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'aegir/chai'

export const expectError = (error: unknown, message: string) => {
export const expectError = (error: unknown, message: string): void => {
if (error instanceof Error) {
expect(error.message).to.equal(message)
} else {
Expand Down

0 comments on commit b962b2e

Please sign in to comment.