mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
eslint: enable recommended ruleset (#3263)
This commit is contained in:
parent
5a8b1a7d24
commit
9b510373a6
12
.eslintrc
12
.eslintrc
@ -1,7 +1,7 @@
|
||||
{
|
||||
"plugins": ["@typescript-eslint", "prettier"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"extends": ["plugin:prettier/recommended", "prettier"],
|
||||
"extends": ["eslint:recommended", "plugin:prettier/recommended", "prettier"],
|
||||
"ignorePatterns": ["node_modules", "coverage", "packages/pg-protocol/dist/**/*", "packages/pg-query-stream/dist/**/*"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017,
|
||||
@ -17,5 +17,13 @@
|
||||
"args": "none"
|
||||
}],
|
||||
"no-unused-vars": "off"
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.mts", "*.cts", "*.tsx"],
|
||||
"rules": {
|
||||
"no-undef": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -61,6 +61,7 @@ export class CloudflareSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
async _listen() {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
log('awaiting receive from CF socket')
|
||||
const { done, value } = await this._cfReader!.read()
|
||||
|
||||
@ -19,7 +19,7 @@ function parse(str) {
|
||||
let dummyHost = false
|
||||
if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
|
||||
// Ensure spaces are encoded as %20
|
||||
str = encodeURI(str).replace(/\%25(\d\d)/g, '%$1')
|
||||
str = encodeURI(str).replace(/%25(\d\d)/g, '%$1')
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -183,8 +183,10 @@ Client.prototype._emitResult = function (pq) {
|
||||
case 'PGRES_TUPLES_OK':
|
||||
case 'PGRES_COMMAND_OK':
|
||||
case 'PGRES_EMPTY_QUERY':
|
||||
const result = this._consumeQueryResults(this.pq)
|
||||
this.emit('result', result)
|
||||
{
|
||||
const result = this._consumeQueryResults(this.pq)
|
||||
this.emit('result', result)
|
||||
}
|
||||
break
|
||||
|
||||
case 'PGRES_COPY_OUT':
|
||||
|
||||
@ -11,7 +11,6 @@ if (module === require.main) {
|
||||
pool.query('SELECT NOW()', (err, res) => console.log('completed first'))
|
||||
pool.on('remove', () => {
|
||||
console.log('removed')
|
||||
done()
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
@ -46,6 +46,7 @@ export class BufferReader {
|
||||
public cstring(): string {
|
||||
const start = this.offset
|
||||
let end = start
|
||||
// eslint-disable-next-line no-empty
|
||||
while (this.buffer[end++] !== 0) {}
|
||||
this.offset = end
|
||||
return this.buffer.toString(this.encoding, start, end - 1)
|
||||
|
||||
@ -50,16 +50,8 @@ var rowWithBigOids = {
|
||||
}
|
||||
var bigOidDescBuff = buffers.rowDescription([rowWithBigOids])
|
||||
|
||||
var emptyRowFieldBuf = new BufferList().addInt16(0).join(true, 'D')
|
||||
|
||||
var emptyRowFieldBuf = buffers.dataRow([])
|
||||
|
||||
var oneFieldBuf = new BufferList()
|
||||
.addInt16(1) // number of fields
|
||||
.addInt32(5) // length of bytes of fields
|
||||
.addCString('test')
|
||||
.join(true, 'D')
|
||||
|
||||
var oneFieldBuf = buffers.dataRow(['test'])
|
||||
|
||||
var expectedAuthenticationOkayMessage = {
|
||||
|
||||
@ -328,16 +328,17 @@ export class Parser {
|
||||
}
|
||||
break
|
||||
case 10: // AuthenticationSASL
|
||||
message.name = 'authenticationSASL'
|
||||
message.mechanisms = []
|
||||
let mechanism: string
|
||||
do {
|
||||
mechanism = this.reader.cstring()
|
||||
|
||||
if (mechanism) {
|
||||
message.mechanisms.push(mechanism)
|
||||
}
|
||||
} while (mechanism)
|
||||
{
|
||||
message.name = 'authenticationSASL'
|
||||
message.mechanisms = []
|
||||
let mechanism: string
|
||||
do {
|
||||
mechanism = this.reader.cstring()
|
||||
if (mechanism) {
|
||||
message.mechanisms.push(mechanism)
|
||||
}
|
||||
} while (mechanism)
|
||||
}
|
||||
break
|
||||
case 11: // AuthenticationSASLContinue
|
||||
message.name = 'authenticationSASLContinue'
|
||||
|
||||
@ -75,7 +75,7 @@ describe('error recovery', () => {
|
||||
const client = new Client()
|
||||
const stmt = 'SELECT * FROM goose;'
|
||||
await client.connect()
|
||||
return new Promise(async (resolve) => {
|
||||
return new Promise((resolve) => {
|
||||
let queryError: Error | undefined
|
||||
client.query(stmt).catch((e) => {
|
||||
queryError = e
|
||||
@ -86,7 +86,7 @@ describe('error recovery', () => {
|
||||
assert(queryError, 'query should have errored due to client ending')
|
||||
resolve()
|
||||
})
|
||||
await client.end()
|
||||
client.end()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ const exec = async (client, q) => {
|
||||
const bench = async (client, q, time) => {
|
||||
let start = Date.now()
|
||||
let count = 0
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
await exec(client, q)
|
||||
count++
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
function x509Error(msg, cert) {
|
||||
throw new Error('SASL channel binding: ' + msg + ' when parsing public certificate ' + cert.toString('base64'))
|
||||
return new Error('SASL channel binding: ' + msg + ' when parsing public certificate ' + cert.toString('base64'))
|
||||
}
|
||||
|
||||
function readASN1Length(data, index) {
|
||||
@ -7,7 +7,7 @@ function readASN1Length(data, index) {
|
||||
if (length < 0x80) return { length, index }
|
||||
|
||||
const lengthBytes = length & 0x7f
|
||||
if (lengthBytes > 4) x509Error('bad length', data)
|
||||
if (lengthBytes > 4) throw x509Error('bad length', data)
|
||||
|
||||
length = 0
|
||||
for (let i = 0; i < lengthBytes; i++) {
|
||||
@ -18,11 +18,11 @@ function readASN1Length(data, index) {
|
||||
}
|
||||
|
||||
function readASN1OID(data, index) {
|
||||
if (data[index++] !== 0x6) x509Error('non-OID data', data) // 6 = OID
|
||||
if (data[index++] !== 0x6) throw x509Error('non-OID data', data) // 6 = OID
|
||||
|
||||
const { length: OIDLength, index: indexAfterOIDLength } = readASN1Length(data, index)
|
||||
index = indexAfterOIDLength
|
||||
lastIndex = index + OIDLength
|
||||
let lastIndex = index + OIDLength
|
||||
|
||||
const byte1 = data[index++]
|
||||
let oid = ((byte1 / 40) >> 0) + '.' + (byte1 % 40)
|
||||
@ -43,7 +43,7 @@ function readASN1OID(data, index) {
|
||||
}
|
||||
|
||||
function expectASN1Seq(data, index) {
|
||||
if (data[index++] !== 0x30) x509Error('non-sequence data', data) // 30 = Sequence
|
||||
if (data[index++] !== 0x30) throw x509Error('non-sequence data', data) // 30 = Sequence
|
||||
return readASN1Length(data, index)
|
||||
}
|
||||
|
||||
@ -85,10 +85,10 @@ function signatureAlgorithmHashFromCertificate(data, index) {
|
||||
case '1.2.840.10045.4.3.4':
|
||||
return 'SHA-512'
|
||||
// RSASSA-PSS: hash is indicated separately
|
||||
case '1.2.840.113549.1.1.10':
|
||||
case '1.2.840.113549.1.1.10': {
|
||||
index = indexAfterOID
|
||||
index = expectASN1Seq(data, index).index
|
||||
if (data[index++] !== 0xa0) x509Error('non-tag data', data) // a0 = constructed tag 0
|
||||
if (data[index++] !== 0xa0) throw x509Error('non-tag data', data) // a0 = constructed tag 0
|
||||
index = readASN1Length(data, index).index // skip over tag length field
|
||||
index = expectASN1Seq(data, index).index // skip over sequence length field
|
||||
const { oid: hashOID } = readASN1OID(data, index)
|
||||
@ -105,7 +105,8 @@ function signatureAlgorithmHashFromCertificate(data, index) {
|
||||
case '2.16.840.1.101.3.4.2.3':
|
||||
return 'SHA-512'
|
||||
}
|
||||
x509Error('unknown hash OID ' + hashOID, data)
|
||||
throw x509Error('unknown hash OID ' + hashOID, data)
|
||||
}
|
||||
// Ed25519 -- see https: return//github.com/openssl/openssl/issues/15477
|
||||
case '1.3.101.110':
|
||||
case '1.3.101.112': // ph
|
||||
@ -113,9 +114,9 @@ function signatureAlgorithmHashFromCertificate(data, index) {
|
||||
// Ed448 -- still not in pg 17.2 (if supported, digest would be SHAKE256 x 64 bytes)
|
||||
case '1.3.101.111':
|
||||
case '1.3.101.113': // ph
|
||||
x509Error('Ed448 certificate channel binding is not currently supported by Postgres')
|
||||
throw x509Error('Ed448 certificate channel binding is not currently supported by Postgres')
|
||||
}
|
||||
x509Error('unknown OID ' + oid, data)
|
||||
throw x509Error('unknown OID ' + oid, data)
|
||||
}
|
||||
|
||||
module.exports = { signatureAlgorithmHashFromCertificate }
|
||||
|
||||
@ -14,6 +14,7 @@ module.exports = {
|
||||
* The Web Crypto API - grabbed from the Node.js library or the global
|
||||
* @type Crypto
|
||||
*/
|
||||
// eslint-disable-next-line no-undef
|
||||
const webCrypto = nodeCrypto.webcrypto || globalThis.crypto
|
||||
/**
|
||||
* The SubtleCrypto API for low level crypto operations.
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
// eslint-disable-next-line
|
||||
var Native
|
||||
// eslint-disable-next-line no-useless-catch
|
||||
try {
|
||||
// Wrap this `require()` in a try-catch to avoid upstream bundlers from complaining that this might not be available since it is an optional import
|
||||
Native = require('pg-native')
|
||||
|
||||
@ -60,7 +60,9 @@ function getCloudflareStreamFuncs() {
|
||||
function isCloudflareRuntime() {
|
||||
// Since 2022-03-21 the `global_navigator` compatibility flag is on for Cloudflare Workers
|
||||
// which means that `navigator.userAgent` will be defined.
|
||||
// eslint-disable-next-line no-undef
|
||||
if (typeof navigator === 'object' && navigator !== null && typeof navigator.userAgent === 'string') {
|
||||
// eslint-disable-next-line no-undef
|
||||
return navigator.userAgent === 'Cloudflare-Workers'
|
||||
}
|
||||
// In case `navigator` or `navigator.userAgent` is not defined then try a more sneaky approach
|
||||
|
||||
@ -99,7 +99,7 @@ var runBigQuery = function (client) {
|
||||
function (err, result) {
|
||||
if (err != null) {
|
||||
console.log(err)
|
||||
throw Err
|
||||
throw err
|
||||
}
|
||||
assert.lengthIs(result.rows, 26)
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ const startMockServer = (port, badBuffer, callback) => {
|
||||
setImmediate(() => {
|
||||
socket.write(badBuffer)
|
||||
})
|
||||
break
|
||||
default:
|
||||
// console.log('got code', code)
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ suite.test('sasl/scram', function () {
|
||||
0x0d, // signature algorithm length
|
||||
0x06, // ASN.1 OID
|
||||
0x09, // OID length
|
||||
0x2a, // OID: 1.2.840.113549.1.1.11 (RSASSA-PKCS1-v1_5 / SHA-256)
|
||||
0x2a, // OID: 1.2.840.113549.1.1.11 (RSASSA-PKCS1-v1_5 / SHA-256)
|
||||
0x86,
|
||||
0x48,
|
||||
0x86,
|
||||
|
||||
@ -7,7 +7,7 @@ var defaults = require('../../../lib').defaults
|
||||
|
||||
// clear process.env
|
||||
var realEnv = {}
|
||||
for (var key in process.env) {
|
||||
for (const key in process.env) {
|
||||
realEnv[key] = process.env[key]
|
||||
delete process.env[key]
|
||||
}
|
||||
@ -122,6 +122,6 @@ testVal('verify-full', true)
|
||||
testVal('no-verify', { rejectUnauthorized: false })
|
||||
|
||||
// restore process.env
|
||||
for (var key in realEnv) {
|
||||
for (const key in realEnv) {
|
||||
process.env[key] = realEnv[key]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user