Skip to content

Commit

Permalink
lint: use standard style
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 21, 2016
1 parent d27e238 commit 6c82e1a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
coverage
node_modules
3 changes: 3 additions & 0 deletions .eslintrc
@@ -0,0 +1,3 @@
{
"extends": "standard"
}
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -15,13 +15,15 @@ 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"
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"
12 changes: 6 additions & 6 deletions index.js
Expand Up @@ -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')
Expand All @@ -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)
})
Expand All @@ -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++) {
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -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"
Expand All @@ -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/"
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
4 changes: 2 additions & 2 deletions test/test.js
Expand Up @@ -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)
}
Expand All @@ -189,6 +189,6 @@ function cryptoRandomBytes(size, callback) {
callback(err)
}

function unexpectedResolve() {
function unexpectedResolve () {
throw new Error('unexpected resolve')
}

0 comments on commit 6c82e1a

Please sign in to comment.