Skip to content

Commit e6c9957

Browse files
RangerMauvervagg
authored andcommitted
fix: changes for new lint rules
1 parent 163d463 commit e6c9957

12 files changed

+48
-30
lines changed

.eslintrc

-8
This file was deleted.

src/bases/base.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as API from './interface.js'
88
* Class represents both BaseEncoder and MultibaseEncoder meaning it
99
* can be used to encode to multibase or base encode without multibase
1010
* prefix.
11+
*
1112
* @class
1213
* @template {string} Base
1314
* @template {string} Prefix
@@ -46,6 +47,8 @@ class Encoder {
4647
* Class represents both BaseDecoder and MultibaseDecoder so it could be used
4748
* to decode multibases (with matching prefix) or just base decode strings
4849
* with corresponding base encoding.
50+
*
51+
* @class
4952
* @template {string} Base
5053
* @template {string} Prefix
5154
* @implements {API.MultibaseDecoder<Prefix>}
@@ -193,7 +196,7 @@ export class Codec {
193196
/**
194197
* @template {string} Base
195198
* @template {string} Prefix
196-
* @param {Object} options
199+
* @param {object} options
197200
* @param {Base} options.name
198201
* @param {Prefix} options.prefix
199202
* @param {(bytes:Uint8Array) => string} options.encode
@@ -206,7 +209,7 @@ export const from = ({ name, prefix, encode, decode }) =>
206209
/**
207210
* @template {string} Base
208211
* @template {string} Prefix
209-
* @param {Object} options
212+
* @param {object} options
210213
* @param {Base} options.name
211214
* @param {Prefix} options.prefix
212215
* @param {string} options.alphabet
@@ -324,7 +327,7 @@ const encode = (data, alphabet, bitsPerChar) => {
324327
*
325328
* @template {string} Base
326329
* @template {string} Prefix
327-
* @param {Object} options
330+
* @param {object} options
328331
* @param {Base} options.name
329332
* @param {Prefix} options.prefix
330333
* @param {string} options.alphabet

src/bases/interface.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ export interface BaseEncoder {
88
/**
99
* Base encodes to a **plain** (and not a multibase) string. Unlike
1010
* `encode` no multibase prefix is added.
11+
*
1112
* @param bytes
1213
*/
13-
baseEncode(bytes: Uint8Array): string
14+
baseEncode: (bytes: Uint8Array) => string
1415
}
1516

1617
/**
@@ -20,9 +21,10 @@ export interface BaseDecoder {
2021
/**
2122
* Decodes **plain** (and not a multibase) string. Unlike
2223
* decode
24+
*
2325
* @param text
2426
*/
25-
baseDecode(text: string): Uint8Array
27+
baseDecode: (text: string) => Uint8Array
2628
}
2729

2830
/**
@@ -58,7 +60,7 @@ export interface MultibaseEncoder<Prefix extends string> {
5860
* Encodes binary data into **multibase** string (which will have a
5961
* prefix added).
6062
*/
61-
encode(bytes: Uint8Array): Multibase<Prefix>
63+
encode: (bytes: Uint8Array) => Multibase<Prefix>
6264
}
6365

6466
/**
@@ -71,9 +73,10 @@ export interface MultibaseDecoder<Prefix extends string> {
7173
/**
7274
* Decodes **multibase** string (which must have a multibase prefix added).
7375
* If prefix does not match
76+
*
7477
* @param multibase
7578
*/
76-
decode(multibase: Multibase<Prefix>): Uint8Array
79+
decode: (multibase: Multibase<Prefix>) => Uint8Array
7780
}
7881

