Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 3909066

Browse files
authored
Merge pull request #688 from UziTech/eslint
2 parents b829a1d + de9926a commit 3909066

17 files changed

+107
-73
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
coverage/
3+
.nyc_output/
4+
docs/

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
env: {
3+
commonjs: true,
4+
es2021: true,
5+
node: true
6+
},
7+
extends: [
8+
'standard'
9+
],
10+
rules: {
11+
'no-shadow': 'error',
12+
'no-unused-vars': ['error', {
13+
argsIgnorePattern: '^_',
14+
caughtErrorsIgnorePattern: '^_'
15+
}]
16+
}
17+
}

lib/client/client.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,25 @@ Client.prototype.modify = function modify (name, change, controls, callback) {
418418

419419
const changes = []
420420

421-
function changeFromObject (change) {
422-
if (!change.operation && !change.type) { throw new Error('change.operation required') }
423-
if (typeof (change.modification) !== 'object') { throw new Error('change.modification (object) required') }
421+
function changeFromObject (obj) {
422+
if (!obj.operation && !obj.type) { throw new Error('change.operation required') }
423+
if (typeof (obj.modification) !== 'object') { throw new Error('change.modification (object) required') }
424424

425-
if (Object.keys(change.modification).length === 2 &&
426-
typeof (change.modification.type) === 'string' &&
427-
Array.isArray(change.modification.vals)) {
425+
if (Object.keys(obj.modification).length === 2 &&
426+
typeof (obj.modification.type) === 'string' &&
427+
Array.isArray(obj.modification.vals)) {
428428
// Use modification directly if it's already normalized:
429429
changes.push(new Change({
430-
operation: change.operation || change.type,
431-
modification: change.modification
430+
operation: obj.operation || obj.type,
431+
modification: obj.modification
432432
}))
433433
} else {
434434
// Normalize the modification object
435-
Object.keys(change.modification).forEach(function (k) {
435+
Object.keys(obj.modification).forEach(function (k) {
436436
const mod = {}
437-
mod[k] = change.modification[k]
437+
mod[k] = obj.modification[k]
438438
changes.push(new Change({
439-
operation: change.operation || change.type,
439+
operation: obj.operation || obj.type,
440440
modification: mod
441441
}))
442442
})
@@ -679,9 +679,9 @@ Client.prototype.starttls = function starttls (options,
679679
return callback(new Error('STARTTLS already in progress or active'))
680680
}
681681

682-
function onSend (err, emitter) {
683-
if (err) {
684-
callback(err)
682+
function onSend (sendErr, emitter) {
683+
if (sendErr) {
684+
callback(sendErr)
685685
return
686686
}
687687
/*
@@ -697,7 +697,7 @@ Client.prototype.starttls = function starttls (options,
697697
self._starttls = null
698698
callback(err)
699699
})
700-
emitter.on('end', function (res) {
700+
emitter.on('end', function (_res) {
701701
const sock = self._socket
702702
/*
703703
* Unplumb socket data during SSL negotiation.
@@ -850,9 +850,9 @@ Client.prototype.connect = function connect () {
850850
}
851851

852852
// Initialize socket events and LDAP parser.
853-
function initSocket (url) {
853+
function initSocket (server) {
854854
tracker = messageTrackerFactory({
855-
id: url ? url.href : self.socketPath,
855+
id: server ? server.href : self.socketPath,
856856
parser: new Parser({ log: log })
857857
})
858858

@@ -938,7 +938,7 @@ Client.prototype.connect = function connect () {
938938
f(basicClient, callback)
939939
},
940940
inputs: self.listeners('setup')
941-
}, function (err, res) {
941+
}, function (err, _res) {
942942
if (err) {
943943
self.emit('setupError', err)
944944
}
@@ -1001,7 +1001,7 @@ Client.prototype.connect = function connect () {
10011001
}
10021002
retry.failAfter(failAfter)
10031003

1004-
retry.on('ready', function (num, delay) {
1004+
retry.on('ready', function (num, _delay) {
10051005
if (self.destroyed) {
10061006
// Cease connection attempts if destroyed
10071007
return

lib/client/message-tracker/id-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const { MAX_MSGID } = require('../constants')
1616
module.exports = function idGeneratorFactory (start = 0) {
1717
let currentID = start
1818
return function nextID () {
19-
const nextID = currentID + 1
20-
currentID = (nextID >= MAX_MSGID) ? 1 : nextID
19+
const id = currentID + 1
20+
currentID = (id >= MAX_MSGID) ? 1 : id
2121
return currentID
2222
}
2323
}

lib/client/search_pager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ SearchPager.prototype._nextPage = function _nextPage (cookie) {
150150
/**
151151
* Callback provided to the client API for successful transmission.
152152
*/
153-
SearchPager.prototype._sendCallback = function _sendCallback (err, res) {
153+
SearchPager.prototype._sendCallback = function _sendCallback (err) {
154154
if (err) {
155155
this.finished = true
156156
if (!this.started) {

lib/messages/abandon_response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Object.defineProperties(AbandonResponse.prototype, {
2323
}
2424
})
2525

26-
AbandonResponse.prototype.end = function (status) {}
26+
AbandonResponse.prototype.end = function (_status) {}
2727

2828
AbandonResponse.prototype._json = function (j) {
2929
return j

lib/messages/search_entry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Object.defineProperties(SearchEntry.prototype, {
5454
obj[a.type] = []
5555
}
5656
})
57-
this.controls.forEach(function (element, index, array) {
57+
this.controls.forEach(function (element) {
5858
obj.controls.push(element.json)
5959
})
6060
return obj
@@ -79,7 +79,7 @@ Object.defineProperties(SearchEntry.prototype, {
7979
obj[a.type] = []
8080
}
8181
})
82-
this.controls.forEach(function (element, index, array) {
82+
this.controls.forEach(function (element) {
8383
obj.controls.push(element.json)
8484
})
8585
return obj

lib/messages/unbind_response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Object.defineProperties(UnbindResponse.prototype, {
3131
/**
3232
* Special override that just ends the connection, if present.
3333
*
34-
* @param {Number} status completely ignored.
34+
* @param {Number} _status completely ignored.
3535
*/
36-
UnbindResponse.prototype.end = function (status) {
36+
UnbindResponse.prototype.end = function (_status) {
3737
assert.ok(this.connection)
3838

3939
this.log.trace('%s: unbinding!', this.connection.ldap.id)

lib/persistent_search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getOperationType (requestType) {
7777
}
7878
}
7979

80-
function getEntryChangeNotificationControl (req, obj, callback) {
80+
function getEntryChangeNotificationControl (req, obj) {
8181
// if we want to return a ECNC
8282
if (req.persistentSearch.value.returnECs) {
8383
const attrs = obj.attributes

lib/server.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,28 +313,28 @@ function Server (options) {
313313
return c
314314
}
315315

316-
function newConnection (c) {
317-
setupConnection(c)
318-
log.trace('new connection from %s', c.ldap.id)
316+
function newConnection (conn) {
317+
setupConnection(conn)
318+
log.trace('new connection from %s', conn.ldap.id)
319319

320320
dtrace.fire('server-connection', function () {
321-
return [c.remoteAddress]
321+
return [conn.remoteAddress]
322322
})
323323

324-
c.parser = new Parser({
324+
conn.parser = new Parser({
325325
log: options.log
326326
})
327-
c.parser.on('message', function (req) {
328-
req.connection = c
329-
req.logId = c.ldap.id + '::' + req.messageID
327+
conn.parser.on('message', function (req) {
328+
req.connection = conn
329+
req.logId = conn.ldap.id + '::' + req.messageID
330330
req.startTime = new Date().getTime()
331331

332-
log.debug('%s: message received: req=%j', c.ldap.id, req.json)
332+
log.debug('%s: message received: req=%j', conn.ldap.id, req.json)
333333

334334
const res = getResponse(req)
335335
if (!res) {
336336
log.warn('Unimplemented server method: %s', req.type)
337-
c.destroy()
337+
conn.destroy()
338338
return false
339339
}
340340

@@ -368,18 +368,18 @@ function Server (options) {
368368
}
369369
}
370370

371-
res.connection = c
371+
res.connection = conn
372372
res.logId = req.logId
373373
res.requestDN = req.dn
374374

375375
const chain = self._getHandlerChain(req, res)
376376

377377
let i = 0
378378
return (function messageIIFE (err) {
379-
function sendError (err) {
380-
res.status = err.code || errors.LDAP_OPERATIONS_ERROR
379+
function sendError (sendErr) {
380+
res.status = sendErr.code || errors.LDAP_OPERATIONS_ERROR
381381
res.matchedDN = req.suffix ? req.suffix.toString() : ''
382-
res.errorMessage = err.message || ''
382+
res.errorMessage = sendErr.message || ''
383383
return res.end()
384384
}
385385

@@ -388,8 +388,8 @@ function Server (options) {
388388

389389
function next () {} // stub out next for the post chain
390390

391-
self._postChain.forEach(function (c) {
392-
c.call(self, req, res, next)
391+
self._postChain.forEach(function (cb) {
392+
cb.call(self, req, res, next)
393393
})
394394
}
395395

@@ -404,7 +404,7 @@ function Server (options) {
404404
const next = messageIIFE
405405
if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) }
406406

407-
if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { c.ldap.bindDN = req.dn }
407+
if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { conn.ldap.bindDN = req.dn }
408408

409409
return after()
410410
} catch (e) {
@@ -415,23 +415,23 @@ function Server (options) {
415415
}())
416416
})
417417

418-
c.parser.on('error', function (err, message) {
419-
self.emit('error', new VError(err, 'Parser error for %s', c.ldap.id))
418+
conn.parser.on('error', function (err, message) {
419+
self.emit('error', new VError(err, 'Parser error for %s', conn.ldap.id))
420420

421-
if (!message) { return c.destroy() }
421+
if (!message) { return conn.destroy() }
422422

423423
const res = getResponse(message)
424-
if (!res) { return c.destroy() }
424+
if (!res) { return conn.destroy() }
425425

426426
res.status = 0x02 // protocol error
427427
res.errorMessage = err.toString()
428-
return c.end(res.toBer())
428+
return conn.end(res.toBer())
429429
})
430430

431-
c.on('data', function (data) {
432-
log.trace('data on %s: %s', c.ldap.id, util.inspect(data))
431+
conn.on('data', function (data) {
432+
log.trace('data on %s: %s', conn.ldap.id, util.inspect(data))
433433

434-
c.parser.write(data)
434+
conn.parser.write(data)
435435
})
436436
} // end newConnection
437437

0 commit comments

Comments
 (0)