Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
chore: use eslint-config-ipfs (#3287)
Browse files Browse the repository at this point in the history
Uses shared eslint config `eslint-config-ipfs` by integrating ipfs/aegir#638. Shared config uses new jsdoc plugin enabling use to remove bunch of `eslint-disable-next-line valid-jsdoc` comments. On the flip side it adds bit more requirements for structuring jsdoc comments. Most changes are generated automatically by eslint with `--fix` flag.

This change also intentionally adds `.eslintrc` files to every package with content `{ "extends": "ipfs" }`, so that all the tools that support eslint pick up desired configuration.  `eslint-config-ipfs` package itself isn't added to dependencies, because it gets installed as `aegir` dependency.

Co-authored-by: achingbrain <[email protected]>
  • Loading branch information
Gozala and achingbrain authored Oct 6, 2020
1 parent 0c88348 commit 2ff7ca5
Show file tree
Hide file tree
Showing 76 changed files with 247 additions and 180 deletions.
3 changes: 3 additions & 0 deletions packages/interface-ipfs-core/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "ipfs"
}
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"uint8arrays": "^1.1.0"
},
"devDependencies": {
"aegir": "^26.0.0",
"aegir": "^27.0.0",
"ipfsd-ctl": "^7.0.0"
},
"contributors": [
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs-cli/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "ipfs"
}
2 changes: 1 addition & 1 deletion packages/ipfs-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"yargs": "^16.0.3"
},
"devDependencies": {
"aegir": "^26.0.0",
"aegir": "^27.0.0",
"nanoid": "^3.1.12",
"ncp": "^2.0.0",
"rimraf": "^3.0.2",
Expand Down
9 changes: 5 additions & 4 deletions packages/ipfs-cli/test/utils/ipfs-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ module.exports = (repoPath, opts) => {

/**
* Expect the command passed as @param arguments to fail.
* @param {String} command String command to run, e.g. `'pin ls'`
* @param {Object} options Options to pass to `execa`
* @return {Promise} Resolves if the command passed as @param arguments fails,
* rejects if it was successful.
*
* @param {string} command - String command to run, e.g. `'pin ls'`
* @param {Object} options - Options to pass to `execa`
* @returns {Promise} Resolves if the command passed as @param arguments fails,
* rejects if it was successful.
*/
ipfs.fail = function ipfsFail (command, options) {
return ipfs(command, { disableErrorLog: true, ...(options || {}) })
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs-core-utils/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "ipfs"
}
2 changes: 1 addition & 1 deletion packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"uint8arrays": "^1.1.0"
},
"devDependencies": {
"aegir": "^26.0.0",
"aegir": "^27.0.0",
"delay": "^4.4.0"
}
}
28 changes: 14 additions & 14 deletions packages/ipfs-core-utils/src/cid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
const CID = require('cids')

/**
* Stringify a CID encoded in the requested base, upgrading to v1 if necessary.
*
* Setting upgrade to false will disable automatic CID upgrading from v0 to v1
* which is necessary if the multibase is something other than base58btc. Note
* that it will also not apply the encoding (since v0 CIDs can only be encoded
* as base58btc).
*
* @param {CID|Buffer|String} cid The CID to encode
* @param {Object} [options] Optional options
* @param {String} [options.base] Name of multibase codec to encode the CID with
* @param {Boolean} [options.upgrade] Automatically upgrade v0 CIDs to v1 when
* necessary. Default: true.
* @returns {String}
*/
* Stringify a CID encoded in the requested base, upgrading to v1 if necessary.
*
* Setting upgrade to false will disable automatic CID upgrading from v0 to v1
* which is necessary if the multibase is something other than base58btc. Note
* that it will also not apply the encoding (since v0 CIDs can only be encoded
* as base58btc).
*
* @param {CID | Buffer | string} cid - The CID to encode
* @param {Object} [options] - Optional options
* @param {string} [options.base] - Name of multibase codec to encode the CID with
* @param {boolean} [options.upgrade] - Automatically upgrade v0 CIDs to v1 when
* necessary. Default: true.
* @returns {string}
*/
exports.cidToString = (cid, options) => {
options = options || {}
options.upgrade = options.upgrade !== false
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs-core/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "ipfs"
}
2 changes: 1 addition & 1 deletion packages/ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"uint8arrays": "^1.1.0"
},
"devDependencies": {
"aegir": "^26.0.0",
"aegir": "^27.0.0",
"delay": "^4.4.0",
"ipfsd-ctl": "^7.0.0",
"interface-ipfs-core": "^0.140.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/api-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = class ApiManager {

/**
* @template API
* @typedef {{ cancel(): any; api: API; }} Updated
* @typedef {{ cancel: () => any, api: API }} Updated
*/

constructor () {
Expand Down
11 changes: 5 additions & 6 deletions packages/ipfs-core/src/components/add-all/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const { withTimeoutOption } = require('../../utils')
const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })

