Skip to content

Commit 6fd84bf

Browse files
committed
[lint] fix parens/curlies/semis/etc
1 parent 9a76e2f commit 6fd84bf

File tree

12 files changed

+355
-325
lines changed

12 files changed

+355
-325
lines changed

.eslintrc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@
1818

1919
"rules": {
2020
"consistent-return": "warn",
21-
"curly": "warn",
22-
"dot-notation": [2, { "allowKeywords": true, "allowPattern": "throws" }],
2321
"func-style": "warn",
2422
"id-denylist": "warn",
2523
"max-params": "warn",
26-
"max-statements-per-line": "warn",
2724
"multiline-comment-style": "off",
28-
"no-else-return": "warn",
29-
"no-extra-parens": "warn",
3025
"no-param-reassign": "warn",
3126
"no-use-before-define": "warn",
32-
"semi": ["error", "never"],
3327
"sort-keys": "warn",
34-
"strict": "warn",
3528
},
3629

3730
"ignorePatterns": [
@@ -43,18 +36,13 @@
4336
"files": "bench/*",
4437
"extends": "@ljharb/eslint-config/node/4",
4538
"rules": {
46-
"curly": "warn",
4739
"func-style": "warn",
4840
"max-params": "warn",
49-
"no-extra-parens": "warn",
50-
"no-mixed-operators": "warn",
5141
"no-param-reassign": "warn",
5242
"no-use-before-define": "warn",
5343
"no-var": "off",
5444
"prefer-arrow-callback": "off",
5545
"prefer-template": "off",
56-
"semi": ["error", "never"],
57-
"strict": "warn",
5846
},
5947
},
6048
],

bench/index.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
var Benchmark = require('benchmark')
2-
var current = require('../lib/sync')
3-
var old = require('./old')
1+
'use strict';
42

5-
run('hello', 'world', 100, 32, 'md5')
6-
run('hello', 'world', 100, 32, 'sha256')
7-
run('hello', 'world', 10000, 70, 'md5')
8-
run('hello', 'world', 10000, 70, 'sha256')
3+
var Benchmark = require('benchmark');
4+
var current = require('../lib/sync');
5+
var old = require('./old');
6+
7+
run('hello', 'world', 100, 32, 'md5');
8+
run('hello', 'world', 100, 32, 'sha256');
9+
run('hello', 'world', 10000, 70, 'md5');
10+
run('hello', 'world', 10000, 70, 'sha256');
911
function run(password, salt, iterations, keylen, digest) {
10-
var suite = new Benchmark.Suite()
11-
console.log(`password: ${password}`)
12-
console.log(`salt: ${salt}`)
13-
console.log(`iterations: ${iterations}`)
14-
console.log(`keylen: ${keylen}`)
15-
console.log(`digest: ${digest}`)
12+
var suite = new Benchmark.Suite();
13+
console.log(`password: ${password}`);
14+
console.log(`salt: ${salt}`);
15+
console.log(`iterations: ${iterations}`);
16+
console.log(`keylen: ${keylen}`);
17+
console.log(`digest: ${digest}`);
1618

1719
// add tests
1820
suite
1921
.add('current', function () {
20-
current(password, salt, iterations, keylen, digest)
22+
current(password, salt, iterations, keylen, digest);
2123
})
2224
.add('old', function () {
23-
old(password, salt, iterations, keylen, digest)
25+
old(password, salt, iterations, keylen, digest);
2426
})
2527

2628
// add listeners
2729
.on('cycle', function (event) {
28-
console.log(String(event.target))
30+
console.log(String(event.target));
2931
})
3032
.on('complete', function () {
31-
console.log('Fastest is ' + this.filter('fastest').map('name'))
32-
console.log('')
33+
// eslint-disable-next-line no-invalid-this
34+
console.log('Fastest is ' + this.filter('fastest').map('name'));
35+
console.log('');
3336
})
34-
.run()
37+
.run();
3538
}

