Skip to content

Commit

Permalink
BE-836 Configure eslint for typescript (#195)
Browse files Browse the repository at this point in the history
Did code lint acorss all ts code by eslint/prettier

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia authored Oct 7, 2020
1 parent 5f70976 commit 42e0e5c
Show file tree
Hide file tree
Showing 44 changed files with 1,135 additions and 638 deletions.
90 changes: 38 additions & 52 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"plugins": ["spellcheck"],
"extends": "airbnb",
"extends": ["airbnb"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
Expand Down Expand Up @@ -111,7 +111,7 @@
"no-magic-numbers": ["off"],
"no-restricted-globals": ["off"],
"no-restricted-syntax": ["off"],
"no-console": ["off"],
"no-console": ["error"],
"no-tabs": ["off"],
"func-names": ["off"],
"one-var": ["off"],
Expand Down Expand Up @@ -173,34 +173,10 @@
"identifiers": false,
"lang": "en_US",
"skipWords": [
"0px",
"1px",
"2px",
"3px",
"4px",
"10px",
"12px",
"14px",
"9px",
"25px",
"30px",
"70px",
"100px",
"100vh",
"520px",
"750px",
"7165ae",
"rgba",
"afeeee",
"#",
"-yyyy",
"-yyyy-MM-dd",
"5bc5c2",
"dff1fe",
"858aa6",
"d0ecda",
"ffa686",
"ffeed8",
"adminpw",
"adminroutes",
"aff",
Expand All @@ -211,22 +187,8 @@
"auth",
"authroutes",
"axios",
"blksize",
"blockactivity",
"blocksbyhour",
"blockandtx",
"blockhash",
"blockid",
"blocknum",
"blocksbyminute",
"cartesian",
"chai",
"chaincode",
"chaincodename",
"chaincodes",
"chaincodeid",
"channelid",
"channelname",
"checkbox",
"classnames",
"const",
Expand Down Expand Up @@ -295,9 +257,6 @@
"newpeer",
"nock",
"nowrap",
"orderer",
"orderers",
"orderrers",
"orgs",
"param",
"peerid",
Expand Down Expand Up @@ -349,9 +308,6 @@
"timeline",
"tls",
"tooltip",
"txcount",
"txid",
"txhash",
"robertfeng",
"vchinoy",
"Uint8",
Expand All @@ -372,7 +328,6 @@
"Im7h",
"helmet-csp",
"khanacademy",
"channelsinfo",
"signcerts",
"utf8",
"dirname",
Expand All @@ -390,8 +345,6 @@
"searchparm",
"x-xss-protection",
"prc",
"cfcdcd",
"594aa5",
"accessor",
"asn1",
"Asn",
Expand Down Expand Up @@ -441,10 +394,27 @@
"unregister",
"userdataservice",
"parens",
"npm"
"npm",
"sqlcharacter",
"peerlist",
"www",
"craetedat"
],
"skipIfMatch": ["http://[^s]*", "[a-z]scc"],
"skipWordIfMatch": ["^foobar.*$"],
"skipWordIfMatch": [
"^\\d+px",
"^\\d+vh",
"^#[0-9a-f]+",
"blk[a-z]+",
"block[a-z]+",
"[Cc]haincode[a-z]*",
"channel[a-z]+",
"[Oo]rderer[a-z]*",
"'[0-9a-f]{64}'",
"[a-zA-Z._0-9]{80}",
"[cq]scc",
"^get[a-zA-Z]+"
],
"skipIfMatch": ["[a-zA-Z._0-9]{80}", "'*tx[A-Za-z_]+"],
"minLength": 3
}
]
Expand All @@ -455,6 +425,22 @@
"rules": {
"no-unused-expressions": "off"
}
},
{
"files": ["**/*.ts"],
"plugins": ["spellcheck", "@typescript-eslint", "no-loops"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-console": ["error"],
"import/extensions": ["off"]
}
}
]
}
30 changes: 14 additions & 16 deletions app/Explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,35 @@ import swaggerUi from 'swagger-ui-express';
import compression from 'compression';
import passport from 'passport';
import RateLimit from 'express-rate-limit';
import {PlatformBuilder } from './platform/PlatformBuilder';
import { PlatformBuilder } from './platform/PlatformBuilder';
import explorerconfig from './explorerconfig.json';
import {PersistenceFactory} from './persistence/PersistenceFactory';
import {authroutes} from './rest/authroutes';
import {dbroutes} from './rest/dbroutes';
import {platformroutes} from './rest/platformroutes';
import {adminroutes} from './platform/fabric/rest/adminroutes';
import {explorerConst} from './common/ExplorerConst'
import {explorerError} from './common/ExplorerMessage'
import {authCheckMiddleware} from './middleware/auth-check';
import { PersistenceFactory } from './persistence/PersistenceFactory';
import { authroutes } from './rest/authroutes';
import { dbroutes } from './rest/dbroutes';
import { platformroutes } from './rest/platformroutes';
import { adminroutes } from './platform/fabric/rest/adminroutes';
import { explorerConst } from './common/ExplorerConst';
import { explorerError } from './common/ExplorerMessage';
import { authCheckMiddleware } from './middleware/auth-check';
import swaggerDocument from './swagger.json';
import {ExplorerError} from './common/ExplorerError';
import {localLoginStrategy} from './passport/local-login';
import { ExplorerError } from './common/ExplorerError';
import { localLoginStrategy } from './passport/local-login';

