Skip to content

Commit 9b51037

Browse files
authored
eslint: enable recommended ruleset (#3263)
1 parent 5a8b1a7 commit 9b51037

File tree

18 files changed

+51
-40
lines changed

18 files changed

+51
-40
lines changed

Diff for: .eslintrc

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"plugins": ["@typescript-eslint", "prettier"],
33
"parser": "@typescript-eslint/parser",
4-
"extends": ["plugin:prettier/recommended", "prettier"],
4+
"extends": ["eslint:recommended", "plugin:prettier/recommended", "prettier"],
55
"ignorePatterns": ["node_modules", "coverage", "packages/pg-protocol/dist/**/*", "packages/pg-query-stream/dist/**/*"],
66
"parserOptions": {
77
"ecmaVersion": 2017,
@@ -17,5 +17,13 @@
1717
"args": "none"
1818
}],
1919
"no-unused-vars": "off"
20-
}
20+
},
21+
"overrides": [
22+
{
23+
"files": ["*.ts", "*.mts", "*.cts", "*.tsx"],
24+
"rules": {
25+
"no-undef": "off"
26+
}
27+
}
28+
]
2129
}

Diff for: packages/pg-cloudflare/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class CloudflareSocket extends EventEmitter {
6161
}
6262

6363
async _listen() {
64+
// eslint-disable-next-line no-constant-condition
6465
while (true) {
6566
log('awaiting receive from CF socket')
6667
const { done, value } = await this._cfReader!.read()

Diff for: packages/pg-connection-string/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function parse(str) {
1919
let dummyHost = false
2020
if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
2121
// Ensure spaces are encoded as %20
22-
str = encodeURI(str).replace(/\%25(\d\d)/g, '%$1')
22+
str = encodeURI(str).replace(/%25(\d\d)/g, '%$1')
2323
}
2424

2525
try {

Diff for: packages/pg-native/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ Client.prototype._emitResult = function (pq) {
183183
case 'PGRES_TUPLES_OK':
184184
case 'PGRES_COMMAND_OK':
185185
case 'PGRES_EMPTY_QUERY':
186-
const result = this._consumeQueryResults(this.pq)
187-
this.emit('result', result)
186+
{
187+
const result = this._consumeQueryResults(this.pq)
188+
this.emit('result', result)
189+
}
188190
break
189191

190192
case 'PGRES_COPY_OUT':

Diff for: packages/pg-pool/test/idle-timeout-exit.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if (module === require.main) {
1111
pool.query('SELECT NOW()', (err, res) => console.log('completed first'))
1212
pool.on('remove', () => {
1313
console.log('removed')
14-
done()
1514
})
1615

1716
setTimeout(() => {

Diff for: packages/pg-protocol/src/buffer-reader.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class BufferReader {
4646
public cstring(): string {
4747
const start = this.offset
4848
let end = start
49+
// eslint-disable-next-line no-empty
4950
while (this.buffer[end++] !== 0) {}
5051
this.offset = end
5152
return this.buffer.toString(this.encoding, start, end - 1)

Diff for: packages/pg-protocol/src/inbound-parser.test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,8 @@ var rowWithBigOids = {
5050
}
5151
var bigOidDescBuff = buffers.rowDescription([rowWithBigOids])
5252

53-
var emptyRowFieldBuf = new BufferList().addInt16(0).join(true, 'D')
54-
5553
var emptyRowFieldBuf = buffers.dataRow([])
5654

57-
var oneFieldBuf = new BufferList()
58-
.addInt16(1) // number of fields
59-
.addInt32(5) // length of bytes of fields
60-
.addCString('test')
61-
.join(true, 'D')
62-
6355
var oneFieldBuf = buffers.dataRow(['test'])
6456

6557
var expectedAuthenticationOkayMessage = {

Diff for: packages/pg-protocol/src/parser.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,17 @@ export class Parser {
328328
}
329329
break
330330
case 10: // AuthenticationSASL
331-
message.name = 'authenticationSASL'
332-
message.mechanisms = []
333-
let mechanism: string
334-
do {
335-
mechanism = this.reader.cstring()
336-
337-
if (mechanism) {
338-
message.mechanisms.push(mechanism)
339-
}
340-
} while (mechanism)
331+
{
332+
message.name = 'authenticationSASL'
333+
message.mechanisms = []
334+
let mechanism: string
335+
do {
336+
mechanism = this.reader.cstring()
337+
if (mechanism) {
338+
message.mechanisms.push(mechanism)
339+
}
340+
} while (mechanism)
341+
}
341342
break
342343
case 11: // AuthenticationSASLContinue
343344
message.name = 'authenticationSASLContinue'

Diff for: packages/pg-query-stream/test/error.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('error recovery', () => {
7575
const client = new Client()
7676
const stmt = 'SELECT * FROM goose;'
7777
await client.connect()
78-
return new Promise(async (resolve) => {
78+
return new Promise((resolve) => {
7979
let queryError: Error | undefined
8080
client.query(stmt).catch((e) => {
8181
queryError = e
@@ -86,7 +86,7 @@ describe('error recovery', () => {
8686
assert(queryError, 'query should have errored due to client ending')
8787
resolve()
8888
})
89-
await client.end()
89+
client.end()
9090
})
9191
})
9292

Diff for: packages/pg/bench.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const exec = async (client, q) => {
2525
const bench = async (client, q, time) => {
2626
let start = Date.now()
2727
let count = 0
28+
// eslint-disable-next-line no-constant-condition
2829
while (true) {
2930
await exec(client, q)
3031
count++

Diff for: packages/pg/lib/crypto/cert-signatures.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function x509Error(msg, cert) {
2-
throw new Error('SASL channel binding: ' + msg + ' when parsing public certificate ' + cert.toString('base64'))
2+
return new Error('SASL channel binding: ' + msg + ' when parsing public certificate ' + cert.toString('base64'))
33
}
44

55
function readASN1Length(data, index) {
66
let length = data[index++]
77
if (length < 0x80) return { length, index }
88

99
const lengthBytes = length & 0x7f
10-
if (lengthBytes > 4) x509Error('bad length', data)
10+
if (lengthBytes > 4) throw x509Error('bad length', data)
1111

1212
length = 0
1313
for (let i = 0; i < lengthBytes; i++) {
@@ -18,11 +18,11 @@ function readASN1Length(data, index) {
1818
}
1919

2020
function readASN1OID(data, index) {
21-
if (data[index++] !== 0x6) x509Error('non-OID data', data) // 6 = OID
21+
if (data[index++] !== 0x6) throw x509Error('non-OID data', data) // 6 = OID
2222

2323
const { length: OIDLength, index: indexAfterOIDLength } = readASN1Length(data, index)
2424
index = indexAfterOIDLength
25-
lastIndex = index + OIDLength
25+
let lastIndex = index + OIDLength
2626

2727
const byte1 = data[index++]
2828
let oid = ((byte1 / 40) >> 0) + '.' + (byte1 % 40)
@@ -43,7 +43,7 @@ function readASN1OID(data, index) {
4343
}
4444

4545
function expectASN1Seq(data, index) {
46-
if (data[index++] !== 0x30) x509Error('non-sequence data', data) // 30 = Sequence
46+
if (data[index++] !== 0x30) throw x509Error('non-sequence data', data) // 30 = Sequence
4747
return readASN1Length(data, index)
4848
}
4949

@@ -85,10 +85,10 @@ function signatureAlgorithmHashFromCertificate(data, index) {
8585
case '1.2.840.10045.4.3.4':
8686
return 'SHA-512'
8787
// RSASSA-PSS: hash is indicated separately
88-
case '1.2.840.113549.1.1.10':
88+
case '1.2.840.113549.1.1.10': {
8989
index = indexAfterOID
9090
index = expectASN1Seq(data, index).index
91-
if (data[index++] !== 0xa0) x509Error('non-tag data', data) // a0 = constructed tag 0
91+
if (data[index++] !== 0xa0) throw x509Error('non-tag data', data) // a0 = constructed tag 0
9292
index = readASN1Length(data, index).index // skip over tag length field
9393
index = expectASN1Seq(data, index).index // skip over sequence length field
9494
const { oid: hashOID } = readASN1OID(data, index)
@@ -105,17 +105,18 @@ function signatureAlgorithmHashFromCertificate(data, index) {
105105
case '2.16.840.1.101.3.4.2.3':
106106
return 'SHA-512'
107107
}
108-
x509Error('unknown hash OID ' + hashOID, data)
108+
throw x509Error('unknown hash OID ' + hashOID, data)
109+
}
109110
// Ed25519 -- see https: return//github.com/openssl/openssl/issues/15477
110111
case '1.3.101.110':
111112
case '1.3.101.112': // ph
112113
return 'SHA-512'
113114
// Ed448 -- still not in pg 17.2 (if supported, digest would be SHAKE256 x 64 bytes)
114115
case '1.3.101.111':
115116
case '1.3.101.113': // ph
116-
x509Error('Ed448 certificate channel binding is not currently supported by Postgres')
117+
throw x509Error('Ed448 certificate channel binding is not currently supported by Postgres')
117118
}
118-
x509Error('unknown OID ' + oid, data)
119+
throw x509Error('unknown OID ' + oid, data)
119120
}
120121

121122
module.exports = { signatureAlgorithmHashFromCertificate }

Diff for: packages/pg/lib/crypto/utils-webcrypto.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
* The Web Crypto API - grabbed from the Node.js library or the global
1515
* @type Crypto
1616
*/
17+
// eslint-disable-next-line no-undef
1718
const webCrypto = nodeCrypto.webcrypto || globalThis.crypto
1819
/**
1920
* The SubtleCrypto API for low level crypto operations.

Diff for: packages/pg/lib/native/client.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// eslint-disable-next-line
44
var Native
5+
// eslint-disable-next-line no-useless-catch
56
try {
67
// 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
78
Native = require('pg-native')

Diff for: packages/pg/lib/stream.js

+2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ function getCloudflareStreamFuncs() {
6060
function isCloudflareRuntime() {
6161
// Since 2022-03-21 the `global_navigator` compatibility flag is on for Cloudflare Workers
6262
// which means that `navigator.userAgent` will be defined.
63+
// eslint-disable-next-line no-undef
6364
if (typeof navigator === 'object' && navigator !== null && typeof navigator.userAgent === 'string') {
65+
// eslint-disable-next-line no-undef
6466
return navigator.userAgent === 'Cloudflare-Workers'
6567
}
6668
// In case `navigator` or `navigator.userAgent` is not defined then try a more sneaky approach

Diff for: packages/pg/test/integration/client/big-simple-query-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var runBigQuery = function (client) {
9999
function (err, result) {
100100
if (err != null) {
101101
console.log(err)
102-
throw Err
102+
throw err
103103
}
104104
assert.lengthIs(result.rows, 26)
105105
}

Diff for: packages/pg/test/integration/gh-issues/3174-tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const startMockServer = (port, badBuffer, callback) => {
6060
setImmediate(() => {
6161
socket.write(badBuffer)
6262
})
63+
break
6364
default:
6465
// console.log('got code', code)
6566
}

Diff for: packages/pg/test/unit/client/sasl-scram-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ suite.test('sasl/scram', function () {
225225
0x0d, // signature algorithm length
226226
0x06, // ASN.1 OID
227227
0x09, // OID length
228-
0x2a, // OID: 1.2.840.113549.1.1.11 (RSASSA-PKCS1-v1_5 / SHA-256)
228+
0x2a, // OID: 1.2.840.113549.1.1.11 (RSASSA-PKCS1-v1_5 / SHA-256)
229229
0x86,
230230
0x48,
231231
0x86,

Diff for: packages/pg/test/unit/connection-parameters/environment-variable-tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var defaults = require('../../../lib').defaults
77

88
// clear process.env
99
var realEnv = {}
10-
for (var key in process.env) {
10+
for (const key in process.env) {
1111
realEnv[key] = process.env[key]
1212
delete process.env[key]
1313
}
@@ -122,6 +122,6 @@ testVal('verify-full', true)
122122
testVal('no-verify', { rejectUnauthorized: false })
123123

124124
// restore process.env
125-
for (var key in realEnv) {
125+
for (const key in realEnv) {
126126
process.env[key] = realEnv[key]
127127
}

0 commit comments

Comments
 (0)