From 6a7dbc62362183546e5b6b524e376d8ae536bec3 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Mon, 13 Jun 2022 09:50:57 -0700 Subject: [PATCH] yet another attempt to make tools happy --- package.json | 3 +-- src/block.js | 4 +++- src/codecs/json.js | 16 ++++++---------- src/codecs/raw.js | 17 ++++++----------- src/hashes/hasher.js | 9 +++------ src/hashes/interface.js | 4 ++++ src/hashes/sha2.js | 2 -- 7 files changed, 23 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index a7594a06..9ec7b9b5 100644 --- a/package.json +++ b/package.json @@ -130,8 +130,7 @@ "standard": { "ignore": [ "dist", - "vendor", - "**/interface.js" + "vendor" ] }, "directories": { diff --git a/src/block.js b/src/block.js index 3a53b766..ac38896b 100644 --- a/src/block.js +++ b/src/block.js @@ -2,6 +2,8 @@ import { bytes as binary, CID } from './index.js' // Linter can see that API is used in types. // eslint-disable-next-line import * as API from './interface.js' +// eslint-disable-next-line +import * as BlockAPI from './block/interface.js' const readonly = ({ enumerable = true, configurable = false } = {}) => ({ enumerable, @@ -224,7 +226,7 @@ const createUnsafe = ({ bytes, cid, value: maybeValue, codec }) => { * @param {API.ByteView} options.bytes * @param {API.BlockDecoder} options.codec * @param {API.MultihashHasher} options.hasher - * @returns {Promise>} + * @returns {Promise>} */ const create = async ({ bytes, cid, hasher, codec }) => { if (!bytes) throw new Error('Missing required argument "bytes"') diff --git a/src/codecs/json.js b/src/codecs/json.js index ac1cee27..90abe777 100644 --- a/src/codecs/json.js +++ b/src/codecs/json.js @@ -1,9 +1,5 @@ -// @ts-check - -/** - * @template T - * @typedef {import('./interface').ByteView} ByteView - */ +// eslint-disable-next-line +import * as API from './interface.js' const textEncoder = new TextEncoder() const textDecoder = new TextDecoder() @@ -14,13 +10,13 @@ export const code = 0x0200 /** * @template T * @param {T} node - * @returns {ByteView} + * @returns {API.ByteView} */ -export const encode = (node) => textEncoder.encode(JSON.stringify(node)) +export const encode = node => textEncoder.encode(JSON.stringify(node)) /** * @template T - * @param {ByteView} data + * @param {API.ByteView} data * @returns {T} */ -export const decode = (data) => JSON.parse(textDecoder.decode(data)) +export const decode = data => JSON.parse(textDecoder.decode(data)) diff --git a/src/codecs/raw.js b/src/codecs/raw.js index 3affb144..4f02cac5 100644 --- a/src/codecs/raw.js +++ b/src/codecs/raw.js @@ -1,23 +1,18 @@ -// @ts-check - +// eslint-disable-next-line +import * as API from './interface.js' import { coerce } from '../bytes.js' -/** - * @template T - * @typedef {import('./interface').ByteView} ByteView - */ - export const name = 'raw' export const code = 0x55 /** * @param {Uint8Array} node - * @returns {ByteView} + * @returns {API.ByteView} */ -export const encode = (node) => coerce(node) +export const encode = node => coerce(node) /** - * @param {ByteView} data + * @param {API.ByteView} data * @returns {Uint8Array} */ -export const decode = (data) => coerce(data) +export const decode = data => coerce(data) diff --git a/src/hashes/hasher.js b/src/hashes/hasher.js index 703e416b..abb21d74 100644 --- a/src/hashes/hasher.js +++ b/src/hashes/hasher.js @@ -1,4 +1,6 @@ import * as Digest from './digest.js' +// eslint-disable-next-line +import * as API from './interface.js' /** * @template {string} Name @@ -17,7 +19,7 @@ export const from = ({ name, code, encode }) => new Hasher(name, code, encode) * @template {string} Name * @template {number} Code * @class - * @implements {MultihashHasher} + * @implements {API.MultihashHasher} */ export class Hasher { /** @@ -50,11 +52,6 @@ export class Hasher { } } -/** - * @template {number} Alg - * @typedef {import('./interface').MultihashHasher} MultihashHasher - */ - /** * @template T * @typedef {Promise|T} Await diff --git a/src/hashes/interface.js b/src/hashes/interface.js index d9b3f4f7..29f46ac5 100644 --- a/src/hashes/interface.js +++ b/src/hashes/interface.js @@ -1 +1,5 @@ // this is dummy module overlayed by interface.ts +// just trying to stop eslint from campaining about +// no named exports +// eslint-disable-next-line no-void, no-shadow-restricted-names +export const undefined = void 0 diff --git a/src/hashes/sha2.js b/src/hashes/sha2.js index 20f88b6e..74542a80 100644 --- a/src/hashes/sha2.js +++ b/src/hashes/sha2.js @@ -1,5 +1,3 @@ -// @ts-check - import crypto from 'crypto' import { from } from './hasher.js' import { coerce } from '../bytes.js'