/**
*
*
* @class Explorer
*/
export class Explorer {

app = Express();
persistence : any;
platforms : any[];
persistence: any;
platforms: any[];

/**
* Creates an instance of explorerConst.
* @memberof Explorer
*/
constructor() {

// set up rate limiter: maximum of 1000 requests per minute

const limiter = new RateLimit({
Expand Down Expand Up @@ -153,4 +151,4 @@ export class Explorer {
}
}
}
}
}
10 changes: 5 additions & 5 deletions app/Synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import { helper } from './common/helper';
import { explorerConst } from './common/ExplorerConst';
import { explorerError } from './common/ExplorerMessage';
import {ExplorerError} from './common/ExplorerError';
import { ExplorerError } from './common/ExplorerError';
import syncconfig from './explorerconfig.json';
import {SyncBuilder} from './sync/SyncBuilder';
import {PersistenceFactory} from './persistence/PersistenceFactory';
import {ExplorerSender} from './sync/sender/ExplorerSender';
import { SyncBuilder } from './sync/SyncBuilder';
import { PersistenceFactory } from './persistence/PersistenceFactory';
import { ExplorerSender } from './sync/sender/ExplorerSender';
/* eslint-enable import/extensions */
const logger = helper.getLogger('Synchronizer');

Expand Down Expand Up @@ -91,4 +91,4 @@ export class Synchronizer {
this.platform.destroy();
}
}
}
}
1 change: 1 addition & 0 deletions app/common/ExplorerConst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* Explorer constants
*/
/* eslint-disable no-shadow */
export enum explorerConst {
PERSISTENCE = 'persistence',
PLATFORMS = 'platforms',
Expand Down
2 changes: 0 additions & 2 deletions app/common/ExplorerError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ export function ExplorerError(...args: string[]) {
this.name = this.constructor.name;
this.message = util.format(args);
}

//require('util').inherits(module.exports, Error);
36 changes: 12 additions & 24 deletions app/common/ExplorerMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,38 @@
/**
* Generic, and Fabric Error messages
*/

/* eslint-disable no-shadow */
export enum explorerError {
ERROR_1001 =
'Missing persistence type property [persistence] in explorerconfig.json',
ERROR_1002 =
'Missing database configuration property [%s] in explorerconfig.json',
ERROR_1001 = 'Missing persistence type property [persistence] in explorerconfig.json',
ERROR_1002 = 'Missing database configuration property [%s] in explorerconfig.json',
ERROR_1003 = 'Persistence implementation is not found for %s',
ERROR_1004 = 'Platform implementation is not found for %s',
ERROR_1005 = 'Platform implementation is not found for synch process %s',
ERROR_1006 = 'Platform type is not found in syncconfig or argument',
ERROR_1007 =
'Missing network_name and client_name , Please run as > sync.js network_name client_name',
ERROR_1008 =
'Sync type is set as [local] hence independent sync process cannot be started. Please change the sync type to [host] and restart explorer',
ERROR_1009 =
'Failed to connect client peer, please check the configuration and peer status',
ERROR_1010 =
'Failed to create wallet, please check the configuration, and valid file paths',
ERROR_1007 = 'Missing network_name and client_name , Please run as > sync.js network_name client_name',
ERROR_1008 = 'Sync type is set as [local] hence independent sync process cannot be started. Please change the sync type to [host] and restart explorer',
ERROR_1009 = 'Failed to connect client peer, please check the configuration and peer status',
ERROR_1010 = 'Failed to create wallet, please check the configuration, and valid file paths',

// Fabric Error message
ERROR_2001 = 'Default defined channel %s is not found for the client %s peer',
ERROR_2002 =
'There are no orderers defined on this channel in the network configuration',
ERROR_2003 =
'Default client peer is down and no channel details available database',
ERROR_2002 = 'There are no orderers defined on this channel in the network configuration',
ERROR_2003 = 'Default client peer is down and no channel details available database',
ERROR_2004 = 'Default channel is not available in database',
ERROR_2005 = 'Default peer is not available in database',
ERROR_2006 = 'Default peer is not added in the client %s',
ERROR_2007 = 'No TLS cert information available',
ERROR_2008 = 'There is no client found for Hyperledger fabric platform',
ERROR_2009 =
'Explorer is closing due to channel name [%s] is already exist in DB',
ERROR_2009 = 'Explorer is closing due to channel name [%s] is already exist in DB',
ERROR_2010 = 'Client Processor Error >> %s',
ERROR_2011 = 'There is no client found for Hyperledger fabric scanner',
ERROR_2013 =
'Channel name [%s] already exist in DB , Kindly re-run the DB scripts to proceed',
ERROR_2013 = 'Channel name [%s] already exist in DB , Kindly re-run the DB scripts to proceed',
ERROR_2014 = 'Invalid platform configuration, Please check the log',
ERROR_2015 = 'Invalid network configuration, Please check the log',

// Generic Message
MESSAGE_1001 = 'Explorer will continue working with only DB data',
MESSAGE_1002 =
'Sync process is started for the network = [%s] and client = [%s]'
MESSAGE_1002 = 'Sync process is started for the network = [%s] and client = [%s]'

// Fabric Message

}
25 changes: 13 additions & 12 deletions app/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,23 @@ import yn from 'yn';
* @returns
*/
export class helper {

static getLogger(moduleName: string) : any {
static getLogger(moduleName: string): any {
const logger = log4js.getLogger(moduleName);

let appLog = 'logs/app/app.log';
let dbLog = 'logs/db/db.log';
let consoleLog = 'logs/console/console.log';

if (process.env.SYNC_LOG_PATH) {
appLog = `${process.env.SYNC_LOG_PATH}/app/app.log`;
dbLog = `${process.env.SYNC_LOG_PATH}/db/db.log`;
consoleLog = `${process.env.SYNC_LOG_PATH}/console/console.log`;
}

let appLevel = 'debug';
let dbLevel = 'debug';
let consoleLevel = 'info';

if (process.env.LOG_LEVEL_APP) {
appLevel = process.env.LOG_LEVEL_APP;
}
Expand All @@ -68,7 +67,7 @@ export class helper {
if (process.env.LOG_LEVEL_CONSOLE) {
consoleLevel = process.env.LOG_LEVEL_CONSOLE;
}

const logConfig = {
appenders: {
app: {
Expand Down Expand Up @@ -100,16 +99,18 @@ export class helper {
PgService: { appenders: ['consoleFilter', 'db'], level: dbLevel }
}
};

if (process.env.LOG_CONSOLE_STDOUT) {
if (yn(process.env.LOG_CONSOLE_STDOUT)) {
logConfig.appenders.console = { ...logConfig.appenders.console, type: 'console' };
logConfig.appenders.console = {
...logConfig.appenders.console,
type: 'console'
};
}
}

log4js.configure(logConfig);

return logger;
}
}

Loading

0 comments on commit 42e0e5c

Please sign in to comment.