Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace standard and snazzy with neostandard #3485

Merged
merged 10 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

const neo = require('neostandard')

module.exports = [
{
ignores: [
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
'lib/llhttp/constants.js',
'lib/llhttp/utils.js',
'test/fixtures/wpt',
'lib/llhttp'
]
},
...neo({
env: ['jest'],
ignores: ['lib/llhttp/constants.js', 'lib/llhttp/utils.js', 'test/fixtures/wpt/**', 'undici-fetch.js'],
ts: true
}),
{
rules: {
'@stylistic/comma-dangle': ['error', {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to get feedback on neostandard/neostandard#79 to make this unnecessary 🙏

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you can update to 0.11.3 now and this override will no longer be needed (though having it will enforce no dangling commas if that's desireable)

arrays: 'never',
objects: 'never',
imports: 'never',
exports: 'never',
functions: 'never'
}],
'@typescript-eslint/no-redeclare': 'off',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a particular issue with TS-files? Maybe it's something we should tweak in neostandard itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this basically happens if you have something like

export interface CacheStorage {
  match (request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>,
  has (cacheName: string): Promise<boolean>,
  open (cacheName: string): Promise<Cache>,
  delete (cacheName: string): Promise<boolean>,
  keys (): Promise<string[]>
}

declare const CacheStorage: {
  prototype: CacheStorage
  new(): CacheStorage
}

Because the interface CacheStorage exists declaring the const CacheStorage results in a no-redeclare linting error

'no-lone-blocks': 'off'
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
}
}
]
2 changes: 0 additions & 2 deletions lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ async function lazyllhttp () {

return await WebAssembly.instantiate(mod, {
env: {
/* eslint-disable camelcase */

wasm_on_url: (p, at, len) => {
/* istanbul ignore next */
Expand Down Expand Up @@ -117,7 +116,6 @@ async function lazyllhttp () {
return currentParser.onMessageComplete() || 0
}

/* eslint-enable camelcase */
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web/fetch/data-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function parseMIMEType (input) {
/** @param {string} data */
function forgivingBase64 (data) {
// 1. Remove all ASCII whitespace from data.
data = data.replace(ASCII_WHITESPACE_REPLACE_REGEX, '') // eslint-disable-line
data = data.replace(ASCII_WHITESPACE_REPLACE_REGEX, '')

let dataLength = data.length
// 2. If data’s code point length divides by 4 leaving
Expand Down
2 changes: 1 addition & 1 deletion lib/web/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ function determineRequestsReferrer (request) {
// 3. Return referrerOrigin.
return referrerOrigin
}
case 'strict-origin': // eslint-disable-line
case 'strict-origin':
/**
* 1. If referrerURL is a potentially trustworthy URL and
* request’s current URL is not a potentially trustworthy URL,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"prebuild:wasm": "node build/wasm.js --prebuild",
"build:wasm": "node build/wasm.js --docker",
"generate-pem": "node scripts/generate-pem.js",
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:javascript && cross-env NODE_V8_COVERAGE= npm run test:typescript",
"test:javascript": "npm run test:javascript:no-jest && npm run test:jest",
"test:javascript:no-jest": "npm run generate-pem && npm run test:unit && npm run test:node-fetch && npm run test:cache && npm run test:interceptors && npm run test:fetch && npm run test:cookies && npm run test:eventsource && npm run test:wpt && npm run test:websocket && npm run test:node-test",
Expand Down Expand Up @@ -111,18 +111,18 @@
"c8": "^10.0.0",
"cross-env": "^7.0.3",
"dns-packet": "^5.4.0",
"eslint": "^9.9.0",
"fast-check": "^3.17.1",
"form-data": "^4.0.0",
"formdata-node": "^6.0.3",
"https-pem": "^3.0.0",
"husky": "^9.0.7",
"jest": "^29.0.2",
"jsdom": "^24.0.0",
"neostandard": "^0.11.2",
"node-forge": "^1.3.1",
"pre-commit": "^1.2.2",
"proxy": "^2.1.1",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tsd": "^0.31.0",
"typescript": "^5.0.2",
"ws": "^8.11.0"
Expand Down
2 changes: 1 addition & 1 deletion test/fetch/pull-dont-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('pull dont\'t push', async (t) => {

// consume the stream
try {
/* eslint-disable-next-line no-empty, no-unused-vars */
/* eslint-disable-next-line no-unused-vars */
for await (const chunk of res.body) {
// process._rawDebug('chunk', chunk)
}
Expand Down
11 changes: 9 additions & 2 deletions test/imports/undici-import.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { request } from '../../'
import { expectType } from 'tsd'
import { Dispatcher, request } from '../../'
import { interceptors } from '../../'

async function exampleCode() {
async function exampleCode () {
const retry = interceptors.retry()
const rd = interceptors.redirect()
const dump = interceptors.dump()

expectType<Dispatcher.DispatcherComposeInterceptor>(retry)
expectType<Dispatcher.DispatcherComposeInterceptor>(rd)
expectType<Dispatcher.DispatcherComposeInterceptor>(dump)

await request('http://localhost:3000/foo')
}

exampleCode()
1 change: 0 additions & 1 deletion test/node-fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ describe('Headers', () => {
['a', '3']
])

// eslint-disable-next-line quotes
assert.strictEqual(format(headers), "{ a: [ '1', '3' ], b: '2', host: 'thehost' }")
})
})
6 changes: 3 additions & 3 deletions test/node-test/abort-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ for (const { AbortControllerImpl, controllerName } of controllers) {
await p.completed
})

function waitingWithBody (body, type) { // eslint-disable-line
function waitingWithBody (body, type) {
test(`Abort ${controllerName} while waiting response (with body ${type})`, async (t) => {
const p = tspl(t, { plan: 1 })

Expand Down Expand Up @@ -187,7 +187,7 @@ for (const { AbortControllerImpl, controllerName } of controllers) {
waitingWithBody(new Uint8Array([42]), 'Uint8Array')
waitingWithBody(wrapWithAsyncIterable(createReadStream(__filename)), 'async-iterator')

function writeHeadersStartedWithBody (body, type) { // eslint-disable-line
function writeHeadersStartedWithBody (body, type) {
test(`Abort ${controllerName} while waiting response (write headers started) (with body ${type})`, async (t) => {
const p = tspl(t, { plan: 1 })

Expand Down Expand Up @@ -217,7 +217,7 @@ for (const { AbortControllerImpl, controllerName } of controllers) {
writeHeadersStartedWithBody(new Uint8Array([42]), 'Uint8Array')
writeHeadersStartedWithBody(wrapWithAsyncIterable(createReadStream(__filename)), 'async-iterator')

function writeBodyStartedWithBody (body, type) { // eslint-disable-line
function writeBodyStartedWithBody (body, type) {
test(`Abort ${controllerName} while waiting response (write headers and write body started) (with body ${type})`, async (t) => {
const p = tspl(t, { plan: 2 })

Expand Down
2 changes: 1 addition & 1 deletion test/node-test/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ test('factory option with basic get request', async (t) => {
}
}

const client = new BalancedPool([], opts) // eslint-disable-line
const client = new BalancedPool([], opts)

let serverCalled = 0
const server = createServer((req, res) => {
Expand Down
16 changes: 8 additions & 8 deletions test/node-test/client-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ test('invalid options throws', (t, done) => {
try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
keepAliveTimeout: 'asd'
}) // eslint-disable-line
})
assert.ok(0)
} catch (err) {
assert.ok(err instanceof errors.InvalidArgumentError)
Expand All @@ -322,7 +322,7 @@ test('invalid options throws', (t, done) => {
try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
localAddress: 123
}) // eslint-disable-line
})
assert.ok(0)
} catch (err) {
assert.ok(err instanceof errors.InvalidArgumentError)
Expand All @@ -332,7 +332,7 @@ test('invalid options throws', (t, done) => {
try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
localAddress: 'abcd123'
}) // eslint-disable-line
})
assert.ok(0)
} catch (err) {
assert.ok(err instanceof errors.InvalidArgumentError)
Expand All @@ -342,7 +342,7 @@ test('invalid options throws', (t, done) => {
try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
keepAliveMaxTimeout: 'asd'
}) // eslint-disable-line
})
assert.ok(0)
} catch (err) {
assert.ok(err instanceof errors.InvalidArgumentError)
Expand All @@ -352,7 +352,7 @@ test('invalid options throws', (t, done) => {
try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
keepAliveMaxTimeout: 0
}) // eslint-disable-line
})
assert.ok(0)
} catch (err) {
assert.ok(err instanceof errors.InvalidArgumentError)
Expand All @@ -362,7 +362,7 @@ test('invalid options throws', (t, done) => {
try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
keepAliveTimeoutThreshold: 'asd'
}) // eslint-disable-line
})
assert.ok(0)
} catch (err) {
assert.ok(err instanceof errors.InvalidArgumentError)
Expand Down Expand Up @@ -408,7 +408,7 @@ test('invalid options throws', (t, done) => {
}

try {
const client = new Client(new URL('http://localhost:200')) // eslint-disable-line
const client = new Client(new URL('http://localhost:200'))
client.destroy(null, null)
assert.ok(0)
} catch (err) {
Expand All @@ -417,7 +417,7 @@ test('invalid options throws', (t, done) => {
}

try {
const client = new Client(new URL('http://localhost:200')) // eslint-disable-line
const client = new Client(new URL('http://localhost:200'))
client.close(null, null)
assert.ok(0)
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions test/types/agent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))

// request
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: '', path: '', method: 'GET' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: '', path: '', method: 'GET', onInfo: ((info) => {}) }))
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: '', path: '', method: 'GET', onInfo: (info) => {} }))
expectAssignable<Promise<Dispatcher.ResponseData>>(agent.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
expectAssignable<void>(agent.request({ origin: '', path: '', method: 'GET' }, (err, data) => {
expectAssignable<Error | null>(err)
Expand All @@ -33,7 +33,7 @@ expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))
expectAssignable<Promise<Dispatcher.StreamData>>(agent.stream({ origin: '', path: '', method: 'GET', onInfo: ((info) => {}) }, data => {
expectAssignable<Promise<Dispatcher.StreamData>>(agent.stream({ origin: '', path: '', method: 'GET', onInfo: (info) => {} }, data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))
Expand Down Expand Up @@ -69,7 +69,7 @@ expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
expectAssignable<Duplex>(agent.pipeline({ origin: '', path: '', method: 'GET', onInfo: ((info) => {}) }, data => {
expectAssignable<Duplex>(agent.pipeline({ origin: '', path: '', method: 'GET', onInfo: (info) => {} }, data => {
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
Expand Down
3 changes: 1 addition & 2 deletions test/types/balanced-pool.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expectAssignable<BalancedPool>(new BalancedPool('', { factory: () => new Dispatc
expectAssignable<BalancedPool>(new BalancedPool('', { factory: (origin, opts) => new Client(origin, opts) }))
expectAssignable<BalancedPool>(new BalancedPool('', { connections: 1 }))
expectAssignable<BalancedPool>(new BalancedPool(['http://localhost:4242', 'http://www.nodejs.org']))
expectAssignable<BalancedPool>(new BalancedPool([new URL('http://localhost:4242'),new URL('http://www.nodejs.org')], {}))
expectAssignable<BalancedPool>(new BalancedPool([new URL('http://localhost:4242'), new URL('http://www.nodejs.org')], {}))

{
const pool = new BalancedPool('', {})
Expand All @@ -26,7 +26,6 @@ expectAssignable<BalancedPool>(new BalancedPool([new URL('http://localhost:4242'
expectAssignable<BalancedPool>(pool.removeUpstream(new URL('http://www.nodejs.org')))
expectAssignable<string[]>(pool.upstreams)


// request
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
Expand Down
6 changes: 3 additions & 3 deletions test/types/client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ expectAssignable<Client>(new Client(new URL('http://localhost'), {}))
expectAssignable<Client>(new Client('', {
interceptors: {
Client: [(dispatcher) => {
expectAssignable<Dispatcher['dispatch']>(dispatcher);
expectAssignable<Dispatcher['dispatch']>(dispatcher)
return (opts, handlers) => {
expectAssignable<Dispatcher.DispatchOptions>(opts);
expectAssignable<Dispatcher.DispatchHandlers>(handlers);
expectAssignable<Dispatcher.DispatchOptions>(opts)
expectAssignable<Dispatcher.DispatchHandlers>(handlers)
return dispatcher(opts, handlers)
}
}]
Expand Down
23 changes: 11 additions & 12 deletions test/types/connector.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {expectAssignable} from 'tsd'
import { expectAssignable } from 'tsd'
import { Client, buildConnector } from '../..'
import {ConnectionOptions, TLSSocket} from 'tls'
import {Socket} from 'net'
import {IpcNetConnectOpts, NetConnectOpts, TcpNetConnectOpts} from "net";
import { TLSSocket } from 'tls'
import { Socket } from 'net'

const connector = buildConnector({ rejectUnauthorized: false, allowH2: false })
expectAssignable<Client>(new Client('', {
Expand All @@ -26,13 +25,13 @@ expectAssignable<buildConnector.BuildOptions>({
checkServerIdentity: () => undefined, // Test if ConnectionOptions is assignable
localPort: 1234, // Test if TcpNetConnectOpts is assignable
keepAlive: true,
keepAliveInitialDelay: 12345,
});
keepAliveInitialDelay: 12345
})

expectAssignable<buildConnector.Options>({
protocol: "http",
hostname: "example.com",
port: "",
localAddress: "127.0.0.1",
httpSocket: new Socket(),
});
protocol: 'http',
hostname: 'example.com',
port: '',
localAddress: '127.0.0.1',
httpSocket: new Socket()
})
Loading
Loading