7982
/**
@@ -86,7 +89,6 @@ export interface MultibaseCodec<Prefix extends string> {
8689
decoder: MultibaseDecoder<Prefix>
8790
}
8891

89-
9092
export interface UnibaseDecoder<Prefix extends string> extends MultibaseDecoder<Prefix> {
9193
// Reserve this property so it can be used to derive type.
9294
readonly decoders?: null
@@ -97,4 +99,3 @@ export interface UnibaseDecoder<Prefix extends string> extends MultibaseDecoder<
9799
export interface CombobaseDecoder<Prefix extends string> extends MultibaseDecoder<Prefix> {
98100
readonly decoders: Record<Prefix, UnibaseDecoder<Prefix>>
99101
}
100-

src/block.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const tree = function * (source, base) {
7171
}
7272

7373
/**
74+
*
7475
* @template T
7576
* @param {T} source
7677
* @param {string[]} path
@@ -100,7 +101,7 @@ const get = (source, path) => {
100101
*/
101102
class Block {
102103
/**
103-
* @param {Object} options
104+
* @param {object} options
104105
* @param {CID<T, C, A, V>} options.cid
105106
* @param {API.ByteView<T>} options.bytes
106107
* @param {T} options.value
@@ -131,6 +132,7 @@ class Block {
131132
}
132133

133134
/**
135+
*
134136
* @param {string} [path]
135137
* @return {API.BlockCursorView<unknown>}
136138
*/
@@ -143,7 +145,7 @@ class Block {
143145
* @template {unknown} T - Logical type of the data encoded in the block
144146
* @template {number} Code - multicodec code corresponding to codec used to encode the block
145147
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
146-
* @param {Object} options
148+
* @param {object} options
147149
* @param {T} options.value
148150
* @param {API.BlockEncoder<Code, T>} options.codec
149151
* @param {API.MultihashHasher<Alg>} options.hasher
@@ -169,7 +171,7 @@ const encode = async ({ value, codec, hasher }) => {
169171
* @template {unknown} T - Logical type of the data encoded in the block
170172
* @template {number} Code - multicodec code corresponding to codec used to encode the block
171173
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
172-
* @param {Object} options
174+
* @param {object} options
173175
* @param {API.ByteView<T>} options.bytes
174176
* @param {API.BlockDecoder<Code, T>} options.codec
175177
* @param {API.MultihashHasher<Alg>} options.hasher
@@ -188,7 +190,7 @@ const decode = async ({ bytes, codec, hasher }) => {
188190
}
189191

190192
/**
191-
* @typedef {Object} RequiredCreateOptions
193+
* @typedef {object} RequiredCreateOptions
192194
* @property {CID} options.cid
193195
*/
194196

@@ -220,7 +222,7 @@ const createUnsafe = ({ bytes, cid, value: maybeValue, codec }) => {
220222
* @template {number} Code - multicodec code corresponding to codec used to encode the block
221223
* @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
222224
* @template {API.Version} V - CID version
223-
* @param {Object} options
225+
* @param {object} options
224226
* @param {API.Link<T, Code, Alg, V>} options.cid
225227
* @param {API.ByteView<T>} options.bytes
226228
* @param {API.BlockDecoder<Code, T>} options.codec

src/cid.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class CID {
227227
*/
228228
static isCID (value) {
229229
deprecate(/^0\.0/, IS_CID_DEPRECATION)
230-
return !!(value && (value[cidSymbol] || value.asCID === value))
230+
return Boolean(value && (value[cidSymbol] || value.asCID === value))
231231
}
232232

233233
get toBaseEncodedString () {
@@ -255,6 +255,15 @@ export class CID {
255255
}
256256

257257
/**
258+
* Takes any input `value` and returns a `CID` instance if it was
259+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
260+
* it will return value back. If `value` is not instance of this CID
261+
* class, but is compatible CID it will return new instance of this
262+
* `CID` class. Otherwise returs null.
263+
*
264+
* This allows two different incompatible versions of CID library to
265+
* co-exist and interop as long as binary interface is compatible.
266+
*
258267
* @template {unknown} Data
259268
* @template {number} Format
260269
* @template {number} Alg
@@ -298,6 +307,7 @@ export class CID {
298307
}
299308

300309
/**
310+
*
301311
* @template {unknown} Data
302312
* @template {number} Format
303313
* @template {number} Alg
@@ -334,6 +344,7 @@ export class CID {
334344

335345
/**
336346
* Simplified version of `create` for CIDv0.
347+
*
337348
* @template {unknown} [T=unknown]
338349
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
339350
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
@@ -344,6 +355,7 @@ export class CID {
344355

345356
/**
346357
* Simplified version of `create` for CIDv1.
358+
*
347359
* @template {unknown} Data
348360
* @template {number} Code
349361
* @template {number} Alg
@@ -361,6 +373,7 @@ export class CID {
361373
*
362374
* An error will be thrown if the bytes provided do not contain a valid
363375
* binary representation of a CID.
376+
*
364377
* @template {unknown} Data
365378
* @template {number} Code
366379
* @template {number} Alg
@@ -603,6 +616,7 @@ const version = '0.0.0-dev'
603616
* @param {string} message
604617
*/
605618
const deprecate = (range, message) => {
619+
/* eslint-disable no-console */
606620
if (range.test(version)) {
607621
console.warn(message)
608622
/* c8 ignore next 3 */

src/codecs/interface.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import type { ByteView } from '../block/interface'
66
export interface BlockEncoder<Code extends number, T> {
77
name: string
88
code: Code
9-
encode(data: T): ByteView<T>
9+
encode: (data: T) => ByteView<T>
1010
}
1111

1212
/**
1313
* IPLD decoder part of the codec.
1414
*/
1515
export interface BlockDecoder<Code extends number, T> {
1616
code: Code
17-
decode(bytes: ByteView<T>): T
17+
decode: (bytes: ByteView<T>) => T
1818
}
1919

2020
/**

src/hashes/digest.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as varint from '../varint.js'
33

44
/**
55
* Creates a multihash digest.
6+
*
67
* @template {number} Code
78
* @param {Code} code
89
* @param {Uint8Array} digest
@@ -22,6 +23,7 @@ export const create = (code, digest) => {
2223

2324
/**
2425
* Turns bytes representation of multihash digest into an instance.
26+
*
2527
* @param {Uint8Array} multihash
2628
* @returns {MultihashDigest}
2729
*/
@@ -67,6 +69,7 @@ export const equals = (a, b) => {
6769
/**
6870
* Represents a multihash digest which carries information about the
6971
* hashing alogrithm and an actual hash digest.
72+
*
7073
* @template {number} Code
7174
* @template {number} Size
7275
* @class
@@ -75,6 +78,7 @@ export const equals = (a, b) => {
7578
export class Digest {
7679
/**
7780
* Creates a multihash digest.
81+
*
7882
* @param {Code} code
7983
* @param {Size} size
8084
* @param {Uint8Array} digest

src/hashes/hasher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Digest from './digest.js'
33
/**
44
* @template {string} Name
55
* @template {number} Code
6-
* @param {Object} options
6+
* @param {object} options
77
* @param {Name} options.name
88
* @param {Code} options.code
99
* @param {(input: Uint8Array) => Await<Uint8Array>} options.encode

src/hashes/interface.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface MultihashHasher<Code extends number = number> {
4444
*
4545
* @param {Uint8Array} input
4646
*/
47-
digest(input: Uint8Array): Promise<MultihashDigest<Code>> | MultihashDigest<Code>
47+
digest: (input: Uint8Array) => Promise<MultihashDigest<Code>> | MultihashDigest<Code>
4848

4949
/**
5050
* Name of the multihash
@@ -68,5 +68,5 @@ export interface MultihashHasher<Code extends number = number> {
6868
* impractical e.g. implementation of Hash Array Mapped Trie (HAMT).
6969
*/
7070
export interface SyncMultihashHasher<Code extends number = number> extends MultihashHasher<Code> {
71-
digest(input: Uint8Array): MultihashDigest<Code>
71+
digest: (input: Uint8Array) => MultihashDigest<Code>
7272
}

src/link.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ const SHA_256_CODE = 0x12
1111

1212
/**
1313
* Simplified version of `create` for CIDv0.
14+
*
1415
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
1516
* @returns {API.LegacyLink}
1617
*/
1718
export const createLegacy = digest => CID.create(0, DAG_PB_CODE, digest)
1819

1920
/**
2021
* Simplified version of `create` for CIDv1.
22+
*
2123
* @template {unknown} Data
2224
* @template {number} Code
2325
* @template {number} Alg

src/traversal.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { base58btc } from './bases/base58.js'
1616
*/
1717

1818
/**
19-
* @param {Object} options
19+
* @template T
20+
* @param {object} options
2021
* @param {CID} options.cid
2122
* @param {(cid: CID) => Promise<BlockView|null>} options.load
2223
* @param {Set<string>} [options.seen]

test/test-multibase-spec.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-env mocha */
2-
'use strict'
32

43
import { bases } from 'multiformats/basics'
54
import { fromString } from 'multiformats/bytes'

0 commit comments

Comments
 (0)