Skip to content

Commit 423baa6

Browse files
committed
Update lint rules for pg-cursor
1 parent 37d1574 commit 423baa6

14 files changed

+348
-125
lines changed

.eslintrc

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
{
2-
"plugins": [
3-
"node"
4-
],
5-
"extends": [
6-
"standard",
7-
"eslint:recommended",
8-
"plugin:node/recommended"
9-
],
2+
"plugins": ["node"],
3+
"extends": ["standard", "eslint:recommended", "plugin:node/recommended"],
104
"parserOptions": {
115
"ecmaVersion": 2017
126
},
137
"env": {
148
"node": true,
15-
"es6": true
9+
"es6": true,
10+
"mocha": true
1611
},
1712
"rules": {
13+
"space-before-function-paren": "off",
14+
"node/no-unpublished-require": [
15+
"error",
16+
{
17+
"allowModules": ["pg"]
18+
}
19+
]
1820
}
1921
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"packages/*"
1111
],
1212
"scripts": {
13-
"test": "yarn lerna exec --parallel yarn test"
13+
"test": "yarn lerna exec --parallel yarn test",
14+
"lint": "yarn lerna exec --parallel yarn lint"
1415
},
1516
"devDependencies": {
1617
"lerna": "^3.19.0"

packages/pg-cursor/.eslintrc

-17
This file was deleted.

packages/pg-cursor/index.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const util = require('util')
66

77
let nextUniqueID = 1 // concept borrowed from org.postgresql.core.v3.QueryExecutorImpl
88

9-
function Cursor(text, values, config) {
9+
function Cursor (text, values, config) {
1010
EventEmitter.call(this)
1111

1212
this._conf = config || {}
@@ -25,42 +25,42 @@ function Cursor(text, values, config) {
2525

2626
util.inherits(Cursor, EventEmitter)
2727

28-
Cursor.prototype._ifNoData = function() {
28+
Cursor.prototype._ifNoData = function () {
2929
this.state = 'idle'
3030
this._shiftQueue()
3131
}
3232

33-
Cursor.prototype._rowDescription = function() {
33+
Cursor.prototype._rowDescription = function () {
3434
if (this.connection) {
3535
this.connection.removeListener('noData', this._ifNoData)
3636
}
3737
}
3838

39-
Cursor.prototype.submit = function(connection) {
39+
Cursor.prototype.submit = function (connection) {
4040
this.connection = connection
4141
this._portal = 'C_' + nextUniqueID++
4242

4343
const con = connection
4444

4545
con.parse(
4646
{
47-
text: this.text,
47+
text: this.text
4848
},
4949
true
5050
)
5151

5252
con.bind(
5353
{
5454
portal: this._portal,
55-
values: this.values,
55+
values: this.values
5656
},
5757
true
5858
)
5959

6060
con.describe(
6161
{
6262
type: 'P',
63-
name: this._portal, // AWS Redshift requires a portal name
63+
name: this._portal // AWS Redshift requires a portal name
6464
},
6565
true
6666
)
@@ -75,13 +75,13 @@ Cursor.prototype.submit = function(connection) {
7575
con.once('rowDescription', this._rowDescription)
7676
}
7777

78-
Cursor.prototype._shiftQueue = function() {
78+
Cursor.prototype._shiftQueue = function () {
7979
if (this._queue.length) {
8080
this._getRows.apply(this, this._queue.shift())
8181
}
8282
}
8383

84-
Cursor.prototype._closePortal = function() {
84+
Cursor.prototype._closePortal = function () {
8585
// because we opened a named portal to stream results
8686
// we need to close the same named portal. Leaving a named portal
8787
// open can lock tables for modification if inside a transaction.
@@ -90,19 +90,19 @@ Cursor.prototype._closePortal = function() {
9090
this.connection.sync()
9191
}
9292

93-
Cursor.prototype.handleRowDescription = function(msg) {
93+
Cursor.prototype.handleRowDescription = function (msg) {
9494
this._result.addFields(msg.fields)
9595
this.state = 'idle'
9696
this._shiftQueue()
9797
}
9898

99-
Cursor.prototype.handleDataRow = function(msg) {
99+
Cursor.prototype.handleDataRow = function (msg) {
100100
const row = this._result.parseRow(msg.fields)
101101
this.emit('row', row, this._result)
102102
this._rows.push(row)
103103
}
104104

105-
Cursor.prototype._sendRows = function() {
105+
Cursor.prototype._sendRows = function () {
106106
this.state = 'idle'
107107
setImmediate(() => {
108108
const cb = this._cb
@@ -118,26 +118,26 @@ Cursor.prototype._sendRows = function() {
118118
})
119119
}
120120

121-
Cursor.prototype.handleCommandComplete = function(msg) {
121+
Cursor.prototype.handleCommandComplete = function (msg) {
122122
this._result.addCommandComplete(msg)
123123
this._closePortal()
124124
}
125125

126-
Cursor.prototype.handlePortalSuspended = function() {
126+
Cursor.prototype.handlePortalSuspended = function () {
127127
this._sendRows()
128128
}
129129

130-
Cursor.prototype.handleReadyForQuery = function() {
130+
Cursor.prototype.handleReadyForQuery = function () {
131131
this._sendRows()
132132
this.state = 'done'
133133
this.emit('end', this._result)
134134
}
135135

136-
Cursor.prototype.handleEmptyQuery = function() {
136+
Cursor.prototype.handleEmptyQuery = function () {
137137
this.connection.sync()
138138
}
139139

140-
Cursor.prototype.handleError = function(msg) {
140+
Cursor.prototype.handleError = function (msg) {
141141
this.connection.removeListener('noData', this._ifNoData)
142142
this.connection.removeListener('rowDescription', this._rowDescription)
143143
this.state = 'error'
@@ -159,29 +159,29 @@ Cursor.prototype.handleError = function(msg) {
159159
this.connection.sync()
160160
}
161161

162-
Cursor.prototype._getRows = function(rows, cb) {
162+
Cursor.prototype._getRows = function (rows, cb) {
163163
this.state = 'busy'
164164
this._cb = cb
165165
this._rows = []
166166
const msg = {
167167
portal: this._portal,
168-
rows: rows,
168+
rows: rows
169169
}
170170
this.connection.execute(msg, true)
171171
this.connection.flush()
172172
}
173173

174174
// users really shouldn't be calling 'end' here and terminating a connection to postgres
175175
// via the low level connection.end api
176-
Cursor.prototype.end = util.deprecate(function(cb) {
176+
Cursor.prototype.end = util.deprecate(function (cb) {
177177
if (this.state !== 'initialized') {
178178
this.connection.sync()
179179
}
180180
this.connection.once('end', cb)
181181
this.connection.end()
182182
}, 'Cursor.end is deprecated. Call end on the client itself to end a connection to the database.')
183183

184-
Cursor.prototype.close = function(cb) {
184+
Cursor.prototype.close = function (cb) {
185185
if (this.state === 'done') {
186186
if (cb) {
187187
return setImmediate(cb)
@@ -192,13 +192,13 @@ Cursor.prototype.close = function(cb) {
192192
this._closePortal()
193193
this.state = 'done'
194194
if (cb) {
195-
this.connection.once('closeComplete', function() {
195+
this.connection.once('closeComplete', function () {
196196
cb()
197197
})
198198
}
199199
}
200200

201-
Cursor.prototype.read = function(rows, cb) {
201+
Cursor.prototype.read = function (rows, cb) {
202202
if (this.state === 'idle') {
203203
return this._getRows(rows, cb)
204204
}

packages/pg-cursor/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"test": "test"
88
},
99
"scripts": {
10-
"test": " mocha && eslint ."
10+
"test": "mocha && eslint .",
11+
"lint": "eslint ."
1112
},
1213
"repository": {
1314
"type": "git",
@@ -26,7 +27,7 @@
2627
"prettier": {
2728
"semi": false,
2829
"printWidth": 120,
29-
"trailingComma": "es5",
30+
"trailingComma": "none",
3031
"singleQuote": true
3132
}
3233
}

packages/pg-cursor/test/close.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@ const Cursor = require('../')
33
const pg = require('pg')
44

55
const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
6-
describe('close', function() {
7-
beforeEach(function(done) {
6+
describe('close', function () {
7+
beforeEach(function (done) {
88
const client = (this.client = new pg.Client())
99
client.connect(done)
1010
client.on('drain', client.end.bind(client))
1111
})
1212

13-
it('can close a finished cursor without a callback', function(done) {
13+
it('can close a finished cursor without a callback', function (done) {
1414
const cursor = new Cursor(text)
1515
this.client.query(cursor)
1616
this.client.query('SELECT NOW()', done)
17-
cursor.read(100, function(err) {
17+
cursor.read(100, function (err) {
1818
assert.ifError(err)
1919
cursor.close()
2020
})
2121
})
2222

23-
it('closes cursor early', function(done) {
23+
it('closes cursor early', function (done) {
2424
const cursor = new Cursor(text)
2525
this.client.query(cursor)
2626
this.client.query('SELECT NOW()', done)
27-
cursor.read(25, function(err) {
27+
cursor.read(25, function (err) {
2828
assert.ifError(err)
2929
cursor.close()
3030
})
3131
})
3232

33-
it('works with callback style', function(done) {
33+
it('works with callback style', function (done) {
3434
const cursor = new Cursor(text)
3535
const client = this.client
3636
client.query(cursor)
37-
cursor.read(25, function(err) {
37+
cursor.read(25, function (err) {
3838
assert.ifError(err)
39-
cursor.close(function(err) {
39+
cursor.close(function (err) {
4040
assert.ifError(err)
4141
client.query('SELECT NOW()', done)
4242
})

packages/pg-cursor/test/error-handling.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ describe('read callback does not fire sync', () => {
2929
let after = false
3030
cursor.read(1, function(err) {
3131
assert(err, 'error should be returned')
32-
assert.equal(after, true, 'should not call read sync')
32+
assert.strictEqual(after, true, 'should not call read sync')
3333
after = false
3434
cursor.read(1, function(err) {
3535
assert(err, 'error should be returned')
36-
assert.equal(after, true, 'should not call read sync')
36+
assert.strictEqual(after, true, 'should not call read sync')
3737
client.end()
3838
done()
3939
})
@@ -49,13 +49,13 @@ describe('read callback does not fire sync', () => {
4949
let after = false
5050
cursor.read(1, function(err) {
5151
assert(!err)
52-
assert.equal(after, true, 'should not call read sync')
52+
assert.strictEqual(after, true, 'should not call read sync')
5353
cursor.read(1, function(err) {
5454
assert(!err)
5555
after = false
5656
cursor.read(1, function(err) {
5757
assert(!err)
58-
assert.equal(after, true, 'should not call read sync')
58+
assert.strictEqual(after, true, 'should not call read sync')
5959
client.end()
6060
done()
6161
})
@@ -73,11 +73,11 @@ describe('proper cleanup', function() {
7373
const cursor1 = client.query(new Cursor(text))
7474
cursor1.read(8, function(err, rows) {
7575
assert.ifError(err)
76-
assert.equal(rows.length, 5)
76+
assert.strictEqual(rows.length, 5)
7777
const cursor2 = client.query(new Cursor(text))
7878
cursor2.read(8, function(err, rows) {
7979
assert.ifError(err)
80-
assert.equal(rows.length, 5)
80+
assert.strictEqual(rows.length, 5)
8181
client.end()
8282
done()
8383
})

0 commit comments

Comments
 (0)