/**
* @typedef {Uint8Array | Blob | String | Iterable<Uint8Array> | Iterable<number> | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>} FileContent
* @typedef {Uint8Array | Blob | string | Iterable<Uint8Array> | Iterable<number> | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>} FileContent
*
* @typedef {object} FileObject
* - If no path is specified, then the item will be added to the root level and will be given a name according to it's CID.
* - If no content is passed, then the item is treated as an empty directory.
* - One of path or content must be passed.
* - If no path is specified, then the item will be added to the root level and will be given a name according to it's CID.
* - If no content is passed, then the item is treated as an empty directory.
* - One of path or content must be passed.
* @property {string} [path] - The path you want to the file to be accessible at from the root CID _after_ it has been added
* @property {FileContent} [content] - The contents of the file
* @property {number | string} [mode] - File mode to store the entry with (see https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation)
Expand Down Expand Up @@ -45,6 +45,7 @@ const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })

/**
* Import multiple files and data into IPFS.
*
* @template {Record<string, any>} ExtraOptions
* @callback AddAll
* @param {FileStream} source
Expand All @@ -54,8 +55,6 @@ const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })

module.exports = ({ block, gcLock, preload, pin, options: constructorOptions }) => {
const isShardingEnabled = constructorOptions.EXPERIMENTAL && constructorOptions.EXPERIMENTAL.sharding

// eslint-disable-next-line valid-jsdoc
/**
* @type {AddAll<{}>}
*/
Expand Down
22 changes: 11 additions & 11 deletions packages/ipfs-core/src/components/add-all/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* Parses chunker string into options used by DAGBuilder in ipfs-unixfs-engine
*
*
* @param {String} chunker Chunker algorithm supported formats:
* "size-{size}"
* "rabin"
* "rabin-{avg}"
* "rabin-{min}-{avg}-{max}"
* @param {string} chunker - Chunker algorithm supported formats:
* "size-{size}"
* "rabin"
* "rabin-{avg}"
* "rabin-{min}-{avg}-{max}"
*
* @return {Object} Chunker options for DAGBuilder
* @returns {Object} Chunker options for DAGBuilder
*/
const parseChunkerString = (chunker) => {
if (!chunker) {
Expand Down Expand Up @@ -40,12 +40,12 @@ const parseChunkerString = (chunker) => {
/**
* Parses rabin chunker string
*
* @param {String} chunker Chunker algorithm supported formats:
* "rabin"
* "rabin-{avg}"
* "rabin-{min}-{avg}-{max}"
* @param {string} chunker - Chunker algorithm supported formats:
* "rabin"
* "rabin-{avg}"
* "rabin-{min}-{avg}-{max}"
*
* @return {Object} rabin chunker options
* @returns {Object} rabin chunker options
*/
const parseRabinString = (chunker) => {
const options = {}
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core/src/components/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const last = require('it-last')
* @property {string} [hashAlg] - multihash hashing algorithm to use (default: `'sha2-256'`)
* @property {boolean} [onlyHash] - If true, will not add blocks to the blockstore (default: `false`)
* @property {boolean} [pin] - pin this object when adding (default: `true`)
* @property {function} [progress] - a function that will be called with the byte length of chunks as a file is added to ipfs (default: `undefined`)
* @property {Function} [progress] - a function that will be called with the byte length of chunks as a file is added to ipfs (default: `undefined`)
* @property {boolean} [rawLeaves] - if true, DAG leaves will contain raw file data and not be wrapped in a protobuf (default: `false`)
* @property {boolean} [trickle] - if true will use the [trickle DAG](https://godoc.org/github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs/importer/trickle) format for DAG generation (default: `false`)
* @property {boolean} [wrapWithDirectory] - Adds a wrapping node around the content (default: `false`)
*/

/**
* Import a file or data into IPFS.
*
* @template {Record<string, any>} ExtraOptions
* @callback Add
* @param {Source} source - Data to import
Expand All @@ -30,7 +31,6 @@ const last = require('it-last')
*/

module.exports = ({ addAll }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {Add<{}>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const { withTimeoutOption } = require('../../utils')

/**
* Show diagnostic information on the bitswap agent.
*
* @template {Record<string, any>} ExtraOptions
* @callback Stat
* @param {import('../../utils').AbortOptions & ExtraOptions} [options]
* @returns {Promise<BitswapStats>}
*/

module.exports = ({ bitswap }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {Stat<{}>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { withTimeoutOption } = require('../../utils')

/**
* Removes one or more CIDs from the wantlist
*
* @template {Record<string, any>} ExtraOptions
* @callback Unwant
* @param {CID | CID[]} cids - The CIDs to remove from the wantlist
Expand All @@ -18,7 +19,6 @@ const { withTimeoutOption } = require('../../utils')
*/

module.exports = ({ bitswap }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {Unwant<{}>}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { withTimeoutOption } = require('../../utils')

/**
* Returns the wantlist for a connected peer
*
* @template {Record<string, any>} ExtraOptions
* @callback WantlistForPeer
* @param {PeerId | CID | string | Buffer} peerId - A peer ID to return the wantlist for\
Expand All @@ -18,7 +19,6 @@ const { withTimeoutOption } = require('../../utils')
*/

module.exports = ({ bitswap }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {WantlistForPeer<{}>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const { withTimeoutOption } = require('../../utils')

/**
* Returns the wantlist for your node
*
* @template {Record<string, any>} ExtraOptions
* @callback WantlistFn
* @param {import('../../utils').AbortOptions & ExtraOptions} [options]
* @returns {Promise<CID[]>} - An array of CIDs currently in the wantlist
*/

module.exports = ({ bitswap }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {WantlistFn<{}>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { withTimeoutOption } = require('../../utils')

/**
* Get a raw IPFS block.
*
* @template {Record<string, any>} ExtraOptions
* @callback BlockGet
* @param {CID | string | Buffer} cid - A CID that corresponds to the desired block
Expand All @@ -23,7 +24,6 @@ const { withTimeoutOption } = require('../../utils')
*/

module.exports = ({ blockService, preload }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {BlockGet<PreloadOptions>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { withTimeoutOption } = require('../../utils')

/**
* Stores input as an IPFS block.
*
* @template {Record<string, any>} ExtraOptions
* @callback BlockPut
* @param {Buffer | Block} block - The block or data to store
Expand All @@ -32,7 +33,6 @@ const { withTimeoutOption } = require('../../utils')
*/

module.exports = ({ blockService, pin, gcLock, preload }) => {
// eslint-disable-next-line valid-jsdoc
/**
* @type {BlockPut<import('./get').PreloadOptions>}
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/components/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = ({ libp2p, repo }) => {
* Query the DHT for all multiaddresses associated with a `PeerId`.
*
* @param {PeerId} peerId - The id of the peer to search for.
* @returns {Promise<{ id: String, addrs: Multiaddr[] }>}
* @returns {Promise<{id: string, addrs: Multiaddr[]}>}
*/
findPeer: withTimeoutOption(async peerId => { // eslint-disable-line require-await
if (typeof peerId === 'string') {
Expand Down
Loading

0 comments on commit 2ff7ca5

Please sign in to comment.