Skip to content

Commit 1cc16ec

Browse files
committed
apply prettier on the js client
1 parent 6c849d8 commit 1cc16ec

File tree

8 files changed

+72
-45
lines changed

8 files changed

+72
-45
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ clippy-%:
4040
--deny=clippy::manual_let_else \
4141
--deny=clippy::used_underscore_binding $(ARGS)
4242

43+
format-check-js-%:
44+
cd $(call make-path,$*) && pnpm install && pnpm format $(ARGS)
45+
4346
format-check-%:
4447
cargo $(nightly) fmt --check --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
4548

@@ -81,9 +84,6 @@ test-js-%:
8184
test-%:
8285
SBF_OUT_DIR=$(PWD)/target/deploy cargo $(nightly) test --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
8386

84-
format-check-js-%:
85-
cd $(call make-path,$*) && pnpm install && pnpm format $(ARGS)
86-
8787
lint-js-%:
8888
cd $(call make-path,$*) && pnpm install && pnpm lint $(ARGS)
8989

clients/js/.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
extends: ["@solana/eslint-config-solana"],
3+
ignorePatterns: [".eslintrc.cjs", "tsup.config.ts", "env-shim.ts"],
4+
parserOptions: {
5+
project: "tsconfig.json",
6+
tsconfigRootDir: __dirname,
7+
sourceType: "module",
8+
},
9+
rules: {
10+
"@typescript-eslint/ban-types": "off",
11+
"@typescript-eslint/sort-type-constituents": "off",
12+
"prefer-destructuring": "off",
13+
"simple-import-sort/imports": "off",
14+
"sort-keys-fix/sort-keys-fix": "off",
15+
"typescript-sort-keys/interface": "off",
16+
},
17+
};

clients/js/.prettierrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"useTabs": false,
6+
"tabWidth": 2,
7+
"arrowParens": "always",
8+
"printWidth": 80
9+
}
10+

clients/js/src/actions.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import {
77
KeyPairSigner,
88
Rpc,
99
TransactionSigner,
10-
} from "@solana/kit";
10+
} from '@solana/kit';
1111
import {
1212
getCreateAccountInstruction,
1313
getTransferSolInstruction,
14-
} from "@solana-program/system";
14+
} from '@solana-program/system';
1515
import {
1616
getCloseAccountInstruction,
1717
getInitializeInstruction,
1818
getReallocateInstruction,
1919
getSetAuthorityInstruction,
2020
getWriteInstruction,
2121
SPL_RECORD_PROGRAM_ADDRESS,
22-
} from "./generated";
23-
import { RECORD_META_DATA_SIZE } from "./constants";
22+
} from './generated';
23+
import { RECORD_META_DATA_SIZE } from './constants';
2424

2525
export interface CreateRecordArgs {
2626
rpc: Rpc<GetMinimumBalanceForRentExemptionApi>;
@@ -66,7 +66,7 @@ export async function createRecord({
6666
recordAccount: recordSigner.address,
6767
authority,
6868
},
69-
{ programAddress: programId },
69+
{ programAddress: programId }
7070
);
7171

7272
return {
@@ -95,7 +95,7 @@ export function createWriteInstruction(args: WriteRecordArgs): Instruction {
9595
offset: BigInt(args.offset),
9696
data: args.data,
9797
},
98-
{ programAddress: args.programId },
98+
{ programAddress: args.programId }
9999
);
100100
}
101101

@@ -134,7 +134,7 @@ export async function reallocateRecord({
134134
source: payer,
135135
destination: recordAccount,
136136
amount: lamportsNeeded,
137-
}),
137+
})
138138
);
139139
}
140140

@@ -145,8 +145,8 @@ export async function reallocateRecord({
145145
authority,
146146
dataLength: BigInt(newDataLength),
147147
},
148-
{ programAddress: programId },
149-
),
148+
{ programAddress: programId }
149+
)
150150
);
151151

152152
return ixs;
@@ -160,15 +160,15 @@ export interface SetAuthorityArgs {
160160
}
161161

