Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Aug 28, 2023
1 parent 638dbed commit 3d74818
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/bases/identity.js
@@ -1,7 +1,7 @@
// @ts-check

import { from } from './base.js'
import { fromString, toString } from '../bytes.js'
import { from } from './base.js'

export const identity = from({
prefix: '\x00',
Expand Down
16 changes: 7 additions & 9 deletions src/basics.js
@@ -1,21 +1,19 @@
// @ts-check

import * as identityBase from './bases/identity.js'
import * as base2 from './bases/base2.js'
import * as base8 from './bases/base8.js'
import * as base10 from './bases/base10.js'
import * as base16 from './bases/base16.js'
import * as base2 from './bases/base2.js'
import * as base256emoji from './bases/base256emoji.js'
import * as base32 from './bases/base32.js'
import * as base36 from './bases/base36.js'
import * as base58 from './bases/base58.js'
import * as base64 from './bases/base64.js'
import * as base256emoji from './bases/base256emoji.js'
import * as sha2 from './hashes/sha2.js'
import * as identity from './hashes/identity.js'

import * as raw from './codecs/raw.js'
import * as base8 from './bases/base8.js'
import * as identityBase from './bases/identity.js'
import * as json from './codecs/json.js'

import * as raw from './codecs/raw.js'
import * as identity from './hashes/identity.js'
import * as sha2 from './hashes/sha2.js'
import { CID, hasher, digest, varint, bytes } from './index.js'

const bases = { ...identityBase, ...base2, ...base8, ...base10, ...base16, ...base32, ...base36, ...base58, ...base64, ...base256emoji }
Expand Down
5 changes: 3 additions & 2 deletions src/block/interface.ts
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
/* eslint-disable no-use-before-define */
import { Link, Version } from '../link/interface.js'
import { CID } from '../cid.js'

import type { CID } from '../cid.js'
import type { Link, Version } from '../link/interface.js'

/**
* A byte-encoded representation of some type of `Data`.
Expand Down
10 changes: 6 additions & 4 deletions src/cid.js
@@ -1,11 +1,11 @@
import * as varint from './varint.js'
import * as Digest from './hashes/digest.js'
import { base58btc } from './bases/base58.js'
import { base32 } from './bases/base32.js'
import { base58btc } from './bases/base58.js'
import { coerce } from './bytes.js'
import * as Digest from './hashes/digest.js'
// Linter can see that API is used in types.
// eslint-disable-next-line
import * as API from "./link/interface.js"
import * as varint from './varint.js'

// This way TS will also expose all the types from module
export * from './link/interface.js'
Expand Down Expand Up @@ -82,7 +82,6 @@ export class CID {
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
* @param {Uint8Array} bytes
*
*/
constructor (version, code, multihash, bytes) {
/** @readonly */
Expand Down Expand Up @@ -215,6 +214,9 @@ export class CID {
return format(this, base)
}

/**
* @returns {API.LinkJSON<this>}
*/
toJSON () {
return { '/': format(this) }
}
Expand Down
2 changes: 1 addition & 1 deletion src/hashes/sha2.js
@@ -1,8 +1,8 @@
// @ts-check

import crypto from 'crypto'
import { from } from './hasher.js'
import { coerce } from '../bytes.js'
import { from } from './hasher.js'

export const sha256 = from({
name: 'sha2-256',
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
@@ -1,8 +1,9 @@
import { CID } from './cid.js'
import * as varint from './varint.js'
import * as bytes from './bytes.js'
import * as hasher from './hashes/hasher.js'
import { CID } from './cid.js'
import * as digest from './hashes/digest.js'
import * as hasher from './hashes/hasher.js'
import * as varint from './varint.js'

// This way TS will also expose all the types from module
export * from './interface.js'

Expand Down
2 changes: 1 addition & 1 deletion src/link.js
@@ -1,7 +1,7 @@
import { CID, format, toJSON, fromJSON } from './cid.js'
// Linter can see that API is used in types.
// eslint-disable-next-line
import * as API from "./link/interface.js"
import { CID, format, toJSON, fromJSON } from './cid.js'
// This way TS will also expose all the types from module
export * from './link/interface.js'

Expand Down
3 changes: 2 additions & 1 deletion src/link/interface.ts
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
/* eslint-disable no-use-before-define */
import type { MultihashDigest } from '../hashes/interface.js'

import type { MultibaseEncoder, MultibaseDecoder, Multibase } from '../bases/interface.js'
import type { Phantom, ByteView } from '../block/interface.js'
import type { MultihashDigest } from '../hashes/interface.js'

export type { MultihashDigest, MultibaseEncoder, MultibaseDecoder }
export type Version = 0 | 1
Expand Down
11 changes: 2 additions & 9 deletions src/traversal.js
@@ -1,18 +1,11 @@
import { base58btc } from './bases/base58.js'

/**
* @template [C=number] - multicodec code corresponding to codec used to encode the block
* @template [A=number] - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template [V=0|1] - CID version
* @typedef {import('./cid').CID<unknown, C, A, V>} CID
* @typedef {import('./cid').CID} CID
*/

/**
* @template [T=unknown] - Logical type of the data encoded in the block
* @template [C=number] - multicodec code corresponding to codec used to encode the block
* @template [A=number] - multicodec code corresponding to the hashing algorithm used in CID creation.
* @template [V=0|1] - CID version
* @typedef {import('./block/interface.js').BlockView<T, C, A, V>} BlockView
* @typedef {import('./block/interface.js').BlockView} BlockView
*/

/**
Expand Down
5 changes: 3 additions & 2 deletions test/test-block.spec.js
@@ -1,9 +1,10 @@
/* globals describe, it */

import { assert } from 'aegir/chai'
import * as main from '../src/block.js'
import * as codec from '../src/codecs/json.js'
import { sha256 as hasher } from '../src/hashes/sha2.js'
import * as main from '../src/block.js'
import { CID, bytes } from '../src/index.js'
import { assert } from 'aegir/chai'

const fixture = { hello: 'world' }
const link = CID.parse('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae')
Expand Down
3 changes: 2 additions & 1 deletion test/test-bytes.spec.js
@@ -1,6 +1,7 @@
/* globals describe, it */
import * as bytes from '../src/bytes.js'

import { assert } from 'aegir/chai'
import * as bytes from '../src/bytes.js'

describe('bytes', () => {
it('isBinary', () => {
Expand Down
16 changes: 8 additions & 8 deletions test/test-cid.spec.js
@@ -1,17 +1,17 @@
/* globals describe, it */

import { fromHex, toHex, equals } from '../src/bytes.js'
import { varint, CID } from '../src/index.js'
import { base58btc } from '../src/bases/base58.js'
import { base32 } from '../src/bases/base32.js'
import { base64 } from '../src/bases/base64.js'
import { sha256, sha512 } from '../src/hashes/sha2.js'
import invalidMultihash from './fixtures/invalid-multihash.js'
import OLDCID from 'cids'
import { assert } from 'aegir/chai'
import OLDCID from 'cids'
// Linter can see that API is used in types.
// eslint-disable-next-line
import * as API from 'multiformats'
import { base32 } from '../src/bases/base32.js'
import { base58btc } from '../src/bases/base58.js'
import { base64 } from '../src/bases/base64.js'
import { fromHex, toHex, equals } from '../src/bytes.js'
import { sha256, sha512 } from '../src/hashes/sha2.js'
import { varint, CID } from '../src/index.js'
import invalidMultihash from './fixtures/invalid-multihash.js'

const textEncoder = new TextEncoder()

Expand Down
2 changes: 1 addition & 1 deletion test/test-link.spec.js
@@ -1,8 +1,8 @@
/* globals describe, it */

import * as Link from '../src/link.js'
import { assert } from 'aegir/chai'
import { sha256 } from '../src/hashes/sha2.js'
import * as Link from '../src/link.js'

const utf8 = new TextEncoder()

Expand Down
2 changes: 1 addition & 1 deletion test/test-multibase-spec.spec.js
@@ -1,8 +1,8 @@
/* eslint-env mocha */

import { assert } from 'aegir/chai'
import { bases } from '../src/basics.js'
import { fromString } from '../src/bytes.js'
import { assert } from 'aegir/chai'

const encoded = [
{
Expand Down
9 changes: 5 additions & 4 deletions test/test-multibase.spec.js
@@ -1,14 +1,15 @@
/* globals describe, it */
import * as bytes from '../src/bytes.js'
import * as b2 from '../src/bases/base2.js'
import * as b8 from '../src/bases/base8.js'

import { assert } from 'aegir/chai'
import * as b10 from '../src/bases/base10.js'
import * as b16 from '../src/bases/base16.js'
import * as b2 from '../src/bases/base2.js'
import * as b32 from '../src/bases/base32.js'
import * as b36 from '../src/bases/base36.js'
import * as b58 from '../src/bases/base58.js'
import * as b64 from '../src/bases/base64.js'
import { assert } from 'aegir/chai'
import * as b8 from '../src/bases/base8.js'
import * as bytes from '../src/bytes.js'

const { base16, base32, base58btc, base64 } = { ...b16, ...b32, ...b58, ...b64 }

Expand Down
5 changes: 3 additions & 2 deletions test/test-multicodec.spec.js
@@ -1,8 +1,9 @@
/* globals describe, it */

import { assert } from 'aegir/chai'
import * as bytes from '../src/bytes.js'
import * as raw from '../src/codecs/raw.js'
import * as json from '../src/codecs/json.js'
import { assert } from 'aegir/chai'
import * as raw from '../src/codecs/raw.js'

describe('multicodec', () => {
it('encode/decode raw', () => {
Expand Down
13 changes: 7 additions & 6 deletions test/test-multihash.spec.js
@@ -1,13 +1,14 @@
/* globals describe, it */
import { fromHex, fromString } from '../src/bytes.js'
import { sha256, sha512 } from '../src/hashes/sha2.js'
import { identity } from '../src/hashes/identity.js'
import { decode as decodeDigest, create as createDigest } from '../src/hashes/digest.js'
import valid from './fixtures/valid-multihash.js'
import invalid from './fixtures/invalid-multihash.js'

import { hash as slSha256 } from '@stablelib/sha256'
import { hash as slSha512 } from '@stablelib/sha512'
import { assert } from 'aegir/chai'
import { fromHex, fromString } from '../src/bytes.js'
import { decode as decodeDigest, create as createDigest } from '../src/hashes/digest.js'
import { identity } from '../src/hashes/identity.js'
import { sha256, sha512 } from '../src/hashes/sha2.js'
import invalid from './fixtures/invalid-multihash.js'
import valid from './fixtures/valid-multihash.js'

/**
* @param {number|string} code
Expand Down
7 changes: 4 additions & 3 deletions test/test-traversal.spec.js
@@ -1,10 +1,11 @@
/* globals describe, it */

import { assert } from 'aegir/chai'
import * as main from '../src/block.js'
import { fromString } from '../src/bytes.js'
import * as codec from '../src/codecs/json.js'
import { sha256 as hasher } from '../src/hashes/sha2.js'
import * as main from '../src/block.js'
import { walk } from '../src/traversal.js'
import { fromString } from '../src/bytes.js'
import { assert } from 'aegir/chai'

/** @typedef {import('../src/cid.js').CID} CID */

Expand Down
2 changes: 1 addition & 1 deletion test/test-varint.spec.js
@@ -1,7 +1,7 @@
/* globals describe, it */

import { varint } from '../src/index.js'
import { assert } from 'aegir/chai'
import { varint } from '../src/index.js'

const UTF8 = new TextEncoder()

Expand Down
4 changes: 2 additions & 2 deletions test/ts-use/src/main.ts
@@ -1,8 +1,8 @@
import * as Block from 'multiformats/block'
import { sha256 } from 'multiformats/hashes/sha2'
import * as json from 'multiformats/codecs/json'
import { sha256 } from 'multiformats/hashes/sha2'

const main = async () => {
const main = async (): Promise<void> => {
const block = await Block.encode({
value: { hello: 'world' },
hasher: sha256,
Expand Down

0 comments on commit 3d74818

Please sign in to comment.