Add ESLinte to Auction Example

The auction example had no ESLint configuration.
This change adds a .eslintrc.js file that matches
the rest of the projects.

This change also fixes all the linting issue in
the auction example.

Signed-off-by: Brett Logan <lindluni@github.com>
This commit is contained in:
Brett Logan 2021-02-08 09:39:11 -05:00 committed by denyeart
parent 37513c3c2b
commit 9b071d0463
12 changed files with 541 additions and 500 deletions

View file

@ -0,0 +1,5 @@
#
# SPDX-License-Identifier: Apache-2.0
#
coverage

View file

@ -0,0 +1,36 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
module.exports = {
env: {
node: true,
mocha: true
},
parserOptions: {
ecmaVersion: 8,
sourceType: 'script'
},
extends: 'eslint:recommended',
rules: {
indent: ['error', 'tab'],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'no-unused-vars': ['error', { args: 'none' }],
'no-console': 'off',
curly: 'error',
eqeqeq: 'error',
'no-throw-literal': 'error',
strict: 'error',
'no-var': 'error',
'dot-notation': 'error',
'no-trailing-spaces': 'error',
'no-use-before-define': 'error',
'no-useless-call': 'error',
'no-with': 'error',
'operator-linebreak': 'error',
yoda: 'error',
'quote-props': ['error', 'as-needed']
}
};

View file

