Skip to content

Commit

Permalink
Fix eslint violations (#3078)
Browse files Browse the repository at this point in the history
Co-authored-by: alxndrsn <alxndrsn>
  • Loading branch information
alxndrsn committed Oct 19, 2023
1 parent b9a528c commit 16322c2
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 50 deletions.
5 changes: 4 additions & 1 deletion docs/theme.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export default {
head: (
<>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="node-postgres is a collection of node.js modules for interfacing with your PostgreSQL database." />
<meta
name="description"
content="node-postgres is a collection of node.js modules for interfacing with your PostgreSQL database."
/>
<meta name="og:title" content="node-postgres" />
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-100138145-1"></script>
<script
Expand Down
21 changes: 18 additions & 3 deletions packages/pg-cursor/test/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@ describe('error handling', function () {
const queuedRead1 = cursor.read(1)
const queuedRead2 = cursor.read(1)

assert(await immediateRead.then(() => null, (err) => err))
assert(await queuedRead1.then(() => null, (err) => err))
assert(await queuedRead2.then(() => null, (err) => err))
assert(
await immediateRead.then(
() => null,
(err) => err
)
)
assert(
await queuedRead1.then(
() => null,
(err) => err
)
)
assert(
await queuedRead2.then(
() => null,
(err) => err
)
)

client.end()
})
Expand Down
6 changes: 3 additions & 3 deletions packages/pg-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function promisify(Promise, callback) {
const result = new Promise(function (resolve, reject) {
res = resolve
rej = reject
}).catch(err => {
}).catch((err) => {
// replace the stack trace that leads to `TCP.onStreamRead` with one that leads back to the
// application that created the query
Error.captureStackTrace(err);
throw err;
Error.captureStackTrace(err)
throw err
})
return { callback: cb, result: result }
}
Expand Down
6 changes: 5 additions & 1 deletion packages/pg-pool/test/idle-timeout-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ if (module === require.main) {
const allowExitOnIdle = process.env.ALLOW_EXIT_ON_IDLE === '1'
const Pool = require('../index')

const pool = new Pool({ maxLifetimeSeconds: 2, idleTimeoutMillis: 200, ...(allowExitOnIdle ? { allowExitOnIdle: true } : {}) })
const pool = new Pool({
maxLifetimeSeconds: 2,
idleTimeoutMillis: 200,
...(allowExitOnIdle ? { allowExitOnIdle: true } : {}),
})
pool.query('SELECT NOW()', (err, res) => console.log('completed first'))
pool.on('remove', () => {
console.log('removed')
Expand Down
3 changes: 1 addition & 2 deletions packages/pg/bench.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const pg = require('./lib')

const params = {
text:
'select typname, typnamespace, typowner, typlen, typbyval, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray from pg_type where typtypmod = $1 and typisdefined = $2',
text: 'select typname, typnamespace, typowner, typlen, typbyval, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray from pg_type where typtypmod = $1 and typisdefined = $2',
values: [-1, true],
}

Expand Down
6 changes: 3 additions & 3 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,11 @@ class Client extends EventEmitter {
if (!query.callback) {
result = new this._Promise((resolve, reject) => {
query.callback = (err, res) => (err ? reject(err) : resolve(res))
}).catch(err => {
}).catch((err) => {
// replace the stack trace that leads to `TCP.onStreamRead` with one that leads back to the
// application that created the query
Error.captureStackTrace(err);
throw err;
Error.captureStackTrace(err)
throw err
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pg/lib/crypto/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ if (useLegacyCrypto) {
// We are on an old version of Node.js that requires legacy crypto utilities.
module.exports = require('./utils-legacy')
} else {
module.exports = require('./utils-webcrypto');
module.exports = require('./utils-webcrypto')
}
6 changes: 3 additions & 3 deletions packages/pg/lib/native/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ Client.prototype.query = function (config, values, callback) {
result = new this._Promise((resolve, reject) => {
resolveOut = resolve
rejectOut = reject
}).catch(err => {
Error.captureStackTrace(err);
throw err;
}).catch((err) => {
Error.captureStackTrace(err)
throw err
})
query.callback = (err, res) => (err ? rejectOut(err) : resolveOut(res))
}
Expand Down
3 changes: 1 addition & 2 deletions packages/pg/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class Query extends EventEmitter {
if (this.callback) {
try {
this.callback(null, this._results)
}
catch(err) {
} catch (err) {
process.nextTick(() => {
throw err
})
Expand Down
32 changes: 16 additions & 16 deletions packages/pg/test/integration/client/async-stack-trace-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@ process.on('unhandledRejection', function (e) {
const suite = new helper.Suite()

// these tests will only work for if --async-stack-traces is on, which is the default starting in node 16.
const NODE_MAJOR_VERSION = +process.versions.node.split('.')[0];
const NODE_MAJOR_VERSION = +process.versions.node.split('.')[0]
if (NODE_MAJOR_VERSION >= 16) {
suite.testAsync('promise API async stack trace in pool', async function outerFunction() {
async function innerFunction() {
const pool = new pg.Pool()
await pool.query('SELECT test from nonexistent');
await pool.query('SELECT test from nonexistent')
}
try {
await innerFunction();
throw Error("should have errored");
await innerFunction()
throw Error('should have errored')
} catch (e) {
const stack = e.stack;
if(!e.stack.includes("innerFunction") || !e.stack.includes("outerFunction")) {
throw Error("async stack trace does not contain wanted values: " + stack);
const stack = e.stack
if (!e.stack.includes('innerFunction') || !e.stack.includes('outerFunction')) {
throw Error('async stack trace does not contain wanted values: ' + stack)
}
}
})

suite.testAsync('promise API async stack trace in client', async function outerFunction() {
async function innerFunction() {
const client = new pg.Client()
await client.connect();
await client.connect()
try {
await client.query('SELECT test from nonexistent');
await client.query('SELECT test from nonexistent')
} finally {
client.end();
client.end()
}
}
try {
await innerFunction();
throw Error("should have errored");
await innerFunction()
throw Error('should have errored')
} catch (e) {
const stack = e.stack;
if(!e.stack.includes("innerFunction") || !e.stack.includes("outerFunction")) {
throw Error("async stack trace does not contain wanted values: " + stack);
const stack = e.stack
if (!e.stack.includes('innerFunction') || !e.stack.includes('outerFunction')) {
throw Error('async stack trace does not contain wanted values: ' + stack)
}
}
})
}
}
2 changes: 1 addition & 1 deletion packages/pg/test/integration/client/sasl-scram-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ suite.testAsync('sasl/scram fails when password is empty', async () => {
...config,
// We use a password function here so the connection defaults do not
// override the empty string value with one from process.env.PGPASSWORD
password: () => '',
password: () => '',
})
let usingSasl = false
client.connection.once('authenticationSASL', () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/pg/test/integration/gh-issues/3062-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ suite.testAsync('result fields with the same name should pick the last value', a
const client = new helper.pg.Client()
await client.connect()

const { rows: [shouldBeNullRow] } = await client.query('SELECT NULL AS test, 10 AS test, NULL AS test')
const {
rows: [shouldBeNullRow],
} = await client.query('SELECT NULL AS test, 10 AS test, NULL AS test')
assert.equal(shouldBeNullRow.test, null)

const { rows: [shouldBeTwelveRow] } = await client.query('SELECT NULL AS test, 10 AS test, 12 AS test')
const {
rows: [shouldBeTwelveRow],
} = await client.query('SELECT NULL AS test, 10 AS test, 12 AS test')
assert.equal(shouldBeTwelveRow.test, 12)

const { rows: [shouldBeAbcRow] } = await client.query(`SELECT NULL AS test, 10 AS test, 12 AS test, 'ABC' AS test`)
const {
rows: [shouldBeAbcRow],
} = await client.query(`SELECT NULL AS test, 10 AS test, 12 AS test, 'ABC' AS test`)
assert.equal(shouldBeAbcRow.test, 'ABC')

await client.end()
Expand Down
3 changes: 1 addition & 2 deletions packages/pg/test/integration/gh-issues/787-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const pool = new helper.pg.Pool()

pool.connect(function (err, client) {
var q = {
name:
'This is a super long query name just so I can test that an error message is properly spit out to console.error without throwing an exception or anything',
name: 'This is a super long query name just so I can test that an error message is properly spit out to console.error without throwing an exception or anything',
text: 'SELECT NOW()',
}
client.query(q, function () {
Expand Down
6 changes: 2 additions & 4 deletions packages/pg/test/unit/client/escape-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ var testLit = function (testName, input, expected) {
var actual = Client.prototype.escapeLiteral(input)
assert.equal(expected, actual)
})



test('utils.' + testName, function () {
var actual = utils.escapeLiteral(input)
assert.equal(expected, actual)
Expand All @@ -39,8 +38,7 @@ var testIdent = function (testName, input, expected) {
var actual = Client.prototype.escapeIdentifier(input)
assert.equal(expected, actual)
})



test('utils.' + testName, function () {
var actual = utils.escapeIdentifier(input)
assert.equal(expected, actual)
Expand Down
30 changes: 25 additions & 5 deletions packages/pg/test/unit/utils-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,17 @@ testEscapeLiteral('escapeLiteral: contains backslashes only', 'hello \\ world',

testEscapeLiteral('escapeLiteral: contains single quotes and double quotes', 'hello \' " world', "'hello '' \" world'")

testEscapeLiteral('escapeLiteral: contains double quotes and backslashes', 'hello \\ " world', " E'hello \\\\ \" world'")
testEscapeLiteral(
'escapeLiteral: contains double quotes and backslashes',
'hello \\ " world',
" E'hello \\\\ \" world'"
)

testEscapeLiteral('escapeLiteral: contains single quotes and backslashes', "hello \\ ' world", " E'hello \\\\ '' world'")
testEscapeLiteral(
'escapeLiteral: contains single quotes and backslashes',
"hello \\ ' world",
" E'hello \\\\ '' world'"
)

testEscapeLiteral(
'escapeLiteral: contains single quotes, double quotes, and backslashes',
Expand All @@ -281,11 +289,23 @@ testEscapeIdentifier('escapeIdentifier: contains single quotes only', "hello ' w

testEscapeIdentifier('escapeIdentifier: contains backslashes only', 'hello \\ world', '"hello \\ world"')

testEscapeIdentifier('escapeIdentifier: contains single quotes and double quotes', 'hello \' " world', '"hello \' "" world"')
testEscapeIdentifier(
'escapeIdentifier: contains single quotes and double quotes',
'hello \' " world',
'"hello \' "" world"'
)

testEscapeIdentifier('escapeIdentifier: contains double quotes and backslashes', 'hello \\ " world', '"hello \\ "" world"')
testEscapeIdentifier(
'escapeIdentifier: contains double quotes and backslashes',
'hello \\ " world',
'"hello \\ "" world"'
)

testEscapeIdentifier('escapeIdentifier: contains single quotes and backslashes', "hello \\ ' world", '"hello \\ \' world"')
testEscapeIdentifier(
'escapeIdentifier: contains single quotes and backslashes',
"hello \\ ' world",
'"hello \\ \' world"'
)

testEscapeIdentifier(
'escapeIdentifier: contains single quotes, double quotes, and backslashes',
Expand Down

0 comments on commit 16322c2

Please sign in to comment.