Skip to content

Commit 481c61b

Browse files
authored
[refactor] Improve typescript codebase (#553)
* Use base tsconfig * Add lint check * Fix tilt
1 parent 34347c8 commit 481c61b

File tree

19 files changed

+119
-201
lines changed

19 files changed

+119
-201
lines changed

.github/workflows/lerna.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lerna build & test
1+
name: JS/TS checks
22
on:
33
pull_request:
44
push:
@@ -14,7 +14,9 @@ jobs:
1414
cache: "npm"
1515
- name: Install deps
1616
run: npm ci
17-
- name: Run lerna build
17+
- name: Build
1818
run: npx lerna run build
19-
- name: Run lerna tests
19+
- name: Test
2020
run: npx lerna run test
21+
- name: Lint
22+
run: npx lerna run lint

governance/multisig_wh_message_builder/.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ module.exports = {
33
parser: "@typescript-eslint/parser",
44
plugins: ["@typescript-eslint"],
55
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
6-
rules: {},
6+
rules: {
7+
"@typescript-eslint/no-explicit-any": "off",
8+
},
79
};

governance/multisig_wh_message_builder/src/index.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,19 @@ program
106106
"http://localhost:8899"
107107
)
108108
.action(async (options: any) => {
109-
let cluster: Cluster = options.cluster;
110-
let createKeyAddr: PublicKey = new PublicKey(options.createKey);
111-
let extAuthorityAddr: PublicKey = new PublicKey(options.externalAuthority);
109+
const cluster: Cluster = options.cluster;
110+
const createKeyAddr: PublicKey = new PublicKey(options.createKey);
111+
const extAuthorityAddr: PublicKey = new PublicKey(
112+
options.externalAuthority
113+
);
112114

113-
let threshold: number = parseInt(options.threshold, 10);
115+
const threshold: number = parseInt(options.threshold, 10);
114116

115-
let initialMembers = options.initialMembers
117+
const initialMembers = options.initialMembers
116118
.split(",")
117119
.map((m: string) => new PublicKey(m));
118120

119-
let mesh = await getSquadsClient(
121+
const mesh = await getSquadsClient(
120122
cluster,
121123
options.ledger,
122124
options.ledgerDerivationAccount,
@@ -125,19 +127,21 @@ program
125127
cluster == "localdevnet" ? options.solanaRpc : undefined
126128
);
127129

128-
let vaultAddr = getMsPDA(createKeyAddr, DEFAULT_MULTISIG_PROGRAM_ID)[0];
130+
const vaultAddr = getMsPDA(createKeyAddr, DEFAULT_MULTISIG_PROGRAM_ID)[0];
129131
console.log("Creating new vault at", vaultAddr.toString());
130132

131133
try {
132-
let _multisig = await mesh.getMultisig(vaultAddr);
134+
await mesh.getMultisig(vaultAddr);
133135

134136
// NOTE(2022-12-08): If this check prevents you from iterating dev
135137
// work in tilt, restart solana-devnet.
136138
console.log(
137139
"Reached an existing vault under the address, refusing to create."
138140
);
139141
process.exit(17); // EEXIST
140-
} catch (e: any) {}
142+
} catch (e: any) {
143+
undefined;
144+
}
141145
console.log("No existing vault found, creating...");
142146
await mesh.createMultisig(
143147
extAuthorityAddr,
@@ -309,7 +313,7 @@ program
309313

310314
const wormholeTools = await loadWormholeTools(cluster, squad.connection);
311315

312-
let onChainInstructions = await getProposalInstructions(
316+
const onChainInstructions = await getProposalInstructions(
313317
squad,
314318
await squad.getTransaction(new PublicKey(options.txPda))
315319
);
@@ -692,7 +696,7 @@ async function setIsActiveIx(
692696
attesterProgramId: PublicKey,
693697
isActive: boolean
694698
): Promise<TransactionInstruction> {
695-
const [configKey, _bump] = PublicKey.findProgramAddressSync(
699+
const [configKey] = PublicKey.findProgramAddressSync(
696700
[Buffer.from("pyth2wormhole-config-v3")],
697701
attesterProgramId
698702
);

governance/multisig_wh_message_builder/src/multisig.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import lodash from "lodash";
1111
export async function getActiveProposals(
1212
squad: Squads,
1313
vault: PublicKey,
14-
offset: number = 1
14+
offset = 1
1515
): Promise<TransactionAccount[]> {
1616
const msAccount = await squad.getMultisig(vault);
17-
let txKeys = lodash
17+
const txKeys = lodash
1818
.range(offset, msAccount.transactionIndex + 1)
1919
.map((i) => getTxPDA(vault, new BN(i), DEFAULT_MULTISIG_PROGRAM_ID)[0]);
20-
let msTransactions = await squad.getTransactions(txKeys);
20+
const msTransactions = await squad.getTransactions(txKeys);
2121
return msTransactions
2222
.filter(
2323
(x: TransactionAccount | null): x is TransactionAccount => x != null
@@ -29,10 +29,10 @@ export async function getManyProposalsInstructions(
2929
squad: Squads,
3030
txAccounts: TransactionAccount[]
3131
): Promise<InstructionAccount[][]> {
32-
let allIxsKeys = [];
33-
let ownerTransaction = [];
34-
for (let [index, txAccount] of txAccounts.entries()) {
35-
let ixKeys = lodash
32+
const allIxsKeys = [];
33+
const ownerTransaction = [];
34+
for (const [index, txAccount] of txAccounts.entries()) {
35+
const ixKeys = lodash
3636
.range(1, txAccount.instructionIndex + 1)
3737
.map(
3838
(i) =>
@@ -42,14 +42,14 @@ export async function getManyProposalsInstructions(
4242
DEFAULT_MULTISIG_PROGRAM_ID
4343
)[0]
4444
);
45-
for (let ixKey of ixKeys) {
45+
for (const ixKey of ixKeys) {
4646
allIxsKeys.push(ixKey);
4747
ownerTransaction.push(index);
4848
}
4949
}
5050

51-
let allTxIxsAcccounts = await squad.getInstructions(allIxsKeys);
52-
let ixAccountsByTx: InstructionAccount[][] = Array.from(
51+
const allTxIxsAcccounts = await squad.getInstructions(allIxsKeys);
52+
const ixAccountsByTx: InstructionAccount[][] = Array.from(
5353
Array(txAccounts.length),
5454
() => []
5555
);
@@ -67,13 +67,13 @@ export async function getProposalInstructions(
6767
squad: Squads,
6868
txAccount: TransactionAccount
6969
): Promise<InstructionAccount[]> {
70-
let ixKeys = lodash
70+
const ixKeys = lodash
7171
.range(1, txAccount.instructionIndex + 1)
7272
.map(
7373
(i) =>
7474
getIxPDA(txAccount.publicKey, new BN(i), DEFAULT_MULTISIG_PROGRAM_ID)[0]
7575
);
76-
let txIxs = await squad.getInstructions(ixKeys);
76+
const txIxs = await squad.getInstructions(ixKeys);
7777
return txIxs.filter(
7878
(x: InstructionAccount | null): x is InstructionAccount => x != null
7979
);

governance/multisig_wh_message_builder/src/util.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ async function send(
8888
p2 | P2_MORE,
8989
buffer
9090
);
91-
// @ts-ignore -- TransportStatusError is a constructor Function, not a Class
9291
if (response.length !== 2)
9392
throw TransportStatusError(StatusCodes.INCORRECT_DATA);
9493

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["src"],
4+
"exclude": ["node_modules", "**/__tests__/*"],
25
"compilerOptions": {
3-
"declaration": true,
4-
"composite": true,
5-
"declarationMap": true,
6-
"incremental": true,
7-
"target": "es2016",
8-
"module": "commonjs",
9-
"outDir": "lib",
10-
"esModuleInterop": true,
11-
"forceConsistentCasingInFileNames": true,
12-
"strict": true,
13-
"skipLibCheck": true,
14-
"resolveJsonModule": true,
15-
"noErrorTruncation": true,
16-
"rootDir": "src/"
17-
},
18-
"include": ["src/**/*.ts"]
6+
"rootDir": "src/",
7+
"outDir": "./lib",
8+
"skipLibCheck": true
9+
}
1910
}
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
{
2+
"extends": "../../../../tsconfig.base.json",
3+
"include": ["src"],
4+
"exclude": ["node_modules", "**/__tests__/*"],
25
"compilerOptions": {
3-
"declaration": true,
4-
"composite": true,
5-
"declarationMap": true,
6-
"incremental": true,
7-
"target": "es2016",
8-
"module": "commonjs",
9-
"outDir": "lib",
10-
"esModuleInterop": true,
11-
"forceConsistentCasingInFileNames": true,
12-
"strict": true,
13-
"skipLibCheck": true,
14-
"resolveJsonModule": true,
15-
"noErrorTruncation": true,
16-
"rootDir": "src/"
17-
},
18-
"include": ["src/**/*.ts"],
19-
"exclude": ["src/__tests__/"]
6+
"rootDir": "src/",
7+
"outDir": "./lib",
8+
"skipLibCheck": true
9+
}
2010
}
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
{
2+
"extends": "../../../../tsconfig.base.json",
3+
"include": ["src"],
4+
"exclude": ["node_modules", "**/__tests__/*"],
25
"compilerOptions": {
3-
"declaration": true,
4-
"target": "es2016",
5-
"module": "commonjs",
6-
"outDir": "lib",
7-
"esModuleInterop": true,
8-
"forceConsistentCasingInFileNames": true,
9-
"strict": true,
10-
"skipLibCheck": true,
11-
"resolveJsonModule": true,
12-
"noErrorTruncation": true
13-
},
14-
"include": ["src/**/*.ts"],
15-
"exclude": ["src/__tests__/"]
6+
"rootDir": "src/",
7+
"outDir": "./lib",
8+
"skipLibCheck": true
9+
}
1610
}
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
{
2+
"extends": "../../../../tsconfig.base.json",
3+
"include": ["src"],
4+
"exclude": ["node_modules", "**/__tests__/*"],
25
"compilerOptions": {
3-
"declaration": true,
4-
"composite": true,
5-
"declarationMap": true,
6-
"incremental": true,
7-
"target": "es2016",
8-
"module": "commonjs",
9-
"outDir": "lib",
10-
"esModuleInterop": true,
11-
"forceConsistentCasingInFileNames": true,
12-
"strict": true,
13-
"skipLibCheck": true,
14-
"resolveJsonModule": true,
15-
"noErrorTruncation": true,
16-
"rootDir": "src/"
17-
},
18-
"include": ["src/**/*.ts"],
19-
"exclude": ["src/__tests__/"]
6+
"rootDir": "src/",
7+
"outDir": "./lib",
8+
"skipLibCheck": true
9+
}
2010
}
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
{
2+
"extends": "../../../../tsconfig.base.json",
3+
"include": ["src"],
4+
"exclude": ["node_modules", "**/__tests__/*"],
25
"compilerOptions": {
3-
"declaration": true,
4-
"composite": true,
5-
"declarationMap": true,
6-
"incremental": true,
7-
"target": "es2016",
8-
"module": "commonjs",
9-
"outDir": "lib",
10-
"esModuleInterop": true,
11-
"forceConsistentCasingInFileNames": true,
12-
"strict": true,
13-
"skipLibCheck": true,
14-
"resolveJsonModule": true,
15-
"noErrorTruncation": true,
16-
"rootDir": "src/"
17-
},
18-
"include": ["src/**/*.ts"],
19-
"exclude": ["src/__tests__/"]
6+
"rootDir": "src/",
7+
"outDir": "./lib",
8+
"skipLibCheck": true
9+
}
2010
}

0 commit comments

Comments
 (0)