Skip to content

Commit

Permalink
[FABN-599] Fixed eslint issues with autofix
Browse files Browse the repository at this point in the history
- Issues resolved that could be autofixed
- Added root test folder to .eslintignore
- Updated test script in package.json to ignore chaincode tests
- Add package focused linting

Change-Id: I6a3841c4d8a5a607ea1ebeba46991df4f978a516
Signed-off-by: Liam Grace <liamgrace.896@gmail.com>
  • Loading branch information
liam-grace committed Oct 5, 2018
1 parent 7bb022e commit d7b354e
Show file tree
Hide file tree
Showing 77 changed files with 2,189 additions and 2,138 deletions.
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright 2018 IBM All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
coverage
node_modules
config
.nyc_output
6 changes: 3 additions & 3 deletions build/tasks/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
'use strict';

var gulp = require('gulp');
var debug = require('gulp-debug');
const gulp = require('gulp');
const debug = require('gulp-debug');

const DEPS = [
'fabric-client/lib/api.js',
Expand All @@ -31,7 +31,7 @@ const DEPS = [
'fabric-client/types/base.d.ts'
];

gulp.task('ca', function() {
gulp.task('ca', () => {
return gulp.src(DEPS, { base: 'fabric-client/' })
.pipe(debug())
.pipe(gulp.dest('fabric-ca-client/'))
Expand Down
30 changes: 15 additions & 15 deletions build/tasks/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
limitations under the License.
*/

var gulp = require('gulp');
var jsdoc = require('gulp-jsdoc3');
var del = require('del');
const gulp = require('gulp');
const jsdoc = require('gulp-jsdoc3');
const del = require('del');

gulp.task('clean', function(){
gulp.task('clean', () => {
return del('./docs/gen/**', {force:true});
});

gulp.task('doc', ['clean'], function () {
gulp.task('doc', ['clean'], () => {
gulp.src([
'docs/index.md',
'fabric-network/index.js',
Expand All @@ -37,14 +37,14 @@ gulp.task('doc', ['clean'], function () {
'fabric-ca-client/lib/AffiliationService.js',
'fabric-ca-client/lib/IdentityService.js',
], { read: false })
.pipe(jsdoc({
opts: {
tutorials: './docs/tutorials',
destination: './docs/gen'
},
templates: {
systemName: 'Hyperledger Fabric SDK for node.js',
theme: 'cosmo' //cerulean, cosmo, cyborg, flatly, journal, lumen, paper, readable, sandstone, simplex, slate, spacelab, superhero, united, yeti
}
}));
.pipe(jsdoc({
opts: {
tutorials: './docs/tutorials',
destination: './docs/gen'
},
templates: {
systemName: 'Hyperledger Fabric SDK for node.js',
theme: 'cosmo' //cerulean, cosmo, cyborg, flatly, journal, lumen, paper, readable, sandstone, simplex, slate, spacelab, superhero, united, yeti
}
}));
});
14 changes: 7 additions & 7 deletions build/tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ let gulp = require('gulp'),
fs = require('fs'),
ca = require('./ca.js');

gulp.task('watch', function () {
gulp.task('watch', () => {
watch(ca.DEPS, { ignoreInitial: false, base: 'fabric-client/' })
.pipe(debug())
.pipe(gulp.dest('fabric-ca-client/'));
.pipe(debug())
.pipe(gulp.dest('fabric-ca-client/'));

// only do the following if node_modules/fabric-client and
// node_modules/fabric-ca-client are NOT created as sym links
let statsA = fs.lstatSync('node_modules/fabric-client');
let statsB = fs.lstatSync('node_modules/fabric-ca-client');
const statsA = fs.lstatSync('node_modules/fabric-client');
const statsB = fs.lstatSync('node_modules/fabric-ca-client');
if (!statsA.isSymbolicLink() && !statsB.isSymbolicLink()) {
watch([
'fabric-client/index.js',
Expand All @@ -27,7 +27,7 @@ gulp.task('watch', function () {
'fabric-ca-client/config/**/*',
'fabric-ca-client/lib/**/*'
], { ignoreInitial: false, base: './' })
.pipe(debug())
.pipe(gulp.dest('node_modules'));
.pipe(debug())
.pipe(gulp.dest('node_modules'));
}
});
9 changes: 9 additions & 0 deletions fabric-ca-client/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright 2018 IBM All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
coverage
node_modules
config
.nyc_output
3 changes: 2 additions & 1 deletion fabric-ca-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"version": "1.3.0-snapshot",
"main": "index.js",
"scripts": {
"test": "nyc mocha --recursive -t 10000"
"lint": "eslint .",
"test": "nyc mocha --exclude 'test/data/**/*.js' --recursive -t 10000"
},
"repository": {
"type": "github (read mirror)",
Expand Down
10 changes: 10 additions & 0 deletions fabric-client/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright 2018 IBM All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
coverage
node_modules
config
.nyc_output

2 changes: 1 addition & 1 deletion fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,7 @@ const Channel = class {
if (!request.proposal) {
throw Error('Missing "proposal" parameter in transaction request');
}
let proposalResponses = request.proposalResponses;
const proposalResponses = request.proposalResponses;
const chaincodeProposal = request.proposal;

const endorsements = [];
Expand Down
2 changes: 1 addition & 1 deletion fabric-client/lib/impl/BasicCommitHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BasicCommitHandler extends api.CommitHandler {
if(orderers && orderers.length > 0) {
logger.debug('%s - found %s orderers assigned to channel', method, orderers.length);
// loop through the orderers trying to complete one successfully
for(let orderer of orderers) {
for(const orderer of orderers) {
logger.debug('%s - starting orderer %s', method, orderer.getName());
try {
const results = await orderer.sendBroadcast(envelope, timeout);
Expand Down
52 changes: 26 additions & 26 deletions fabric-client/lib/impl/CouchDBKeyValueStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

'use strict';

var api = require('../api.js');
var util = require('util');
var utils = require('../utils');
var nano = require('nano');
const api = require('../api.js');
const util = require('util');
const utils = require('../utils');
const nano = require('nano');

var logger = utils.getLogger('CouchDBKeyValueStore.js');
const logger = utils.getLogger('CouchDBKeyValueStore.js');

/**
* This is a sample database implementation of the [KeyValueStore]{@link module:api.KeyValueStore} API.
Expand All @@ -21,7 +21,7 @@ var logger = utils.getLogger('CouchDBKeyValueStore.js');
* @class
* @extends module:api.KeyValueStore
*/
var CouchDBKeyValueStore = class extends api.KeyValueStore {
const CouchDBKeyValueStore = class extends api.KeyValueStore {
/**
* @typedef {Object} CouchDBOpts
* @property {string} url The CouchDB instance url, in the form of http(s)://<user>:<password>@host:port
Expand All @@ -43,7 +43,7 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
// Create the keyValStore instance
super();

var self = this;
const self = this;
// url is the database instance url
this._url = options.url;
// Name of the database, optional
Expand All @@ -53,18 +53,18 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
this._name = options.name;
}

return new Promise(function (resolve, reject) {
return new Promise(((resolve, reject) => {
// Initialize the CouchDB database client
var dbClient = nano(self._url);
const dbClient = nano(self._url);
// Check if the database already exists. If not, create it.
dbClient.db.get(self._name, function (err) {
dbClient.db.get(self._name, (err) => {
// Check for error
if (err) {
// Database doesn't exist
if (err.error == 'not_found') {
logger.debug('No %s found, creating %s', self._name, self._name);

dbClient.db.create(self._name, function (err) {
dbClient.db.create(self._name, (err) => {
if (err) {
return reject(new Error(util.format('Failed to create %s database due to error: %s', self._name, err.stack ? err.stack : err)));
}
Expand All @@ -86,15 +86,15 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
resolve(self);
}
});
});
}));
}

getValue(name) {
logger.debug('getValue', { key: name });

var self = this;
return new Promise(function (resolve, reject) {
self._database.get(name, function (err, body) {
const self = this;
return new Promise(((resolve, reject) => {
self._database.get(name, (err, body) => {
// Check for error on retrieving from database
if (err) {
if (err.error !== 'not_found') {
Expand All @@ -109,17 +109,17 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
return resolve(body.member);
}
});
});
}));
}

setValue(name, value) {
logger.debug('setValue', { key: name });

var self = this;
const self = this;

return new Promise(function (resolve, reject) {
return new Promise(((resolve, reject) => {
// Attempt to retrieve from the database to see if the entry exists
self._database.get(name, function (err, body) {
self._database.get(name, (err, body) => {
// Check for error on retrieving from database
if (err) {
if (err.error !== 'not_found') {
Expand All @@ -129,7 +129,7 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
// Entry does not exist
logger.debug('setValue: %s, Entry does not exist, insert it.', name);
self._dbInsert({ _id: name, member: value })
.then(function (status) {
.then((status) => {
logger.debug('setValue add: ' + name + ', status: ' + status);
if (status == true) resolve(value);
else reject(new Error('Couch database insert add failed.'));
Expand All @@ -141,21 +141,21 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
logger.debug('setValue: %s, Retrieved entry from %s. Latest rev number: %s', name, self._name, body._rev);

self._dbInsert({ _id: name, _rev: body._rev, member: value })
.then(function (status) {
.then((status) => {
logger.debug('setValue update: ' + name + ', status: ' + status);
if (status == true) resolve(value);
else reject(new Error('Couch database insert update failed.'));
});
}
});
});
}));
}

_dbInsert(options) {
logger.debug('setValue, _dbInsert', { options: options });
var self = this;
return new Promise(function (resolve, reject) {
self._database.insert(options, function (err) {
const self = this;
return new Promise(((resolve, reject) => {
self._database.insert(options, (err) => {
if (err) {
logger.error('setValue, _dbInsert, ERROR: [%s.insert] - ', self._name, err.error);
reject(new Error(err.error));
Expand All @@ -164,7 +164,7 @@ var CouchDBKeyValueStore = class extends api.KeyValueStore {
resolve(true);
}
});
});
}));
}
};

Expand Down
26 changes: 13 additions & 13 deletions fabric-client/lib/impl/CryptoKeyStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

'use strict';

var jsrsasign = require('jsrsasign');
var KEYUTIL = jsrsasign.KEYUTIL;
const jsrsasign = require('jsrsasign');
const KEYUTIL = jsrsasign.KEYUTIL;

var utils = require('../utils.js');
var ECDSAKey = require('./ecdsa/key.js');
const utils = require('../utils.js');
const ECDSAKey = require('./ecdsa/key.js');

/*
* The mixin enforces the special indexing mechanism with private and public
* keys on top of a standard implementation of the KeyValueStore interface
* with the getKey() and putKey() methods
*/
var CryptoKeyStoreMixin = (KeyValueStore) => class extends KeyValueStore {
const CryptoKeyStoreMixin = (KeyValueStore) => class extends KeyValueStore {
getKey(ski) {
var self = this;
const self = this;

// first try the private key entry, since it encapsulates both
// the private key and public key
return this.getValue(_getKeyIndex(ski, true))
.then((raw) => {
if (raw !== null) {
var privKey = KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(raw);
const privKey = KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(raw);
// TODO: for now assuming ECDSA keys only, need to add support for RSA keys
return new ECDSAKey(privKey);
}
Expand All @@ -40,15 +40,15 @@ var CryptoKeyStoreMixin = (KeyValueStore) => class extends KeyValueStore {
return key;

if (key !== null) {
var pubKey = KEYUTIL.getKey(key);
const pubKey = KEYUTIL.getKey(key);
return new ECDSAKey(pubKey);
}
});
}

putKey(key) {
var idx = _getKeyIndex(key.getSKI(), key.isPrivate());
var pem = key.toBytes();
const idx = _getKeyIndex(key.getSKI(), key.isPrivate());
const pem = key.toBytes();
return this.setValue(idx, pem)
.then(() => {
return key;
Expand All @@ -68,8 +68,8 @@ var CryptoKeyStoreMixin = (KeyValueStore) => class extends KeyValueStore {
*
* @class
*/
var CryptoKeyStore = function(KVSImplClass, opts) {
var superClass;
const CryptoKeyStore = function(KVSImplClass, opts) {
let superClass;

if (typeof KVSImplClass !== 'function') {
let impl_class = utils.getConfigSetting('crypto-value-store');
Expand All @@ -84,7 +84,7 @@ var CryptoKeyStore = function(KVSImplClass, opts) {
opts = KVSImplClass;
}

var MyClass = class extends CryptoKeyStoreMixin(superClass) {};
const MyClass = class extends CryptoKeyStoreMixin(superClass) {};
return new MyClass(opts);
};

Expand Down
Loading

0 comments on commit d7b354e

Please sign in to comment.