162162
export function createSetAuthorityInstruction(
163-
args: SetAuthorityArgs,
163+
args: SetAuthorityArgs
164164
): Instruction {
165165
return getSetAuthorityInstruction(
166166
{
167167
recordAccount: args.recordAccount,
168168
authority: args.authority,
169169
newAuthority: args.newAuthority,
170170
},
171-
{ programAddress: args.programId },
171+
{ programAddress: args.programId }
172172
);
173173
}
174174

@@ -180,14 +180,14 @@ export interface CloseRecordArgs {
180180
}
181181

182182
export function createCloseRecordInstruction(
183-
args: CloseRecordArgs,
183+
args: CloseRecordArgs
184184
): Instruction {
185185
return getCloseAccountInstruction(
186186
{
187187
recordAccount: args.recordAccount,
188188
authority: args.authority,
189189
receiver: args.receiver,
190190
},
191-
{ programAddress: args.programId },
191+
{ programAddress: args.programId }
192192
);
193193
}

clients/js/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from "./constants";
2-
export * from "./generated";
3-
export * from "./actions";
1+
export * from './constants';
2+
export * from './generated';
3+
export * from './actions';

clients/js/test/_setup.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,43 @@ import {
2323
setTransactionMessageFeePayerSigner,
2424
setTransactionMessageLifetimeUsingBlockhash,
2525
signTransactionMessageWithSigners,
26-
} from "@solana/kit";
26+
} from '@solana/kit';
2727

2828
export type Client = {
2929
rpc: Rpc<SolanaRpcApi>;
3030
rpcSubscriptions: RpcSubscriptions<SolanaRpcSubscriptionsApi>;
3131
};
3232

3333
export const createDefaultSolanaClient = (): Client => {
34-
const rpc = createSolanaRpc("http://127.0.0.1:8899");
35-
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://127.0.0.1:8900");
34+
const rpc = createSolanaRpc('http://127.0.0.1:8899');
35+
const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');
3636
return { rpc, rpcSubscriptions };
3737
};
3838

3939
export const generateKeyPairSignerWithSol = async (
4040
client: Client,
41-
putativeLamports: bigint = 1_000_000_000n,
41+
putativeLamports: bigint = 1_000_000_000n
4242
) => {
4343
const signer = await generateKeyPairSigner();
4444
await airdropFactory(client)({
4545
recipientAddress: signer.address,
4646
lamports: lamports(putativeLamports),
47-
commitment: "confirmed",
47+
commitment: 'confirmed',
4848
});
4949
return signer;
5050
};
5151

5252
export const createDefaultTransaction = async (
5353
client: Client,
54-
feePayer: TransactionSigner,
54+
feePayer: TransactionSigner
5555
) => {
5656
const { value: latestBlockhash } = await client.rpc
5757
.getLatestBlockhash()
5858
.send();
5959
return pipe(
6060
createTransactionMessage({ version: 0 }),
6161
(tx) => setTransactionMessageFeePayerSigner(feePayer, tx),
62-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
62+
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
6363
);
6464
};
6565

