Skip to content

Commit

Permalink
chore: no longer depends on hd-scripts, packages use/configure eslint…
Browse files Browse the repository at this point in the history
… directly, fixes warnings from npm lint script (#1058)

Motivation:
* fix warning in console when running lint script while devving in
access-client: #1053

Tactics:
* new package `packages/eslint-config-w3up`
* all packages use package.json to set `eslintConfig.extends` to
`@web3-storage/eslint-config-w3up` and have a devDep on that package
within the monorepo. No monorepo subpackages use any eslint rules other
than those in eslint-config-w3up. i.e. all w3up packages use the same
eslint config (this wasn't actually the case before, since different
w3up packages were depending on different versions of hd-scripts)
* no packages depend on hd-scripts any more
  • Loading branch information
gobengo committed Nov 2, 2023
1 parent 256e651 commit ebdb99b
Show file tree
Hide file tree
Showing 60 changed files with 399 additions and 1,725 deletions.
35 changes: 6 additions & 29 deletions packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"uint8arrays": "^4.0.6"
},
"devDependencies": {
"@web3-storage/eslint-config-w3up": "workspace:^",
"@types/assert": "^1.5.6",
"@types/inquirer": "^9.0.4",
"@types/mocha": "^10.0.1",
Expand All @@ -86,7 +87,6 @@
"@types/ws": "^8.5.4",
"@ucanto/server": "^9.0.1",
"assert": "^2.0.0",
"hd-scripts": "^4.0.0",
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"sinon": "^15.0.3",
Expand All @@ -95,37 +95,14 @@
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/index.js"
"@web3-storage/eslint-config-w3up"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"unicorn/prefer-number-properties": "off",
"unicorn/prefer-export-from": "off",
"unicorn/expiring-todo-comments": "off",
"unicorn/no-array-reduce": "off",
"unicorn/explicit-length-check": "off",
"no-continue": "off",
"jsdoc/no-undefined-types": [
"error",
{
"definedTypes": [
"ArrayLike",
"AsyncIterable",
"AsyncIterableIterator",
"Iterable",
"IterableIterator",
"Generator",
"CryptoKeyPair",
"NodeJS",
"ErrorOptions",
"IDBTransactionMode"
]
}
]
},
"env": {
"browser": true,
"es2022": true,
"mocha": true
},
"ignorePatterns": [
Expand All @@ -138,8 +115,8 @@
],
"ignores": [
"@types/*",
"hd-scripts",
"assert"
"assert",
"@web3-storage/eslint-config-w3up"
]
}
}
1 change: 1 addition & 0 deletions packages/access-client/src/agent-use-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export async function pollAccessClaimUntil(
opts
) {
const interval = opts?.interval || 250
// eslint-disable-next-line no-constant-condition
while (true) {
if (opts?.signal?.aborted)
throw opts.signal.reason ?? new Error('operation aborted')
Expand Down
1 change: 0 additions & 1 deletion packages/access-client/src/crypto/aes-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class AesKey {
)
const encryptedBytes = new Uint8Array(buf)
const encrypted = uint8arrays.toString(
// eslint-disable-next-line unicorn/prefer-spread
uint8arrays.concat([iv, encryptedBytes]),
'base64pad'
)
Expand Down
1 change: 0 additions & 1 deletion packages/access-client/src/crypto/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export function decompressP256(comp) {
yPadded.set(y, offset)

// concat coords & prepend P-256 prefix
// eslint-disable-next-line unicorn/prefer-spread
const publicKey = uint8arrays.concat([[0x04], x, yPadded])
return publicKey
}
5 changes: 1 addition & 4 deletions packages/access-client/src/crypto/p256-ecdh.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ async function didFromPubkey(pubkey) {
const buf = await webcrypto.subtle.exportKey('raw', pubkey)
const bytes = new Uint8Array(buf)
return DID.format(
DID.decode(
// eslint-disable-next-line unicorn/prefer-spread
uint8arrays.concat([P256_DID_PREFIX, compressP256Pubkey(bytes)])
)
DID.decode(uint8arrays.concat([P256_DID_PREFIX, compressP256Pubkey(bytes)]))
)
}

Expand Down
1 change: 0 additions & 1 deletion packages/access-client/src/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*
* @module
*/
/* eslint-disable unicorn/prefer-spread */
import { CarBufferReader } from '@ipld/car/buffer-reader'
import * as CarBufferWriter from '@ipld/car/buffer-writer'
import { Delegation } from '@ucanto/core/delegation'
Expand Down
1 change: 1 addition & 0 deletions packages/access-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface SpaceMeta {
* Agent class types
*/

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface AgentOptions<S extends Record<string, any>> {
url?: URL
connection?: ConnectionView<S>
Expand Down
1 change: 0 additions & 1 deletion packages/access-client/test/agent-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as ucanto from '@ucanto/core'

describe('AgentData', () => {
it('should not destructure store methods', async () => {
// eslint-disable-next-line unicorn/no-await-expression-member
const raw = (await AgentData.create()).export()
class Store {
async open() {}
Expand Down
2 changes: 0 additions & 2 deletions packages/access-client/test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ describe('Agent', function () {
const { nb: input } = capability
const ucan = Delegation.view(
{ root: input.ucan, blocks: invocation.blocks },
// eslint-disable-next-line unicorn/no-null
null
)
return ucan
Expand Down Expand Up @@ -424,7 +423,6 @@ describe('Agent', function () {
// the agent has a delegation+sesssion for each service
const services = [serviceAWeb, serviceBWeb]
for (const service of services) {
// eslint-disable-next-line unicorn/no-await-expression-member
const nonce = (await ed25519.Signer.generate()).did()
const delegation = await ucanto.delegate({
issuer: Absentee.from({ id: account }),
Expand Down
28 changes: 8 additions & 20 deletions packages/capabilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@
"@web3-storage/data-segment": "^3.2.0"
},
"devDependencies": {
"@web3-storage/eslint-config-w3up": "workspace:^",
"@types/assert": "^1.5.6",
"@types/mocha": "^10.0.0",
"@types/node": "^20.8.4",
"assert": "^2.0.0",
"hd-scripts": "^4.0.0",
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"type-fest": "^3.3.0",
Expand All @@ -101,28 +101,16 @@
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/index.js"
"@web3-storage/eslint-config-w3up"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"unicorn/expiring-todo-comments": "off",
"unicorn/numeric-separators-style": "off",
"unicorn/prefer-number-properties": "off",
"unicorn/prefer-export-from": "off",
"unicorn/no-array-reduce": "off",
"jsdoc/no-undefined-types": [
"error",
{
"definedTypes": [
"Iterable"
]
}
]
},
"env": {
"mocha": true
"es2022": true,
"mocha": true,
"browser": true,
"node": true
},
"ignorePatterns": [
"dist",
Expand All @@ -135,8 +123,8 @@
],
"ignores": [
"@types/*",
"hd-scripts",
"assert"
"assert",
"@web3-storage/eslint-config-w3up"
]
}
}
1 change: 0 additions & 1 deletion packages/capabilities/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export function equalWith(child, parent) {
* @param {unknown} parent
* @param {string} constraint
*/

export function equal(child, parent, constraint) {
if (parent === undefined || parent === '*') {
return ok({})
Expand Down
1 change: 0 additions & 1 deletion packages/capabilities/test/capabilities/store.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable unicorn/no-null */
import assert from 'assert'
import { access } from '@ucanto/validator'
import { Verifier } from '@ucanto/principal'
Expand Down
18 changes: 4 additions & 14 deletions packages/did-mailto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,23 @@
"attw": "attw --pack .",
"build": "tsc --build",
"check": "tsc --build",
"lint": "tsc --build",
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"test": "mocha --bail --timeout 10s -n no-warnings -n experimental-vm-modules -n experimental-fetch test/**/*.spec.js",
"test-watch": "pnpm build && mocha --bail --timeout 10s --watch --parallel -n no-warnings -n experimental-vm-modules -n experimental-fetch --watch-files src,test"
},
"devDependencies": {
"@web3-storage/eslint-config-w3up": "workspace:^",
"@types/assert": "^1.5.6",
"@types/mocha": "^10.0.1",
"@types/node": "^20.8.4",
"hd-scripts": "^4.1.0",
"mocha": "^10.2.0"
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/index.js"
"@web3-storage/eslint-config-w3up"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"jsdoc/no-undefined-types": [
"error",
{
"definedTypes": [
"Iterable"
]
}
]
},
"env": {
"mocha": true
},
Expand Down
8 changes: 6 additions & 2 deletions packages/did-mailto/test/did-mailto.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ describe('did-mailto', () => {
})

/**
* @param {typeof didMailto} didMailto
* @param {import("./test-types.js").TestAdder} test
* @param {typeof didMailto} didMailto - did-mailto module to test
* @param {import("./test-types.js").TestAdder} test - function to call to add a named test
*/
function testDidMailto(didMailto, test) {
test('module is an object', async () => {
Expand Down Expand Up @@ -37,6 +37,7 @@ function testDidMailto(didMailto, test) {
}
}

/** @yields examples for testing */
function* examples() {
yield {
email: didMailto.email('example+123@example.com'),
Expand All @@ -48,6 +49,9 @@ function* examples() {
}
}

/**
* @yields many valid-but-unusual email addresses
*/
function* validEmailAddresses() {
// https://gist.github.com/cjaoude/fd9910626629b53c4d25#file-gistfile1-txt-L5
yield* [
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config-w3up/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
61 changes: 61 additions & 0 deletions packages/eslint-config-w3up/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict'

module.exports = {
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jsdoc/recommended",
],
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-ts-comment": "off",

/**
* many of these rules are inherited from hd-scripts.
* It may be useful over time to remove these rules
* and juse use plugin:jsdoc/recommended defaults.
* But that might require updating src.
*/
"jsdoc/check-values": "off",
"jsdoc/check-tag-names": "off",
"jsdoc/require-jsdoc": [
"warn",
{
"publicOnly": true
}
],
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off",
"jsdoc/require-throws": "off",
"jsdoc/require-yields": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-property-description": "off",
"jsdoc/require-returns-description": "off",
"jsdoc/valid-types": "off",
"jsdoc/tag-lines": [
"error",
"any",
{
"startLines": 1
}
],
"jsdoc/no-undefined-types": [
"error",
{
"definedTypes": [
"ArrayLike",
"AsyncIterable",
"AsyncIterableIterator",
"Iterable",
"IterableIterator",
"Generator",
"CryptoKeyPair",
"NodeJS",
"ErrorOptions",
"IDBTransactionMode"
]
}
]

}
}
25 changes: 25 additions & 0 deletions packages/eslint-config-w3up/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@web3-storage/eslint-config-w3up",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "eslint '**/*.{js,ts}'"
},
"author": "",
"license": "ISC",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint-plugin-jsdoc": "^46.8.2"
},
"peerDependencies": {
"eslint": ">= 8"
},
"eslintConfig": {
"extends": "./index.js",
"env": {
"node": true
}
}
}
Loading

0 comments on commit ebdb99b

Please sign in to comment.