Skip to content

Commit

Permalink
[FAB-12456] Adding eslint to chaincode-node
Browse files Browse the repository at this point in the history
Change-Id: I015be309e016e84920b77e3a20148f460a8b549d
Signed-off-by: SamRasha <[email protected]>
  • Loading branch information
SammyRasha committed Oct 18, 2018
1 parent a072650 commit d43ceca
Show file tree
Hide file tree
Showing 49 changed files with 8,276 additions and 8,212 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
52 changes: 46 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
"sourceType": "module"
},
"rules": {
"indent": ["error", "tab"],
"array-bracket-spacing": ["error", "never"],
"arrow-spacing": ["error"],
"brace-style": ["error"],
"comma-spacing": ["error"],
"curly": ["error"],
"dot-notation": ["error"],
"eqeqeq": ["error"],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"keyword-spacing":"error",
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-unused-vars":["error"],
"no-trailing-spaces": ["error"],
"max-len": [
"error",
{
Expand All @@ -26,6 +36,36 @@
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true
}
]
],
"no-console": ["warn"],
"no-shadow": ["error"],
"no-throw-literal": ["error"],
"no-trailing-spaces": ["error"],
"no-useless-call": ["error"],
"no-unused-vars": [
"error",
{
"args": "none"
}
],
"no-var": ["error"],
"no-with": ["error"],
"object-curly-spacing": ["error", "never"],
"operator-linebreak": ["error"],
"prefer-const": ["error"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"spaced-comment": ["error", "always"],
"space-before-blocks": [
"error",
{
"functions": "always",
"keywords": "always",
"classes": "always"
}
],
"space-infix-ops": ["error"],
"space-in-parens": ["error", "never"],
"yoda": "error"
}
}
131 changes: 65 additions & 66 deletions build/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,90 @@
#
# SPDX-License-Identifier: Apache-2.0
*/

var gulp = require('gulp');
var jsdoc = require('gulp-jsdoc3');
var fs = require('fs-extra');
const path=require('path');
/* eslint-disable no-console */
const gulp = require('gulp');
const jsdoc = require('gulp-jsdoc3');
const fs = require('fs-extra');
const path = require('path');
const replace = require('gulp-replace');
let currentBranch=process.env.GERRIT_BRANCH;
let currentBranch = process.env.GERRIT_BRANCH;