@@ -68,7 +68,7 @@ export const signAndSendTransaction = async (
6868
transactionMessage: BaseTransactionMessage &
6969
TransactionMessageWithFeePayer &
7070
TransactionMessageWithBlockhashLifetime,
71-
commitment: Commitment = "confirmed",
71+
commitment: Commitment = 'confirmed'
7272
) => {
7373
const signedTransaction =
7474
await signTransactionMessageWithSigners(transactionMessage);
@@ -83,12 +83,12 @@ export const signAndSendTransaction = async (
8383
export const sendAndConfirmInstructions = async (
8484
client: Client,
8585
payer: TransactionSigner,
86-
instructions: Instruction[],
86+
instructions: Instruction[]
8787
) => {
8888
const signature = await pipe(
8989
await createDefaultTransaction(client, payer),
9090
(tx) => appendTransactionMessageInstructions(instructions, tx),
91-
(tx) => signAndSendTransaction(client, tx),
91+
(tx) => signAndSendTransaction(client, tx)
9292
);
9393
return signature;
9494
};

clients/js/test/basic.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from "ava";
2-
import { generateKeyPairSigner } from "@solana/kit";
1+
import test from 'ava';
2+
import { generateKeyPairSigner } from '@solana/kit';
33
import {
44
fetchRecordData,
55
createRecord,
@@ -8,14 +8,14 @@ import {
88
createSetAuthorityInstruction,
99
createCloseRecordInstruction,
1010
RECORD_META_DATA_SIZE,
11-
} from "../src";
11+
} from '../src';
1212
import {
1313
createDefaultSolanaClient,
1414
generateKeyPairSignerWithSol,
1515
sendAndConfirmInstructions,
16-
} from "./_setup";
16+
} from './_setup';
1717

18-
test("basic instructions flow", async (t) => {
18+
test('basic instructions flow', async (t) => {
1919
const client = createDefaultSolanaClient();
2020
const payer = await generateKeyPairSignerWithSol(client);
2121

@@ -54,13 +54,13 @@ test("basic instructions flow", async (t) => {
5454

5555
// Verify Reallocate
5656
let rawAccount = await client.rpc
57-
.getAccountInfo(recordAccount.address, { encoding: "base64" })
57+
.getAccountInfo(recordAccount.address, { encoding: 'base64' })
5858
.send();
5959
// Ensure RECORD_META_DATA_SIZE is defined (it is 33n), convert to Number for subarray
6060
const offset = Number(RECORD_META_DATA_SIZE);
6161

6262
let actualData = rawAccount.value?.data?.[0]
63-
? Buffer.from(rawAccount.value.data[0], "base64").subarray(offset)
63+
? Buffer.from(rawAccount.value.data[0], 'base64').subarray(offset)
6464
: new Uint8Array([]);
6565

6666
t.deepEqual(actualData, Buffer.from([0, 0, 0, 0, 0]));
@@ -77,10 +77,10 @@ test("basic instructions flow", async (t) => {
7777

7878
// Verify Write
7979
rawAccount = await client.rpc
80-
.getAccountInfo(recordAccount.address, { encoding: "base64" })
80+
.getAccountInfo(recordAccount.address, { encoding: 'base64' })
8181
.send();
8282
actualData = rawAccount.value?.data?.[0]
83-
? Buffer.from(rawAccount.value.data[0], "base64").subarray(offset)
83+
? Buffer.from(rawAccount.value.data[0], 'base64').subarray(offset)
8484
: new Uint8Array([]);
8585
t.deepEqual(actualData, Buffer.from([0, 1, 2, 3, 4]));
8686

clients/js/test/longRecord.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import test from "ava";
2-
import { generateKeyPairSigner } from "@solana/kit";
1+
import test from 'ava';
2+
import { generateKeyPairSigner } from '@solana/kit';
33
import {
44
createRecord,
55
createWriteInstruction,
66
RECORD_META_DATA_SIZE,
77
RECORD_CHUNK_SIZE_PRE_INITIALIZE,
88
RECORD_CHUNK_SIZE_POST_INITIALIZE,
9-
} from "../src";
9+
} from '../src';
1010
import {
1111
createDefaultSolanaClient,
1212
generateKeyPairSignerWithSol,
1313
sendAndConfirmInstructions,
14-
} from "./_setup";
14+
} from './_setup';
1515

16-
test("long record data flow", async (t) => {
16+
test('long record data flow', async (t) => {
1717
const client = createDefaultSolanaClient();
1818
const payer = await generateKeyPairSignerWithSol(client);
1919
const recordAuthority = await generateKeyPairSigner();
@@ -67,12 +67,12 @@ test("long record data flow", async (t) => {
6767

6868
// 3. Verify Data
6969
const rawAccount = await client.rpc
70-
.getAccountInfo(recordAccount.address, { encoding: "base64" })
70+
.getAccountInfo(recordAccount.address, { encoding: 'base64' })
7171
.send();
7272

7373
const headerSize = Number(RECORD_META_DATA_SIZE);
7474
const actualData = rawAccount.value?.data?.[0]
75-
? Buffer.from(rawAccount.value.data[0], "base64").subarray(headerSize)
75+
? Buffer.from(rawAccount.value.data[0], 'base64').subarray(headerSize)
7676
: new Uint8Array([]);
7777

7878
t.deepEqual(actualData, Buffer.from(recordData));

0 commit comments

Comments
 (0)