From 6c82e1a77b5a3dc99b29f49546a248e37fe8afca Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 21 May 2016 00:23:19 -0400 Subject: [PATCH] lint: use standard style --- .eslintignore | 2 ++ .eslintrc | 3 +++ .travis.yml | 4 +++- index.js | 12 ++++++------ package.json | 5 +++++ test/.eslintrc | 5 +++++ test/test.js | 4 ++-- 7 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 test/.eslintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..62562b7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage +node_modules diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..e3578aa --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "standard" +} diff --git a/.travis.yml b/.travis.yml index c59b1cd..fbe8e12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,8 @@ cache: - node_modules before_install: # Setup Node.js version-specific dependencies - - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" + - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard istanbul" + # Update Node.js modules - "test ! -d node_modules || npm prune" - "test ! -d node_modules || npm rebuild" @@ -23,5 +24,6 @@ script: # Run test script, depending on istanbul install - "test ! -z $(npm -ps ls istanbul) || npm test" - "test -z $(npm -ps ls istanbul) || npm run-script test-travis" + - "test -z $(npm -ps ls eslint ) || npm run-script lint" after_script: - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" diff --git a/index.js b/index.js index 9ad930f..ef7ddd7 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ module.exports.sync = randomBytesSync * @public */ -function randomBytes(size, callback) { +function randomBytes (size, callback) { // validate callback is a function, if provided if (callback !== undefined && typeof callback !== 'function') { throw new TypeError('argument callback must be a function') @@ -53,8 +53,8 @@ function randomBytes(size, callback) { return generateRandomBytes(size, generateAttempts, callback) } - return new Promise(function executor(resolve, reject) { - generateRandomBytes(size, generateAttempts, function onRandomBytes(err, str) { + return new Promise(function executor (resolve, reject) { + generateRandomBytes(size, generateAttempts, function onRandomBytes (err, str) { if (err) return reject(err) resolve(str) }) @@ -69,7 +69,7 @@ function randomBytes(size, callback) { * @public */ -function randomBytesSync(size) { +function randomBytesSync (size) { var err = null for (var i = 0; i < generateAttempts; i++) { @@ -92,8 +92,8 @@ function randomBytesSync(size) { * @private */ -function generateRandomBytes(size, attempts, callback) { - crypto.randomBytes(size, function onRandomBytes(err, buf) { +function generateRandomBytes (size, attempts, callback) { + crypto.randomBytes(size, function onRandomBytes (err, buf) { if (!err) return callback(null, buf) if (!--attempts) return callback(err) setTimeout(generateRandomBytes.bind(null, size, attempts, callback), 10) diff --git a/package.json b/package.json index a02687c..2b7926a 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,10 @@ "repository": "crypto-utils/random-bytes", "devDependencies": { "bluebird": "3.4.0", + "eslint": "2.10.2", + "eslint-config-standard": "5.3.1", + "eslint-plugin-promise": "1.1.0", + "eslint-plugin-standard": "1.3.2", "istanbul": "0.4.3", "mocha": "2.4.5", "proxyquire": "1.2.0" @@ -23,6 +27,7 @@ "node": ">= 0.8" }, "scripts": { + "lint": "eslint **/*.js", "test": "mocha --trace-deprecation --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --trace-deprecation --reporter dot --check-leaks test/", "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --trace-deprecation --reporter spec --check-leaks test/" diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..7eeefc3 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,5 @@ +{ + "env": { + "mocha": true + } +} diff --git a/test/test.js b/test/test.js index 5975276..60deb56 100644 --- a/test/test.js +++ b/test/test.js @@ -169,7 +169,7 @@ describe('randomBytes.sync()', function () { }) }) -function cryptoRandomBytes(size, callback) { +function cryptoRandomBytes (size, callback) { if (cryptoRandomBytes.seeded === undefined) { return crypto.randomBytes(size, callback) } @@ -189,6 +189,6 @@ function cryptoRandomBytes(size, callback) { callback(err) } -function unexpectedResolve() { +function unexpectedResolve () { throw new Error('unexpected resolve') }