Skip to content

Commit db8dd28

Browse files
author
Tony Crisci
committed
lint and format
1 parent 0332d17 commit db8dd28

13 files changed

Lines changed: 130 additions & 130 deletions

lib/address-x11.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
// read dbus adress from window selection
2-
try {
3-
var x11 = require('x11');
4-
} catch (err) {
5-
x11 = null;
6-
}
7-
81
const fs = require('fs');
92
const os = require('os');
103

114
function getDbusAddressFromWindowSelection (callback) {
5+
// read dbus adress from window selection
6+
// TODO: implement this somewhere
7+
const x11 = require('x11');
128
if (x11 === null) {
139
throw new Error('cannot get session bus address from window selection: dbus-next was installed without x11 support');
1410
}
1511

1612
// read machine uuid
1713
fs.readFile('/var/lib/dbus/machine-id', 'ascii', function (err, uuid) {
1814
if (err) return callback(err);
19-
var hostname = os.hostname().split('-')[0];
15+
const hostname = os.hostname().split('-')[0];
2016
x11.createClient(function (err, display) {
2117
if (err) return callback(err);
22-
var X = display.client;
23-
var selectionName = `_DBUS_SESSION_BUS_SELECTION_${
18+
const X = display.client;
19+
const selectionName = `_DBUS_SESSION_BUS_SELECTION_${
2420
hostname
2521
}_${uuid.trim()}`;
2622
X.InternAtom(false, selectionName, function (err, id) {

lib/align.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const Buffer = require('safe-buffer').Buffer;
22

33
function align (ps, n) {
4-
var pad = n - ps._offset % n;
4+
const pad = n - ps._offset % n;
55
if (pad === 0 || pad === n) return;
66
// TODO: write8(0) in a loop (3 to 7 times here) could be more efficient
7-
var padBuff = Buffer.alloc(pad);
7+
const padBuff = Buffer.alloc(pad);
88
ps.put(Buffer.from(padBuff));
99
ps._offset += pad;
1010
}

lib/bus.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class MessageBus extends EventEmitter {
418418

419419
const pathSplit = path.split('/').filter(n => n);
420420

421-
let children = new Set();
421+
const children = new Set();
422422

423423
for (const key of Object.keys(this._serviceObjects)) {
424424
const keySplit = key.split('/').filter(n => n);
@@ -430,12 +430,12 @@ class MessageBus extends EventEmitter {
430430
}
431431
}
432432

433-
for (let child of children) {
434-
xml.node.node.push({
435-
$: {
436-
name: child
437-
}
438-
});
433+
for (const child of children) {
434+
xml.node.node.push({
435+
$: {
436+
name: child
437+
}
438+
});
439439
}
440440

441441
return xmlHeader + this._builder.buildObject(xml);
@@ -461,7 +461,7 @@ class MessageBus extends EventEmitter {
461461
}
462462

463463
_addMatch (match) {
464-
if (this._matchRules.hasOwnProperty(match)) {
464+
if (Object.prototype.hasOwnProperty.call(match, this._matchRules)) {
465465
this._matchRules[match] += 1;
466466
return Promise.resolve();
467467
}
@@ -485,7 +485,7 @@ class MessageBus extends EventEmitter {
485485
return Promise.resolve();
486486
}
487487

488-
if (this._matchRules.hasOwnProperty(match)) {
488+
if (Object.prototype.hasOwnProperty.call(match, this._matchRules)) {
489489
this._matchRules[match] -= 1;
490490
if (this._matchRules[match] > 0) {
491491
return Promise.resolve();

lib/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function createStream (opts) {
2424
const familyParams = address.split(':');
2525
const family = familyParams[0];
2626
const params = {};
27-
familyParams[1].split(',').map(function (p) {
27+
familyParams[1].split(',').forEach(function (p) {
2828
const keyVal = p.split('=');
2929
params[keyVal[0]] = keyVal[1];
3030
});

lib/dbus-buffer.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function DBusBuffer (buffer, startPos, endian, options) {
2222
}
2323

2424
DBusBuffer.prototype.align = function (power) {
25-
var allbits = (1 << power) - 1;
26-
var paddedOffset = ((this.pos + this.startPos + allbits) >> power) << power;
25+
const allbits = (1 << power) - 1;
26+
const paddedOffset = ((this.pos + this.startPos + allbits) >> power) << power;
2727
this.pos = paddedOffset - this.startPos;
2828
};
2929

@@ -35,7 +35,7 @@ DBusBuffer.prototype.readInt8 = function () {
3535
DBusBuffer.prototype.readSInt16 = function () {
3636
this.align(1);
3737

38-
var res = (this.endian === LE
38+
const res = (this.endian === LE
3939
? this.buffer.readInt16LE(this.pos)
4040
: this.buffer.readInt16BE(this.pos));
4141

@@ -46,7 +46,7 @@ DBusBuffer.prototype.readSInt16 = function () {
4646
DBusBuffer.prototype.readInt16 = function () {
4747
this.align(1);
4848

49-
var res = (this.endian === LE
49+
const res = (this.endian === LE
5050
? this.buffer.readUInt16LE(this.pos)
5151
: this.buffer.readUInt16BE(this.pos));
5252

@@ -57,7 +57,7 @@ DBusBuffer.prototype.readInt16 = function () {
5757
DBusBuffer.prototype.readSInt32 = function () {
5858
this.align(2);
5959

60-
var res = (this.endian === LE
60+
const res = (this.endian === LE
6161
? this.buffer.readInt32LE(this.pos)
6262
: this.buffer.readInt32BE(this.pos));
6363

@@ -68,7 +68,7 @@ DBusBuffer.prototype.readSInt32 = function () {
6868
DBusBuffer.prototype.readInt32 = function () {
6969
this.align(2);
7070

71-
var res = (this.endian === LE
71+
const res = (this.endian === LE
7272
? this.buffer.readUInt32LE(this.pos)
7373
: this.buffer.readUInt32BE(this.pos));
7474

@@ -79,7 +79,7 @@ DBusBuffer.prototype.readInt32 = function () {
7979
DBusBuffer.prototype.readDouble = function () {
8080
this.align(3);
8181

82-
var res = (this.endian === LE
82+
const res = (this.endian === LE
8383
? this.buffer.readDoubleLE(this.pos)
8484
: this.buffer.readDoubleBE(this.pos));
8585

@@ -92,7 +92,7 @@ DBusBuffer.prototype.readString = function (len) {
9292
this.pos++;
9393
return '';
9494
}
95-
var res = this.buffer.toString('utf8', this.pos, this.pos + len);
95+
const res = this.buffer.toString('utf8', this.pos, this.pos + len);
9696
this.pos += len + 1; // dbus strings are always zero-terminated ('s' and 'g' types)
9797
return res;
9898
};
@@ -105,9 +105,10 @@ DBusBuffer.prototype.readTree = function readTree (tree) {
105105
this.align(3);
106106
return this.readStruct(tree.child);
107107
case 'a':
108-
if (!tree.child || tree.child.length !== 1) { throw new Error('Incorrect array element signature'); }
109-
var arrayBlobLength = this.readInt32();
110-
return this.readArray(tree.child[0], arrayBlobLength);
108+
if (!tree.child || tree.child.length !== 1) {
109+
throw new Error('Incorrect array element signature');
110+
}
111+
return this.readArray(tree.child[0], this.readInt32());
111112
case 'v':
112113
return this.readVariant();
113114
default:
@@ -116,27 +117,27 @@ DBusBuffer.prototype.readTree = function readTree (tree) {
116117
};
117118

118119
DBusBuffer.prototype.read = function read (signature) {
119-
var tree = parseSignature(signature);
120+
const tree = parseSignature(signature);
120121
return this.readStruct(tree);
121122
};
122123

123124
DBusBuffer.prototype.readVariant = function readVariant () {
124-
var signature = this.readSimpleType('g');
125-
var tree = parseSignature(signature);
125+
const signature = this.readSimpleType('g');
126+
const tree = parseSignature(signature);
126127
return [tree, this.readStruct(tree)];
127128
};
128129

129130
DBusBuffer.prototype.readStruct = function readStruct (struct) {
130-
var result = [];
131-
for (var i = 0; i < struct.length; ++i) {
131+
const result = [];
132+
for (let i = 0; i < struct.length; ++i) {
132133
result.push(this.readTree(struct[i]));
133134
}
134135
return result;
135136
};
136137

137138
DBusBuffer.prototype.readArray = function readArray (eleType, arrayBlobSize) {
138-
var result;
139-
var start = this.pos;
139+
const result = [];
140+
const start = this.pos;
140141

141142
// special case: treat ay as Buffer
142143
if (eleType.type === 'y' && this.options.ayBuffer) {
@@ -147,15 +148,18 @@ DBusBuffer.prototype.readArray = function readArray (eleType, arrayBlobSize) {
147148
// end of array is start of first element + array size
148149
// we need to add 4 bytes if not on 8-byte boundary
149150
// and array element needs 8 byte alignment
150-
if (['x', 't', 'd', '{', '(', 'r'].indexOf(eleType.type) !== -1) { this.align(3); }
151-
var end = this.pos + arrayBlobSize;
152-
result = [];
153-
while (this.pos < end) result.push(this.readTree(eleType));
151+
if (['x', 't', 'd', '{', '(', 'r'].indexOf(eleType.type) !== -1) {
152+
this.align(3);
153+
}
154+
const end = this.pos + arrayBlobSize;
155+
while (this.pos < end) {
156+
result.push(this.readTree(eleType));
157+
}
154158
return result;
155159
};
156160

157161
DBusBuffer.prototype.readSimpleType = function readSimpleType (t) {
158-
var len, word0, word1;
162+
let len, word0, word1;
159163
switch (t) {
160164
case 'y':
161165
return this.readInt8();

lib/handshake.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const constants = require('./constants');
77
const readLine = require('./readline');
88

99
function sha1 (input) {
10-
var shasum = crypto.createHash('sha1');
10+
const shasum = crypto.createHash('sha1');
1111
shasum.update(input);
1212
return shasum.digest('hex');
1313
}
@@ -18,11 +18,11 @@ function getUserHome () {
1818

1919
function getCookie (context, id, cb) {
2020
// http://dbus.freedesktop.org/doc/dbus-specification.html#auth-mechanisms-sha
21-
var dirname = path.join(getUserHome(), '.dbus-keyrings');
21+
const dirname = path.join(getUserHome(), '.dbus-keyrings');
2222
// > There is a default context, "org_freedesktop_general" that's used by servers that do not specify otherwise.
2323
if (context.length === 0) context = 'org_freedesktop_general';
2424

25-
var filename = path.join(dirname, context);
25+
const filename = path.join(dirname, context);
2626
// check it's not writable by others and readable by user
2727
fs.stat(dirname, function (err, stat) {
2828
if (err) return cb(err);
@@ -42,9 +42,9 @@ function getCookie (context, id, cb) {
4242
}
4343
fs.readFile(filename, 'ascii', function (err, keyrings) {
4444
if (err) return cb(err);
45-
var lines = keyrings.split('\n');
46-
for (var l = 0; l < lines.length; ++l) {
47-
var data = lines[l].split(' ');
45+
const lines = keyrings.split('\n');
46+
for (let l = 0; l < lines.length; ++l) {
47+
const data = lines[l].split(' ');
4848
if (id === data[0]) return cb(null, data[2]);
4949
}
5050
return cb(new Error('cookie not found'));
@@ -58,7 +58,7 @@ function hexlify (input) {
5858

5959
module.exports = function auth (stream, opts, cb) {
6060
// filter used to make a copy so we don't accidently change opts data
61-
var authMethods;
61+
let authMethods;
6262
if (opts.authMethods) {
6363
authMethods = opts.authMethods;
6464
} else {
@@ -73,13 +73,13 @@ function tryAuth (stream, methods, cb) {
7373
return cb(new Error('No authentication methods left to try'));
7474
}
7575

76-
var authMethod = methods.shift();
77-
var uid = 'getuid' in process ? process.getuid() : 0;
78-
var id = hexlify(uid);
76+
const authMethod = methods.shift();
77+
const uid = 'getuid' in process ? process.getuid() : 0;
78+
const id = hexlify(uid);
7979

8080
function beginOrNextAuth () {
8181
readLine(stream, function (line) {
82-
var ok = line.toString('ascii').match(/^([A-Za-z]+) (.*)/);
82+
const ok = line.toString('ascii').match(/^([A-Za-z]+) (.*)/);
8383
if (ok && ok[1] === 'OK') {
8484
stream.write('BEGIN\r\n');
8585
return cb(null, ok[2]); // ok[2] = guid. Do we need it?
@@ -102,7 +102,7 @@ function tryAuth (stream, methods, cb) {
102102
case 'DBUS_COOKIE_SHA1':
103103
stream.write(`AUTH ${authMethod} ${id}\r\n`);
104104
readLine(stream, function (line) {
105-
var data = Buffer.from(
105+
const data = Buffer.from(
106106
line
107107
.toString()
108108
.split(' ')[1]
@@ -111,17 +111,17 @@ function tryAuth (stream, methods, cb) {
111111
)
112112
.toString()
113113
.split(' ');
114-
var cookieContext = data[0];
115-
var cookieId = data[1];
116-
var serverChallenge = data[2];
114+
const cookieContext = data[0];
115+
const cookieId = data[1];
116+
const serverChallenge = data[2];
117117
// any random 16 bytes should work, sha1(rnd) to make it simplier
118-
var clientChallenge = crypto.randomBytes(16).toString('hex');
118+
const clientChallenge = crypto.randomBytes(16).toString('hex');
119119
getCookie(cookieContext, cookieId, function (err, cookie) {
120120
if (err) return cb(err);
121-
var response = sha1(
121+
const response = sha1(
122122
[serverChallenge, clientChallenge, cookie].join(':')
123123
);
124-
var reply = hexlify(clientChallenge + response);
124+
const reply = hexlify(clientChallenge + response);
125125
stream.write(`DATA ${reply}\r\n`);
126126
beginOrNextAuth();
127127
});

0 commit comments

Comments
 (0)