bench/old.js

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
1-
var createHmac = require('create-hmac')
2-
var checkParameters = require('../lib/precondition')
3-
var defaultEncoding = require('../lib/default-encoding')
4-
var Buffer = require('safe-buffer').Buffer
5-
module.exports = pbkdf2
1+
'use strict';
2+
3+
var createHmac = require('create-hmac');
4+
var checkParameters = require('../lib/precondition');
5+
var defaultEncoding = require('../lib/default-encoding');
6+
var Buffer = require('safe-buffer').Buffer;
7+
module.exports = pbkdf2;
68
function pbkdf2(password, salt, iterations, keylen, digest) {
7-
if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
8-
if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
9+
if (!Buffer.isBuffer(password)) {
10+
password = Buffer.from(password, defaultEncoding);
11+
}
12+
if (!Buffer.isBuffer(salt)) {
13+
salt = Buffer.from(salt, defaultEncoding);
14+
}
915

10-
checkParameters(iterations, keylen)
16+
checkParameters(iterations, keylen);
1117

12-
digest = digest || 'sha1'
18+
digest = digest || 'sha1';
1319

14-
var hLen
15-
var l = 1
16-
var DK = Buffer.allocUnsafe(keylen)
17-
var block1 = Buffer.allocUnsafe(salt.length + 4)
18-
salt.copy(block1, 0, 0, salt.length)
20+
var hLen;
21+
var l = 1;
22+
var DK = Buffer.allocUnsafe(keylen);
23+
var block1 = Buffer.allocUnsafe(salt.length + 4);
24+
salt.copy(block1, 0, 0, salt.length);
1925

20-
var r
21-
var T
26+
var r;
27+
var T;
2228

2329
for (var i = 1; i <= l; i++) {
24-
block1.writeUInt32BE(i, salt.length)
25-
var U = createHmac(digest, password).update(block1).digest()
30+
block1.writeUInt32BE(i, salt.length);
31+
var U = createHmac(digest, password).update(block1).digest();
2632

2733
if (!hLen) {
28-
hLen = U.length
29-
T = Buffer.allocUnsafe(hLen)
30-
l = Math.ceil(keylen / hLen)
31-
r = keylen - (l - 1) * hLen
34+
hLen = U.length;
35+
T = Buffer.allocUnsafe(hLen);
36+
l = Math.ceil(keylen / hLen);
37+
r = keylen - ((l - 1) * hLen);
3238
}
3339

34-
U.copy(T, 0, 0, hLen)
40+
U.copy(T, 0, 0, hLen);
3541

3642
for (var j = 1; j < iterations; j++) {
37-
U = createHmac(digest, password).update(U).digest()
38-
for (var k = 0; k < hLen; k++) T[k] ^= U[k]
43+
U = createHmac(digest, password).update(U).digest();
44+
for (var k = 0; k < hLen; k++) {
45+
T[k] ^= U[k];
46+
}
3947
}
4048

41-
var destPos = (i - 1) * hLen
42-
var len = (i === l ? r : hLen)
43-
T.copy(DK, destPos, 0, len)
49+
var destPos = (i - 1) * hLen;
50+
var len = i === l ? r : hLen;
51+
T.copy(DK, destPos, 0, len);
4452
}
4553

46-
return DK
54+
return DK;
4755
}

browser.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
exports.pbkdf2 = require('./lib/async')
2-
exports.pbkdf2Sync = require('./lib/sync')
1+
'use strict';
2+
3+
exports.pbkdf2 = require('./lib/async');
4+
exports.pbkdf2Sync = require('./lib/sync');

index.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
1-
var native = require('crypto')
1+
'use strict';
22

3-
var checkParameters = require('./lib/precondition')
4-
var defaultEncoding = require('./lib/default-encoding')
5-
var toBuffer = require('./lib/to-buffer')
3+
var native = require('crypto');
4+
5+
var checkParameters = require('./lib/precondition');
6+
var defaultEncoding = require('./lib/default-encoding');
7+
var toBuffer = require('./lib/to-buffer');
68

79
function nativePBKDF2(password, salt, iterations, keylen, digest, callback) {
8-
checkParameters(iterations, keylen)
9-
password = toBuffer(password, defaultEncoding, 'Password')
10-
salt = toBuffer(salt, defaultEncoding, 'Salt')
10+
checkParameters(iterations, keylen);
11+
password = toBuffer(password, defaultEncoding, 'Password');
12+
salt = toBuffer(salt, defaultEncoding, 'Salt');
1113

1214
if (typeof digest === 'function') {
13-
callback = digest
14-
digest = 'sha1'
15+
callback = digest;
16+
digest = 'sha1';
17+
}
18+
if (typeof callback !== 'function') {
19+
throw new Error('No callback provided to pbkdf2');
1520
}
16-
if (typeof callback !== 'function') { throw new Error('No callback provided to pbkdf2') }
1721

18-
return native.pbkdf2(password, salt, iterations, keylen, digest, callback)
22+
return native.pbkdf2(password, salt, iterations, keylen, digest, callback);
1923
}
2024

2125
function nativePBKDF2Sync(password, salt, iterations, keylen, digest) {
22-
checkParameters(iterations, keylen)
23-
password = toBuffer(password, defaultEncoding, 'Password')
24-
salt = toBuffer(salt, defaultEncoding, 'Salt')
25-
digest = digest || 'sha1'
26-
return native.pbkdf2Sync(password, salt, iterations, keylen, digest)
26+
checkParameters(iterations, keylen);
27+
password = toBuffer(password, defaultEncoding, 'Password');
28+
salt = toBuffer(salt, defaultEncoding, 'Salt');
29+
digest = digest || 'sha1';
30+
return native.pbkdf2Sync(password, salt, iterations, keylen, digest);
2731
}
2832

2933
/* istanbul ignore next */
3034
if (!native.pbkdf2Sync || native.pbkdf2Sync.toString().indexOf('keylen, digest') === -1) {
3135
/* eslint global-require: 0 */
32-
exports.pbkdf2Sync = require('./lib/sync')
33-
exports.pbkdf2 = require('./lib/async')
36+
exports.pbkdf2Sync = require('./lib/sync');
37+
exports.pbkdf2 = require('./lib/async');
3438

3539
// native
3640
} else {
37-
exports.pbkdf2Sync = nativePBKDF2Sync
38-
exports.pbkdf2 = nativePBKDF2
41+
exports.pbkdf2Sync = nativePBKDF2Sync;
42+
exports.pbkdf2 = nativePBKDF2;
3943
}

0 commit comments

Comments
 (0)