Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 51c4dc6

Browse files
authored
Fix lint check in CI (#519)
* Fix lint check in CI * `npm run lint` now checks that code is properly formatted, instead of running the formatter * Add extra commands to run the linting, include ts definitions file * Update flow-bin, fix type errors that come up * Clarify lint vs lint:fix as requested
1 parent e8bb772 commit 51c4dc6

File tree

13 files changed

+179
-129
lines changed

13 files changed

+179
-129
lines changed

token-swap/js/client/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const uint64 = (property: string = 'uint64'): Object => {
1919
/**
2020
* Layout for a Rust String type
2121
*/
22-
export const rustString = (property: string = 'string') => {
22+
export const rustString = (property: string = 'string'): Object => {
2323
const rsl = BufferLayout.struct(
2424
[
2525
BufferLayout.u32('length'),

token-swap/js/client/token-swap.js

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
import assert from 'assert';
66
import BN from 'bn.js';
77
import * as BufferLayout from 'buffer-layout';
8-
import type { Connection, TransactionSignature } from '@solana/web3.js';
9-
import { Account, PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
8+
import type {Connection, TransactionSignature} from '@solana/web3.js';
9+
import {
10+
Account,
11+
PublicKey,
12+
SystemProgram,
13+
Transaction,
14+
TransactionInstruction,
15+
} from '@solana/web3.js';
1016

1117
import * as Layout from './layout';
12-
import { sendAndConfirmTransaction } from './util/send-and-confirm-transaction';
18+
import {sendAndConfirmTransaction} from './util/send-and-confirm-transaction';
1319

1420
/**
1521
* Some amount of tokens
@@ -18,7 +24,7 @@ export class Numberu64 extends BN {
1824
/**
1925
* Convert to Buffer representation
2026
*/
21-
toBuffer(): Buffer {
27+
toBuffer(): typeof Buffer {
2228
const a = super.toArray().reverse();
2329
const b = Buffer.from(a);
2430
if (b.length === 8) {
@@ -34,7 +40,7 @@ export class Numberu64 extends BN {
3440
/**
3541
* Construct a Numberu64 from Buffer representation
3642
*/
37-
static fromBuffer(buffer: Buffer): Numberu64 {
43+
static fromBuffer(buffer: typeof Buffer): Numberu64 {
3844
assert(buffer.length === 8, `Invalid buffer length: ${buffer.length}`);
3945
return new BN(
4046
[...buffer]
@@ -89,15 +95,17 @@ type TokenSwapInfo = {|
8995
/**
9096
* @private
9197
*/
92-
export const TokenSwapLayout = BufferLayout.struct([
93-
BufferLayout.u8('isInitialized'),
94-
BufferLayout.u8('nonce'),
95-
Layout.publicKey('tokenAccountA'),
96-
Layout.publicKey('tokenAccountB'),
97-
Layout.publicKey('tokenPool'),
98-
Layout.uint64('feesNumerator'),
99-
Layout.uint64('feesDenominator'),
100-
]);
98+
export const TokenSwapLayout: typeof BufferLayout.Structure = BufferLayout.struct(
99+
[
100+
BufferLayout.u8('isInitialized'),
101+
BufferLayout.u8('nonce'),
102+
Layout.publicKey('tokenAccountA'),
103+
Layout.publicKey('tokenAccountB'),
104+
Layout.publicKey('tokenPool'),
105+
Layout.uint64('feesNumerator'),
106+
Layout.uint64('feesDenominator'),
107+
],
108+
);
101109

102110
/**
103111
* An ERC20-like Token
@@ -153,7 +161,6 @@ export class TokenSwap {
153161
);
154162
}
155163

156-
157164
static createInitSwapInstruction(
158165
tokenSwapAccount: Account,
159166
authority: PublicKey,
@@ -165,16 +172,16 @@ export class TokenSwap {
165172
tokenProgramId: PublicKey,
166173
swapProgramId: PublicKey,
167174
feeNumerator: number,
168-
feeDenominator: number
169-
):TransactionInstruction {
175+
feeDenominator: number,
176+
): TransactionInstruction {
170177
const keys = [
171-
{ pubkey: tokenSwapAccount.publicKey, isSigner: false, isWritable: true },
172-
{ pubkey: authority, isSigner: false, isWritable: false },
173-
{ pubkey: tokenAccountA, isSigner: false, isWritable: false },
174-
{ pubkey: tokenAccountB, isSigner: false, isWritable: false },
175-
{ pubkey: tokenPool, isSigner: false, isWritable: true },
176-
{ pubkey: tokenAccountPool, isSigner: false, isWritable: true },
177-
{ pubkey: tokenProgramId, isSigner: false, isWritable: false },
178+
{pubkey: tokenSwapAccount.publicKey, isSigner: false, isWritable: true},
179+
{pubkey: authority, isSigner: false, isWritable: false},
180+
{pubkey: tokenAccountA, isSigner: false, isWritable: false},
181+
{pubkey: tokenAccountB, isSigner: false, isWritable: false},
182+
{pubkey: tokenPool, isSigner: false, isWritable: true},
183+
{pubkey: tokenAccountPool, isSigner: false, isWritable: true},
184+
{pubkey: tokenProgramId, isSigner: false, isWritable: false},
178185
];
179186
const commandDataLayout = BufferLayout.struct([
180187
BufferLayout.u8('instruction'),
@@ -257,7 +264,19 @@ export class TokenSwap {
257264
}),
258265
);
259266

260-
const instruction = TokenSwap.createInitSwapInstruction(tokenSwapAccount, authority, nonce, tokenAccountA, tokenAccountB, tokenPool, tokenAccountPool, tokenProgramId, swapProgramId, feeNumerator, feeDenominator);
267+
const instruction = TokenSwap.createInitSwapInstruction(
268+
tokenSwapAccount,
269+
authority,
270+
nonce,
271+
tokenAccountA,
272+
tokenAccountB,
273+
tokenPool,
274+
tokenAccountPool,
275+
tokenProgramId,
276+
swapProgramId,
277+
feeNumerator,
278+
feeDenominator,
279+
);
261280

262281
transaction.add(instruction);
263282
await sendAndConfirmTransaction(
@@ -271,7 +290,6 @@ export class TokenSwap {
271290
return tokenSwap;
272291
}
273292

274-
275293
/**
276294
* Retrieve tokenSwap information
277295
*/

token-swap/js/client/util/store.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ import fs from 'mz/fs';
99
import mkdirp from 'mkdirp-promise';
1010

1111
export class Store {
12-
dir = path.join(__dirname, 'store');
12+
static getDir(): string {
13+
return path.join(__dirname, 'store');
14+
}
1315

1416
async load(uri: string): Promise<Object> {
15-
const filename = path.join(this.dir, uri);
17+
const filename = path.join(Store.getDir(), uri);
1618
const data = await fs.readFile(filename, 'utf8');
1719
const config = JSON.parse(data);
1820
return config;
1921
}
2022

2123
async save(uri: string, config: Object): Promise<void> {
22-
await mkdirp(this.dir);
23-
const filename = path.join(this.dir, uri);
24+
await mkdirp(Store.getDir());
25+
const filename = path.join(Store.getDir(), uri);
2426
await fs.writeFile(filename, JSON.stringify(config), 'utf8');
2527
}
2628
}

token-swap/js/module.d.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
declare module '@solana/spl-token-swap' {
2-
import { Buffer } from 'buffer';
3-
import { Layout } from 'buffer-layout';
4-
import { PublicKey, TransactionInstruction, TransactionSignature, Connection, Account } from "@solana/web3.js";
2+
import {Buffer} from 'buffer';
3+
import {Layout} from 'buffer-layout';
4+
import {
5+
PublicKey,
6+
TransactionInstruction,
7+
TransactionSignature,
8+
Connection,
9+
Account,
10+
} from '@solana/web3.js';
511
import BN from 'bn.js';
612

713
// === client/token-swap.js ===
@@ -11,19 +17,24 @@ declare module '@solana/spl-token-swap' {
1117
}
1218

1319
export type TokenSwapInfo = {
14-
nonce: number,
15-
tokenAccountA: PublicKey,
16-
tokenAccountB: PublicKey,
17-
tokenPool: PublicKey,
18-
feesNumerator: Numberu64,
19-
feesDenominator: Numberu64,
20-
feeRatio: number,
20+
nonce: number;
21+
tokenAccountA: PublicKey;
22+
tokenAccountB: PublicKey;
23+
tokenPool: PublicKey;
24+
feesNumerator: Numberu64;
25+
feesDenominator: Numberu64;
26+
feeRatio: number;
2127
};
2228

2329
export const TokenSwapLayout: Layout;
2430

2531
export class TokenSwap {
26-
constructor(connection: Connection, tokenSwap: PublicKey, programId: PublicKey, payer: Account);
32+
constructor(
33+
connection: Connection,
34+
tokenSwap: PublicKey,
35+
programId: PublicKey,
36+
payer: Account,
37+
);
2738

2839
static getMinBalanceRentForExemptTokenSwap(
2940
connection: Connection,
@@ -40,7 +51,7 @@ declare module '@solana/spl-token-swap' {
4051
tokenProgramId: PublicKey,
4152
swapProgramId: PublicKey,
4253
feeNumerator: number,
43-
feeDenominator: number
54+
feeDenominator: number,
4455
): TransactionInstruction;
4556

4657
static createTokenSwap(
@@ -57,9 +68,9 @@ declare module '@solana/spl-token-swap' {
5768
feeNumerator: number,
5869
feeDenominator: number,
5970
swapProgramId: PublicKey,
60-
): Promise<TokenSwap>
71+
): Promise<TokenSwap>;
6172

62-
getInfo(): Promise<TokenSwapInfo>
73+
getInfo(): Promise<TokenSwapInfo>;
6374
swap(
6475
authority: PublicKey,
6576
source: PublicKey,
@@ -68,7 +79,7 @@ declare module '@solana/spl-token-swap' {
6879
destination: PublicKey,
6980
tokenProgramId: PublicKey,
7081
amount: number | Numberu64,
71-
): Promise<TransactionSignature>
82+
): Promise<TransactionSignature>;
7283

7384
static swapInstruction(
7485
tokenSwap: PublicKey,
@@ -80,7 +91,7 @@ declare module '@solana/spl-token-swap' {
8091
swapProgramId: PublicKey,
8192
tokenProgramId: PublicKey,
8293
amount: number | Numberu64,
83-
): TransactionInstruction
94+
): TransactionInstruction;
8495

8596
deposit(
8697
authority: PublicKey,
@@ -92,7 +103,7 @@ declare module '@solana/spl-token-swap' {
92103
poolAccount: PublicKey,
93104
tokenProgramId: PublicKey,
94105
amount: number | Numberu64,
95-
): Promise<TransactionSignature>
106+
): Promise<TransactionSignature>;
96107

97108
static depositInstruction(
98109
tokenSwap: PublicKey,
@@ -106,7 +117,7 @@ declare module '@solana/spl-token-swap' {
106117
swapProgramId: PublicKey,
107118
tokenProgramId: PublicKey,
108119
amount: number | Numberu64,
109-
): TransactionInstruction
120+
): TransactionInstruction;
110121

111122
withdraw(
112123
authority: PublicKey,
@@ -118,7 +129,7 @@ declare module '@solana/spl-token-swap' {
118129
userAccountB: PublicKey,
119130
tokenProgramId: PublicKey,
120131
amount: number | Numberu64,
121-
): Promise<TransactionSignature>
132+
): Promise<TransactionSignature>;
122133

123134
static withdrawInstruction(
124135
tokenSwap: PublicKey,
@@ -132,6 +143,6 @@ declare module '@solana/spl-token-swap' {
132143
swapProgramId: PublicKey,
133144
tokenProgramId: PublicKey,
134145
amount: number | Numberu64,
135-
): TransactionInstruction
146+
): TransactionInstruction;
136147
}
137148
}

token-swap/js/module.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare module '@solana/spl-token-swap' {
4747
tokenAccountPool: PublicKey,
4848
tokenProgramId: PublicKey,
4949
feeNumerator: number,
50-
feeDenominator: number
50+
feeDenominator: number,
5151
): TransactionInstruction;
5252

5353
static createTokenSwap(

token-swap/js/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token-swap/js/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"build": "rollup -c",
2828
"start": "babel-node --ignore node_modules cli/main.js",
2929
"lint": "npm run pretty && eslint .",
30-
"lint:fix": "npm run lint -- --fix",
30+
"lint:fix": "npm run pretty:fix && eslint . --fix",
3131
"flow": "flow",
3232
"flow:watch": "watch 'flow' . --wait=1 --ignoreDirectoryPattern=/doc/",
3333
"lint:watch": "watch 'npm run lint:fix' . --wait=1",
@@ -40,7 +40,8 @@
4040
"localnet:up": "rm client/util/store/config.json; set -x; solana-localnet down; set -e; solana-localnet up",
4141
"localnet:down": "solana-localnet down",
4242
"localnet:logs": "solana-localnet logs -f",
43-
"pretty": "prettier --write '{,cli*/**/}*.js'"
43+
"pretty": "prettier --check '{,cli*/**/}*.[jt]s'",
44+
"pretty:fix": "prettier --write '{,cli*/**/}*.[jt]s'"
4445
},
4546
"keywords": [],
4647
"dependencies": {
@@ -65,7 +66,7 @@
6566
"babel-eslint": "^10.1.0",
6667
"eslint": "^7.9.0",
6768
"eslint-plugin-import": "^2.22.0",
68-
"flow-bin": "0.131.0",
69+
"flow-bin": "0.134.0",
6970
"flow-typed": "^3.2.0",
7071
"mz": "^2.7.0",
7172
"prettier": "^2.1.2",

token/js/client/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const uint64 = (property: string = 'uint64'): Object => {
1919
/**
2020
* Layout for a Rust String type
2121
*/
22-
export const rustString = (property: string = 'string') => {
22+
export const rustString = (property: string = 'string'): Object => {
2323
const rsl = BufferLayout.struct(
2424
[
2525
BufferLayout.u32('length'),

0 commit comments

Comments
 (0)