Skip to content

Commit

Permalink
Add gulp eslint task for common coding styles
Browse files Browse the repository at this point in the history
Further fixes in response to comments:
- resolved all lint errors

Change-Id: I49c0635c238a3576408db4157ccb0673654113c3
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Oct 3, 2016
1 parent 869da76 commit c0ea692
Show file tree
Hide file tree
Showing 17 changed files with 2,316 additions and 2,287 deletions.
22 changes: 11 additions & 11 deletions build/tasks/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -18,14 +18,14 @@ var gulp = require('gulp');
var jsdoc = require('gulp-jsdoc3');

gulp.task('doc', function () {
gulp.src([
'README.md',
'index.js',
'./lib/api.js',
'./lib/FileKeyValueStore.js',
'./lib/Chain.js',
'./lib/Member.js'
], {read: false})
.pipe(jsdoc())
.pipe(gulp.dest('./docs/gen'));
gulp.src([
'README.md',
'index.js',
'./lib/api.js',
'./lib/FileKeyValueStore.js',
'./lib/Chain.js',
'./lib/Member.js'
], {read: false})
.pipe(jsdoc())
.pipe(gulp.dest('./docs/gen'));
});
28 changes: 28 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,31 @@ var requireDir = require('require-dir');

// Require all tasks in gulp/tasks, including subfolders
requireDir('./build/tasks', { recurse: true });

var gulp = require('gulp');
var eslint = require('gulp-eslint');

gulp.task('lint', function () {
return gulp.src(['**/*.js', '!node_modules/**', '!docs/**'])
.pipe(eslint(
{
env: ['es6', 'node'],
extends: 'eslint:recommended',
parserOptions: {
sourceType: 'module'
},
rules: {
indent: ['error', 'tab'],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always']
}
}
))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('default', ['lint'], function () {
// This will only run if the lint task is successful...
});
31 changes: 15 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ var _chains = {};
* @returns [Chain]{@link module:api.Chain} a new instance of the Chain class
*/
module.exports.newChain = function(name) {
var chain = _chains[name];

if (chain)
throw new Error(util.format("Chain %s already exists", name));
var chain = _chains[name];

chain = new Chain(name);
if (chain)
throw new Error(util.format('Chain %s already exists', name));

_chains[name] = chain;
return chain;
}
chain = new Chain(name);

_chains[name] = chain;
return chain;
};

/**
* Get a chain. If it doesn't yet exist and 'create' is true, create it.
Expand All @@ -52,14 +52,14 @@ module.exports.newChain = function(name) {
* @returns {Chain} Returns the chain, or null if it doesn't exist and create is false.
*/
module.exports.getChain = function(chainName, create) {
var chain = _chains[chainName];
var chain = _chains[chainName];

if (!chain && create) {
chain = newChain(chainName);
}
if (!chain && create) {
chain = newChain(chainName);
}

return chain;
}
return chain;
};

/**
* Obtains an instance of the [KeyValueStore]{@link module:api.KeyValueStore} class. By default
Expand All @@ -73,5 +73,4 @@ module.exports.getChain = function(chainName, create) {
*/
module.exports.newKeyValueStore = function(options) {
return utils.newKeyValueStore(options);
}

};
Loading

0 comments on commit c0ea692

Please sign in to comment.