Skip to content

Commit

Permalink
chore: replace standard and snazzy with neostandard (#3485)
Browse files Browse the repository at this point in the history
* use neostandard, drop standard and snazzy

* apply automated fixes

* fix manually linting errors

* adapt recommended changes

* add neostandard badge

* remove node_modules

* remove no-lone-blocks

* fix linting issues

* disable jsx, use cache, remove jest env
  • Loading branch information
Uzlopak authored Aug 21, 2024
1 parent c1654af commit 26004bf
Show file tree
Hide file tree
Showing 68 changed files with 704 additions and 680 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# undici

[![Node CI](https://github.com/nodejs/undici/actions/workflows/nodejs.yml/badge.svg)](https://github.com/nodejs/undici/actions/workflows/nodejs.yml) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![npm version](https://badge.fury.io/js/undici.svg)](https://badge.fury.io/js/undici) [![codecov](https://codecov.io/gh/nodejs/undici/branch/main/graph/badge.svg?token=yZL6LtXkOA)](https://codecov.io/gh/nodejs/undici)
[![Node CI](https://github.com/nodejs/undici/actions/workflows/nodejs.yml/badge.svg)](https://github.com/nodejs/undici/actions/workflows/nodejs.yml) [![neostandard javascript style](https://img.shields.io/badge/neo-standard-7fffff?style=flat\&labelColor=ff80ff)](https://github.com/neostandard/neostandard) [![npm version](https://badge.fury.io/js/undici.svg)](https://badge.fury.io/js/undici) [![codecov](https://codecov.io/gh/nodejs/undici/branch/main/graph/badge.svg?token=yZL6LtXkOA)](https://codecov.io/gh/nodejs/undici)

An HTTP/1.1 client, written from scratch for Node.js.

Expand Down
27 changes: 27 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const neo = require('neostandard')

module.exports = [
...neo({
ignores: [
'lib/llhttp',
'test/fixtures/wpt',
'undici-fetch.js'
],
noJsx: true,
ts: true
}),
{
rules: {
'@stylistic/comma-dangle': ['error', {
arrays: 'never',
objects: 'never',
imports: 'never',
exports: 'never',
functions: 'never'
}],
'@typescript-eslint/no-redeclare': 'off'
}
}
]
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
18 changes: 4 additions & 14 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 --cache",
"lint:fix": "eslint --fix --cache",
"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,35 +111,25 @@
"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"
},
"engines": {
"node": ">=18.17"
},
"standard": {
"env": [
"jest"
],
"ignore": [
"lib/llhttp/constants.js",
"lib/llhttp/utils.js",
"test/fixtures/wpt"
]
},
"tsd": {
"directory": "test/types",
"compilerOptions": {
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()
2 changes: 1 addition & 1 deletion test/jest/mock-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { request, setGlobalDispatcher, MockAgent } = require('../..')
const { getResponse } = require('../../lib/mock/mock-utils')

/* global describe, it, expect */
/* global describe, it, afterEach, expect */

describe('MockAgent', () => {
let mockAgent
Expand Down
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' }")
})
})
2 changes: 2 additions & 0 deletions test/node-fetch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,8 @@ describe('node-fetch', () => {
)
})

/* global expect */

// TODO: fix test.
it.skip('should timeout on cloning response without consuming one of the streams when the second packet size is equal default highWaterMark', { timeout: 300 }, function () {
const url = local.mockState(res => {
Expand Down
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
Loading

0 comments on commit 26004bf

Please sign in to comment.