if (!currentBranch){
currentBranch='master';
if (!currentBranch) {
currentBranch = 'master';
}


let docsRoot;
if (process.env.DOCS_ROOT){
docsRoot = process.env.DOCS_ROOT;
if (process.env.DOCS_ROOT) {
docsRoot = process.env.DOCS_ROOT;
} else {
docsRoot = './docs/gen';
docsRoot = './docs/gen';
}

gulp.task('clean', function(){
return fs.removeSync(path.join(docsRoot,currentBranch));
gulp.task('clean', function() {
return fs.removeSync(path.join(docsRoot, currentBranch));
});

let docSrc = [
'docs/README.md',
'fabric-shim/lib/chaincode.js',
'fabric-shim/lib/stub.js',
'fabric-shim/lib/iterators.js',
'fabric-contract-api/lib/**/*.js'
const docSrc = [
'docs/README.md',
'fabric-shim/lib/chaincode.js',
'fabric-shim/lib/stub.js',
'fabric-shim/lib/iterators.js',
'fabric-contract-api/lib/**/*.js'
];


gulp.task('jsdocs', ['clean'], function (cb) {
gulp.src(docSrc, { read: false }).pipe(
jsdoc({
opts: {
tutorials: './docs/tutorials',
destination: path.join(docsRoot,currentBranch)
},
templates: {
systemName: 'Hyperledger Fabric Node.js Contract and Shim',
theme: 'cosmo'
},

},cb)
);
gulp.src(docSrc, {read: false}).pipe(jsdoc({
opts: {
tutorials: './docs/tutorials',
destination: path.join(docsRoot, currentBranch)
},
templates: {
systemName: 'Hyperledger Fabric Node.js Contract and Shim',
theme: 'cosmo'
},

}, cb)
);
});


gulp.task('docs-dev',['docs'], function(){
gulp.watch(docSrc,['docs']);
gulp.task('docs-dev', ['docs'], function() {
gulp.watch(docSrc, ['docs']);
});


gulp.task('docs',['jsdocs'],()=>{

const relativePath = '.';
const packageJson = require(path.join(__dirname,'..','package.json'));
let mapping = ['ClientIdentity',
'ChaincodeFromContract',
'CommonIterator',
'ChaincodeInterface',
'ChaincodeStub',
'HistoryQueryIterator',
'ChaincodeStub.SignedProposal',
'Shim',
'Meta',
'StateQueryIterator'
];

mapping = mapping.map((e)=>{
return `'${e}.html'`;
});

// jsdocs produced
// if this is the master build then we need to ensure that the index.html and
// the 404.html page are properly setup and configured.
if (currentBranch==='master'){
gulp.src('./docs/redirectTemplates/*.html' )
.pipe(replace('LATEST__VERSION',packageJson.docsLatestVersion))
.pipe(replace('FILENAME__MAPPING',mapping.join(',')))
.pipe(replace('RELATIVE__PATH',relativePath))
.pipe(gulp.dest(docsRoot));
} else {
console.log(`Not updating or routing logic, as not master branch - it is ${currentBranch}`); // eslint-disable-line no-console
}
gulp.task('docs', ['jsdocs'], () => {

const relativePath = '.';
const packageJson = require(path.join(__dirname, '..', 'package.json'));
let mapping = ['ClientIdentity',
'ChaincodeFromContract',
'CommonIterator',
'ChaincodeInterface',
'ChaincodeStub',
'HistoryQueryIterator',
'ChaincodeStub.SignedProposal',
'Shim',
'Meta',
'StateQueryIterator'
];

mapping = mapping.map((e) => {
return `'${e}.html'`;
});

// jsdocs produced
// if this is the master build then we need to ensure that the index.html and
// the 404.html page are properly setup and configured.
if (currentBranch === 'master') {
gulp.src('./docs/redirectTemplates/*.html')
.pipe(replace('LATEST__VERSION', packageJson.docsLatestVersion))
.pipe(replace('FILENAME__MAPPING', mapping.join(',')))
.pipe(replace('RELATIVE__PATH', relativePath))
.pipe(gulp.dest(docsRoot));
} else {
console.log(`Not updating or routing logic, as not master branch - it is ${currentBranch}`);
}
});
20 changes: 10 additions & 10 deletions build/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const eslint = require('gulp-eslint');
const path = require('path');

gulp.task('lint', function () {
return gulp.src([
'**/*.js',
'!fabric-shim/node_modules/**',
'!test/node_modules/**',
'!**/typescript/*.js',
'!coverage/**',
'!docs/**'
], {
base: path.join(__dirname, '..')
}).pipe(eslint()).pipe(eslint.format()).pipe(eslint.failAfterError());
return gulp.src([
'**/*.js',
'!fabric-shim/node_modules/**',
'!test/node_modules/**',
'!**/typescript/*.js',
'!coverage/**',
'!docs/**'
], {
base: path.join(__dirname, '..')
}).pipe(eslint()).pipe(eslint.format()).pipe(eslint.failAfterError());
});
38 changes: 19 additions & 19 deletions build/protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ const fs = require('fs');

const GOPATH = process.env.GOPATH;
if (!GOPATH || GOPATH === '') {
console.error(
'The shim implementation depends on protobuf definitions from fabric GO package "%s", ' +
console.error(
'The shim implementation depends on protobuf definitions from fabric GO package "%s", ' +
'but the GOPATH environment variable has not been set up',
'github.com/hyperledger/fabric/protos');
process.exit(1);
'github.com/hyperledger/fabric/protos');
process.exit(1);
}

const baseDir = path.join(GOPATH, 'src/github.com/hyperledger/fabric/protos');
if (!fs.existsSync(baseDir)) {
console.error(
'The shim implementation depends on protobuf definitions from fabric GO package "%s", ' +
console.error(
'The shim implementation depends on protobuf definitions from fabric GO package "%s", ' +
'but the directory "%s" does not seem to exist',
'github.com/hyperledger/fabric/protos',
baseDir);
'github.com/hyperledger/fabric/protos',
baseDir);
}

const DEPS = [
path.join(baseDir, 'common/common.proto'),
path.join(baseDir, 'msp/identities.proto'),
path.join(baseDir, 'ledger/queryresult/kv_query_result.proto'),
path.join(baseDir, 'peer/chaincode.proto'),
path.join(baseDir, 'peer/chaincode_event.proto'),
path.join(baseDir, 'peer/chaincode_shim.proto'),
path.join(baseDir, 'peer/proposal.proto'),
path.join(baseDir, 'peer/proposal_response.proto')
path.join(baseDir, 'common/common.proto'),
path.join(baseDir, 'msp/identities.proto'),
path.join(baseDir, 'ledger/queryresult/kv_query_result.proto'),
path.join(baseDir, 'peer/chaincode.proto'),
path.join(baseDir, 'peer/chaincode_event.proto'),
path.join(baseDir, 'peer/chaincode_shim.proto'),
path.join(baseDir, 'peer/proposal.proto'),
path.join(baseDir, 'peer/proposal_response.proto')
];

gulp.task('protos', function() {
return gulp.src(DEPS, { base: baseDir })
.pipe(debug())
.pipe(gulp.dest(path.join(__dirname, '../fabric-shim/lib/protos')));
return gulp.src(DEPS, {base: baseDir})
.pipe(debug())
.pipe(gulp.dest(path.join(__dirname, '../fabric-shim/lib/protos')));
});

module.exports.DEPS = DEPS;
Loading

0 comments on commit d43ceca

Please sign in to comment.