@ -62,9 +62,9 @@ async function bid(ccp,wallet,user,orgMSP,auctionID,price) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined || process.argv[5] == undefined) { process.argv[4] == undefined || process.argv[5] == undefined) {
console.log("Usage: node bid.js org userID auctionID price"); console.log('Usage: node bid.js org userID auctionID price');
process.exit(1); process.exit(1);
} }
@ -89,8 +89,8 @@ async function main() {
const wallet = await buildWallet(Wallets, walletPath); const wallet = await buildWallet(Wallets, walletPath);
await bid(ccp,wallet,user,orgMSP,auctionID,price); await bid(ccp,wallet,user,orgMSP,auctionID,price);
} else { } else {
console.log("Usage: node bid.js org userID auctionID price"); console.log('Usage: node bid.js org userID auctionID price');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -27,7 +27,7 @@ async function closeAuction(ccp,wallet,user,auctionID) {
// Query the auction to get the list of endorsing orgs. // Query the auction to get the list of endorsing orgs.
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID); let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
var auctionJSON = JSON.parse(auctionString); let auctionJSON = JSON.parse(auctionString);
let statefulTxn = contract.createTransaction('CloseAuction'); let statefulTxn = contract.createTransaction('CloseAuction');
@ -55,9 +55,9 @@ async function closeAuction(ccp,wallet,user,auctionID) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined) { process.argv[4] == undefined) {
console.log("Usage: node closeAuction.js org userID auctionID"); console.log('Usage: node closeAuction.js org userID auctionID');
process.exit(1); process.exit(1);
} }
@ -81,8 +81,8 @@ async function main() {
const wallet = await buildWallet(Wallets, walletPath); const wallet = await buildWallet(Wallets, walletPath);
await closeAuction(ccp,wallet,user,auctionID); await closeAuction(ccp,wallet,user,auctionID);
} else { } else {
console.log("Usage: node closeAuction.js org userID auctionID "); console.log('Usage: node closeAuction.js org userID auctionID ');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -44,9 +44,9 @@ async function createAuction(ccp,wallet,user,auctionID,item) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined || process.argv[5] == undefined) { process.argv[4] == undefined || process.argv[5] == undefined) {
console.log("Usage: node createAuction.js org userID auctionID item"); console.log('Usage: node createAuction.js org userID auctionID item');
process.exit(1); process.exit(1);
} }
@ -71,8 +71,8 @@ async function main() {
const wallet = await buildWallet(Wallets, walletPath); const wallet = await buildWallet(Wallets, walletPath);
await createAuction(ccp,wallet,user,auctionID,item); await createAuction(ccp,wallet,user,auctionID,item);
} else { } else {
console.log("Usage: node createAuction.js org userID auctionID item"); console.log('Usage: node createAuction.js org userID auctionID item');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -27,7 +27,7 @@ async function endAuction(ccp,wallet,user,auctionID) {
// Query the auction to get the list of endorsing orgs. // Query the auction to get the list of endorsing orgs.
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID); let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
var auctionJSON = JSON.parse(auctionString); let auctionJSON = JSON.parse(auctionString);
let statefulTxn = contract.createTransaction('EndAuction'); let statefulTxn = contract.createTransaction('EndAuction');
@ -55,9 +55,9 @@ async function endAuction(ccp,wallet,user,auctionID) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined) { process.argv[4] == undefined) {
console.log("Usage: node endAuction.js org userID auctionID"); console.log('Usage: node endAuction.js org userID auctionID');
process.exit(1); process.exit(1);
} }
@ -81,8 +81,8 @@ async function main() {
const wallet = await buildWallet(Wallets, walletPath); const wallet = await buildWallet(Wallets, walletPath);
await endAuction(ccp,wallet,user,auctionID); await endAuction(ccp,wallet,user,auctionID);
} else { } else {
console.log("Usage: node endAuction.js org userID auctionID"); console.log('Usage: node endAuction.js org userID auctionID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -41,7 +41,7 @@ async function connectToOrg2CA() {
async function main() { async function main() {
if (process.argv[2] == undefined) { if (process.argv[2] == undefined) {
console.log("Usage: node enrollAdmin.js Org"); console.log('Usage: node enrollAdmin.js Org');
process.exit(1); process.exit(1);
} }
@ -55,8 +55,8 @@ async function main() {
else if (org == 'Org2' || org == 'org2') { else if (org == 'Org2' || org == 'org2') {
await connectToOrg2CA(); await connectToOrg2CA();
} else { } else {
console.log("Usage: node registerUser.js org userID"); console.log('Usage: node registerUser.js org userID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`Error in enrolling admin: ${error}`); console.error(`Error in enrolling admin: ${error}`);

View file

@ -38,9 +38,9 @@ async function queryAuction(ccp,wallet,user,auctionID) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined) { process.argv[4] == undefined) {
console.log("Usage: node queryAuction.js org userID auctionID"); console.log('Usage: node queryAuction.js org userID auctionID');
process.exit(1); process.exit(1);
} }
@ -64,8 +64,8 @@ async function main() {
const wallet = await buildWallet(Wallets, walletPath); const wallet = await buildWallet(Wallets, walletPath);
await queryAuction(ccp,wallet,user,auctionID); await queryAuction(ccp,wallet,user,auctionID);
} else { } else {
console.log("Usage: node queryAuction.js org userID auctionID"); console.log('Usage: node queryAuction.js org userID auctionID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -38,9 +38,9 @@ async function queryBid(ccp,wallet,user,auctionID,bidID) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined || process.argv[5] == undefined) { process.argv[4] == undefined || process.argv[5] == undefined) {
console.log("Usage: node bid.js org userID auctionID bidID"); console.log('Usage: node bid.js org userID auctionID bidID');
process.exit(1); process.exit(1);
} }
@ -65,8 +65,8 @@ async function main() {
const wallet = await buildWallet(Wallets, walletPath); const wallet = await buildWallet(Wallets, walletPath);
await queryBid(ccp,wallet,user,auctionID,bidID); await queryBid(ccp,wallet,user,auctionID,bidID);
} else { } else {
console.log("Usage: node bid.js org userID auctionID bidID"); console.log('Usage: node bid.js org userID auctionID bidID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -41,7 +41,7 @@ async function connectToOrg2CA(UserID) {
async function main() { async function main() {
if (process.argv[2] == undefined && process.argv[3] == undefined) { if (process.argv[2] == undefined && process.argv[3] == undefined) {
console.log("Usage: node registerEnrollUser.js org userID"); console.log('Usage: node registerEnrollUser.js org userID');
process.exit(1); process.exit(1);
} }
@ -56,8 +56,8 @@ async function main() {
else if (org == 'Org2' || org == 'org2') { else if (org == 'Org2' || org == 'org2') {
await connectToOrg2CA(userId); await connectToOrg2CA(userId);
} else { } else {
console.log("Usage: node registerEnrollUser.js org userID"); console.log('Usage: node registerEnrollUser.js org userID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`Error in enrolling admin: ${error}`); console.error(`Error in enrolling admin: ${error}`);

View file

@ -27,12 +27,12 @@ async function addBid(ccp,wallet,user,auctionID,bidID) {
console.log('\n--> Evaluate Transaction: read your bid'); console.log('\n--> Evaluate Transaction: read your bid');
let bidString = await contract.evaluateTransaction('QueryBid',auctionID,bidID); let bidString = await contract.evaluateTransaction('QueryBid',auctionID,bidID);
var bidJSON = JSON.parse(bidString); let bidJSON = JSON.parse(bidString);
//console.log('\n--> Evaluate Transaction: query the auction you want to join'); //console.log('\n--> Evaluate Transaction: query the auction you want to join');
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID); let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
// console.log('*** Result: Bid: ' + prettyJSONString(auctionString.toString())); // console.log('*** Result: Bid: ' + prettyJSONString(auctionString.toString()));
var auctionJSON = JSON.parse(auctionString); let auctionJSON = JSON.parse(auctionString);
let bidData = { objectType: 'bid', price: parseInt(bidJSON.price), org: bidJSON.org, bidder: bidJSON.bidder}; let bidData = { objectType: 'bid', price: parseInt(bidJSON.price), org: bidJSON.org, bidder: bidJSON.bidder};
console.log('*** Result: Bid: ' + JSON.stringify(bidData,null,2)); console.log('*** Result: Bid: ' + JSON.stringify(bidData,null,2));
@ -65,9 +65,9 @@ async function addBid(ccp,wallet,user,auctionID,bidID) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined || process.argv[5] == undefined) { process.argv[4] == undefined || process.argv[5] == undefined) {
console.log("Usage: node revealBid.js org userID auctionID bidID"); console.log('Usage: node revealBid.js org userID auctionID bidID');
process.exit(1); process.exit(1);
} }
@ -93,8 +93,8 @@ async function main() {
await addBid(ccp,wallet,user,auctionID,bidID); await addBid(ccp,wallet,user,auctionID,bidID);
} }
else { else {
console.log("Usage: node revealBid.js org userID auctionID bidID"); console.log('Usage: node revealBid.js org userID auctionID bidID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);

View file

@ -37,7 +37,7 @@ async function submitBid(ccp,wallet,user,auctionID,bidID) {
console.log('\n--> Evaluate Transaction: query the auction you want to join'); console.log('\n--> Evaluate Transaction: query the auction you want to join');
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID); let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
var auctionJSON = JSON.parse(auctionString); let auctionJSON = JSON.parse(auctionString);
let statefulTxn = contract.createTransaction('SubmitBid'); let statefulTxn = contract.createTransaction('SubmitBid');
@ -64,13 +64,13 @@ async function submitBid(ccp,wallet,user,auctionID,bidID) {
async function main() { async function main() {
try { try {
if (process.argv[2] == undefined || process.argv[3] == undefined if (process.argv[2] == undefined || process.argv[3] == undefined ||
|| process.argv[4] == undefined || process.argv[5] == undefined) { process.argv[4] == undefined || process.argv[5] == undefined) {
console.log("Usage: node submitBid.js org userID auctionID bidID"); console.log('Usage: node submitBid.js org userID auctionID bidID');
process.exit(1); process.exit(1);
} }
const org = process.argv[2] const org = process.argv[2];
const user = process.argv[3]; const user = process.argv[3];
const auctionID = process.argv[4]; const auctionID = process.argv[4];
const bidID = process.argv[5]; const bidID = process.argv[5];
@ -92,8 +92,8 @@ async function main() {
await submitBid(ccp,wallet,user,auctionID,bidID); await submitBid(ccp,wallet,user,auctionID,bidID);
} }
else { else {
console.log("Usage: node submitBid.js org userID auctionID bidID"); console.log('Usage: node submitBid.js org userID auctionID bidID');
console.log("Org must be Org1 or Org2"); console.log('Org must be Org1 or Org2');
} }
} catch (error) { } catch (error) {
console.error(`******** FAILED to run the application: ${error}`); console.error(`******** FAILED to run the application: ${error}`);