Skip to content

Commit

Permalink
Setup linter and add it to CI (#54)
Browse files Browse the repository at this point in the history
- Setup eslint with husky for precommit lint
- Fix existing lint errors
- Setup linter CI

Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/54
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
  • Loading branch information
prathamesh0 authored and Ashwin committed Jan 29, 2024
1 parent b01201c commit c3f8d53
Show file tree
Hide file tree
Showing 51 changed files with 1,601 additions and 215 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Don't lint node_modules.
node_modules

# Don't lint build output.
dist
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"env": {
"node": true
},
"extends": [
"semistandard",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"@typescript-eslint/no-explicit-any": "off"
}
}
28 changes: 28 additions & 0 deletions .gitea/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint
on:
pull_request:
branches:
- '*'
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Download yarn
run: |
curl -fsSL -o /usr/local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.21/yarn-1.22.21.js
chmod +x /usr/local/bin/yarn
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- name: Linter check
run: yarn lint
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ["dotenv/config"]
setupFiles: ['dotenv/config']
};
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.25",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"dotenv": "^16.3.2",
"eslint": "^8.35.0",
"eslint-config-semistandard": "^15.0.1",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"husky": "^9.0.2",
"jest": "29.0.0",
"ts-jest": "^29.0.2",
"dotenv": "^16.3.2",
"typescript": "^4.6.3"
},
"dependencies": {
Expand All @@ -29,9 +39,10 @@
"test": "jest --runInBand --verbose test/cli.test.ts",
"lint": "eslint .",
"clean": "rm -rf ./dist",
"build": "tsc"
"build": "tsc",
"prepare": "husky"
},
"bin": {
"laconic": "bin/laconic"
}
}
}
6 changes: 3 additions & 3 deletions src/cmds/cns-cmds/account-cmds/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const desc = 'Get account.';
export const handler = async (argv: Arguments) => {
let address = argv.address as string;

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -24,5 +24,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAccounts([address]);

queryOutput(result,argv.output);
}
queryOutput(result, argv.output);
};
2 changes: 1 addition & 1 deletion src/cmds/cns-cmds/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const desc = 'Account operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('account-cmds')
.demandCommand();
}
};
8 changes: 4 additions & 4 deletions src/cmds/cns-cmds/auction-cmds/bid-cmds/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const handler = async (argv: Arguments) => {
assert(quantity, 'Invalid token quantity.');
assert(denom, 'Invalid token type.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -43,7 +43,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);

const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
const revealFile = `{"reveal_file":"${revealFilePath}"}`
const revealFile = `{"reveal_file":"${revealFilePath}"}`;

txOutput(result,revealFile,argv.output,argv.verbose)
}
txOutput(result, revealFile, argv.output, argv.verbose);
};
10 changes: 5 additions & 5 deletions src/cmds/cns-cmds/auction-cmds/bid-cmds/reveal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const handler = async (argv: Arguments) => {
assert(auctionId, 'Invalid auction ID.');
assert(filePath, 'Invalid reveal file path.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -28,7 +28,7 @@ export const handler = async (argv: Arguments) => {

const reveal = fs.readFileSync(path.resolve(filePath));
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;

txOutput(result, success, argv.output, argv.verbose);
};
12 changes: 6 additions & 6 deletions src/cmds/cns-cmds/auction-cmds/bid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export const desc = 'Auction bid operations.';

exports.builder = (yargs: yargs.Argv) => {
return yargs.options({
'auction-id': { type: 'string' },
'type': { type: 'string' },
'quantity': { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
'auction-id': { type: 'string' },
type: { type: 'string' },
quantity: { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
.demandCommand();
}
};
6 changes: 3 additions & 3 deletions src/cmds/cns-cmds/auction-cmds/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
assert(id, 'Invalid auction ID.');

const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAuctionsByIds([id as string]);

queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};
2 changes: 1 addition & 1 deletion src/cmds/cns-cmds/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const desc = 'Auction operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('auction-cmds')
.demandCommand();
}
};
8 changes: 4 additions & 4 deletions src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid authority name.');
assert(bondId, 'Invalid Bond ID.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -24,7 +24,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}`
const success = `{"success":${result.code === 0}}`;

txOutput(result,success,argv.output,argv.verbose)
}
txOutput(result, success, argv.output, argv.verbose);
};
2 changes: 1 addition & 1 deletion src/cmds/cns-cmds/authority-cmds/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const desc = 'Authority bond operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds')
.demandCommand();
}
};
10 changes: 5 additions & 5 deletions src/cmds/cns-cmds/authority-cmds/reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const builder = {
type: 'string',
default: ''
}
}
};

export const handler = async (argv: Arguments) => {
const name = argv.name as string;
const owner = argv.owner as string;
assert(name, 'Invalid authority name.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -31,6 +31,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);

const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
6 changes: 3 additions & 3 deletions src/cmds/cns-cmds/authority-cmds/whois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid authority name.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupAuthorities([name], true);

queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};
2 changes: 1 addition & 1 deletion src/cmds/cns-cmds/authority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const desc = 'Name authority operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('authority-cmds')
.demandCommand();
}
};
13 changes: 6 additions & 7 deletions src/cmds/cns-cmds/bond-cmds/associate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';

import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';

export const command = 'associate';

Expand All @@ -12,15 +12,15 @@ export const builder = {
'bond-id': {
type: 'string'
}
}
};

export const handler = async (argv: Arguments) => {
const id = argv.id as string;
const bondId = argv.bondId as string;
assert(id, 'Invalid Record ID.');
assert(bondId, 'Invalid Bond ID.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -30,7 +30,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)

}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
13 changes: 6 additions & 7 deletions src/cmds/cns-cmds/bond-cmds/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';

import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';

export const command = 'cancel';

export const desc = 'Cancel bond.';

export const handler = async (argv: Arguments) => {
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');

const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -22,7 +22,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.cancelBond({ id }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)

}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
15 changes: 7 additions & 8 deletions src/cmds/cns-cmds/bond-cmds/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';

import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';

export const command = 'create';

Expand All @@ -15,17 +15,17 @@ export const builder = {
quantity: {
type: 'string'
}
}
};

export const handler = async (argv: Arguments) => {
const { config, verbose } = argv;
const { config } = argv;
const denom = argv.type as string;
const amount = argv.quantity as string;

assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');

const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
Expand All @@ -36,8 +36,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const bondId = await registry.getNextBondId(privateKey);
const result = await registry.createBond({ denom, amount }, privateKey, fee);
const jsonString=`{"bondId":"${bondId}"}`
const jsonString = `{"bondId":"${bondId}"}`;

txOutput(result,jsonString,argv.output,argv.verbose)

}
txOutput(result, jsonString, argv.output, argv.verbose);
};
Loading

0 comments on commit c3f8d53

Please sign in to comment.