diff --git a/basics/account-data/native/tests/test.ts b/basics/account-data/native/tests/test.ts index 0a3ac7438..791891a48 100644 --- a/basics/account-data/native/tests/test.ts +++ b/basics/account-data/native/tests/test.ts @@ -1,14 +1,20 @@ -import { Buffer } from 'node:buffer'; -import { describe, test } from 'node:test'; -import { Keypair, PublicKey, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'; -import * as borsh from 'borsh'; -import { start } from 'solana-bankrun'; +import { Buffer } from "node:buffer"; +import { describe, test } from "node:test"; +import { + Keypair, + PublicKey, + SystemProgram, + Transaction, + TransactionInstruction, +} from "@solana/web3.js"; +import * as borsh from "borsh"; +import { start } from "solana-bankrun"; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } @@ -29,24 +35,27 @@ const AddressInfoSchema = new Map([ [ AddressInfo, { - kind: 'struct', + kind: "struct", fields: [ - ['name', 'string'], - ['house_number', 'u8'], - ['street', 'string'], - ['city', 'string'], + ["name", "string"], + ["house_number", "u8"], + ["street", "string"], + ["city", "string"], ], }, ], ]); -describe('Account Data!', async () => { +describe("Account Data!", async () => { const addressInfoAccount = Keypair.generate(); const PROGRAM_ID = PublicKey.unique(); - const context = await start([{ name: 'account_data_program', programId: PROGRAM_ID }], []); + const context = await start( + [{ name: "account_data_program", programId: PROGRAM_ID }], + [] + ); const client = context.banksClient; - test('Create the address info account', async () => { + test("Create the address info account", async () => { const payer = context.payer; console.log(`Program Address : ${PROGRAM_ID}`); @@ -65,10 +74,10 @@ describe('Account Data!', async () => { ], programId: PROGRAM_ID, data: new AddressInfo({ - name: 'Joe C', + name: "Joe C", house_number: 136, - street: 'Mile High Dr.', - city: 'Solana Beach', + street: "Mile High Dr.", + city: "Solana Beach", }).toBuffer(), }); @@ -83,7 +92,9 @@ describe('Account Data!', async () => { test("Read the new account's data", async () => { const accountInfo = await client.getAccount(addressInfoAccount.publicKey); - const readAddressInfo = AddressInfo.fromBuffer(Buffer.from(accountInfo.data)); + const readAddressInfo = AddressInfo.fromBuffer( + Buffer.from(accountInfo.data) + ); console.log(`Name : ${readAddressInfo.name}`); console.log(`House Num: ${readAddressInfo.house_number}`); console.log(`Street : ${readAddressInfo.street}`); diff --git a/basics/counter/native/ts/instructions/createIncrementInstruction.ts b/basics/counter/native/ts/instructions/createIncrementInstruction.ts index 05d436144..fba22b246 100644 --- a/basics/counter/native/ts/instructions/createIncrementInstruction.ts +++ b/basics/counter/native/ts/instructions/createIncrementInstruction.ts @@ -4,9 +4,10 @@ import { PROGRAM_ID } from '../'; export type IncrementInstructionAccounts = { counter: PublicKey; }; -export type IncrementInstructionArgs = {}; -export function createIncrementInstruction(accounts: IncrementInstructionAccounts, args: IncrementInstructionArgs): TransactionInstruction { +export function createIncrementInstruction( + accounts: IncrementInstructionAccounts +): TransactionInstruction { return new TransactionInstruction({ programId: PROGRAM_ID, keys: [ diff --git a/basics/create-account/anchor/tests/test.ts b/basics/create-account/anchor/tests/test.ts index 6bc9800a9..b6ff674cb 100644 --- a/basics/create-account/anchor/tests/test.ts +++ b/basics/create-account/anchor/tests/test.ts @@ -28,7 +28,7 @@ describe('Create a system account', () => { // Check that the account was created const accountInfo = await connection.getAccountInfo(newKeypair.publicKey); - assert((accountInfo.owner = SystemProgram.programId)); + assert(accountInfo.owner === SystemProgram.programId); assert(accountInfo.lamports === lamports); }); }); diff --git a/basics/cross-program-invocation/native/tests/test.ts b/basics/cross-program-invocation/native/tests/test.ts index 0c9ccaeaf..f9e300f95 100644 --- a/basics/cross-program-invocation/native/tests/test.ts +++ b/basics/cross-program-invocation/native/tests/test.ts @@ -14,9 +14,9 @@ describe('CPI Example', () => { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/basics/favorites/anchor/favorites/.env b/basics/favorites/anchor/favorites/.env new file mode 100644 index 000000000..b846e0792 --- /dev/null +++ b/basics/favorites/anchor/favorites/.env @@ -0,0 +1,10 @@ +SECRET_KEY="[ + 128, 166, 168, 193, 245, 44, 59, 104, 191, 31, + 234, 44, 94, 240, 73, 226, 167, 218, 120, 123, + 100, 217, 143, 131, 240, 117, 3, 133, 104, 97, + 221, 192, 63, 247, 49, 204, 178, 219, 103, 184, + 240, 179, 100, 205, 229, 87, 193, 135, 159, 117, + 114, 238, 250, 53, 147, 116, 130, 199, 143, 120, + 62, 15, 23, 15 +]" +MINT_ACCOUNT=[12,30,154,17,31,70,145,100,167,126,88,76,254,107,186,122,219,36,215,214,217,160,183,84,215,35,56,161,192,39,160,112,243,82,181,22,133,180,38,99,209,98,105,87,51,115,31,180,29,64,36,237,175,202,124,200,38,110,27,63,103,215,1,189] \ No newline at end of file diff --git a/basics/pda-rent-payer/native/tests/test.ts b/basics/pda-rent-payer/native/tests/test.ts index ea18e184a..e6b5c102b 100644 --- a/basics/pda-rent-payer/native/tests/test.ts +++ b/basics/pda-rent-payer/native/tests/test.ts @@ -12,9 +12,9 @@ describe('PDA Rent-Payer', async () => { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/basics/processing-instructions/native/tests/test.ts b/basics/processing-instructions/native/tests/test.ts index 7d1c1de89..e8b80427a 100644 --- a/basics/processing-instructions/native/tests/test.ts +++ b/basics/processing-instructions/native/tests/test.ts @@ -12,9 +12,9 @@ describe('custom-instruction-data', async () => { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/basics/program-derived-addresses/native/tests/test.ts b/basics/program-derived-addresses/native/tests/test.ts index dfc43b636..78bc2e553 100644 --- a/basics/program-derived-addresses/native/tests/test.ts +++ b/basics/program-derived-addresses/native/tests/test.ts @@ -13,9 +13,9 @@ describe('PDAs', async () => { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/basics/rent/native/tests/test.ts b/basics/rent/native/tests/test.ts index 59e1fe151..b2a7fddec 100644 --- a/basics/rent/native/tests/test.ts +++ b/basics/rent/native/tests/test.ts @@ -12,9 +12,9 @@ describe('Create a system account', async () => { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/basics/repository-layout/native/tests/test.ts b/basics/repository-layout/native/tests/test.ts index d99b91be0..758a5c9ec 100644 --- a/basics/repository-layout/native/tests/test.ts +++ b/basics/repository-layout/native/tests/test.ts @@ -12,9 +12,9 @@ describe('Carnival', async () => { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/biome.json b/biome.json index 49ddd5545..2671cd2df 100644 --- a/biome.json +++ b/biome.json @@ -35,7 +35,7 @@ "formatter": { "jsxQuoteStyle": "double", "quoteProperties": "asNeeded", - "trailingComma": "all", + "trailingCommas": "all", "semicolons": "always", "arrowParentheses": "always", "bracketSpacing": true, diff --git a/compression/cnft-burn/anchor/tests/cnft-burn.ts b/compression/cnft-burn/anchor/tests/cnft-burn.ts index 45d116671..2d43a3188 100644 --- a/compression/cnft-burn/anchor/tests/cnft-burn.ts +++ b/compression/cnft-burn/anchor/tests/cnft-burn.ts @@ -9,7 +9,7 @@ import { getAsset, getAssetProof } from './readApi'; import { decode, mapProof } from './utils'; // Replace this with your custom RPC endpoint that supports cNFT indexing -export const RPC_PATH = 'https://api.devnet.solana.com'; +const RPC_PATH = 'https://api.devnet.solana.com'; describe('cnft-burn', () => { // Configure the client to use the local cluster. diff --git a/compression/cnft-burn/anchor/tests/utils/helpers.ts b/compression/cnft-burn/anchor/tests/utils/helpers.ts index 0075cfe8f..86e64995f 100644 --- a/compression/cnft-burn/anchor/tests/utils/helpers.ts +++ b/compression/cnft-burn/anchor/tests/utils/helpers.ts @@ -9,6 +9,7 @@ const DEFAULT_DEMO_DATA_FILE = 'demo.json'; /* Load locally stored PublicKey addresses + TODO: use the helpers library and delete this function */ export function loadPublicKeysFromFile(absPath = `${DEFAULT_KEY_DIR_NAME}/${DEFAULT_PUBLIC_KEY_FILE}`) { try { @@ -25,7 +26,7 @@ export function loadPublicKeysFromFile(absPath = `${DEFAULT_KEY_DIR_NAME}/${DEFA return data; } catch (err) { - // console.warn("Unable to load local file"); + console.warn("Unable to load local file"); } // always return an object return {}; @@ -51,7 +52,7 @@ export function saveDemoDataToFile(name: string, newData: any, absPath = `${DEFA return data; } catch (err) { console.warn('Unable to save to file'); - // console.warn(err); + console.warn(err); } // always return an object @@ -105,16 +106,17 @@ export function loadKeypairFromFile(absPath: string) { const keypair = Keypair.fromSecretKey(new Uint8Array(keyfileBytes)); return keypair; } catch (err) { - // return false; + console.error('loadKeypairFromFile:', err); throw err; } } /* Save a locally stored JSON keypair file for later importing + TODO: delete this function and use the helpers library */ -export function saveKeypairToFile(keypair: Keypair, fileName: string, dirName: string = DEFAULT_KEY_DIR_NAME) { - fileName = path.join(dirName, `${fileName}.json`); +export function saveKeypairToFile(keypair: Keypair, relativeFileName: string, dirName: string = DEFAULT_KEY_DIR_NAME) { + const fileName = path.join(dirName, `${relativeFileName}.json`); // create the `dirName` directory, if it does not exists if (!fs.existsSync(`./${dirName}/`)) fs.mkdirSync(`./${dirName}/`); diff --git a/compression/cutils/anchor/tests/utils/helpers.ts b/compression/cutils/anchor/tests/utils/helpers.ts index 0075cfe8f..75ea37208 100644 --- a/compression/cutils/anchor/tests/utils/helpers.ts +++ b/compression/cutils/anchor/tests/utils/helpers.ts @@ -105,16 +105,17 @@ export function loadKeypairFromFile(absPath: string) { const keypair = Keypair.fromSecretKey(new Uint8Array(keyfileBytes)); return keypair; } catch (err) { - // return false; + console.error('loadKeypairFromFile:', err); throw err; } } /* Save a locally stored JSON keypair file for later importing + TODO: delete this function and use the helpers library */ -export function saveKeypairToFile(keypair: Keypair, fileName: string, dirName: string = DEFAULT_KEY_DIR_NAME) { - fileName = path.join(dirName, `${fileName}.json`); +export function saveKeypairToFile(keypair: Keypair, relativeFileName: string, dirName: string = DEFAULT_KEY_DIR_NAME) { + const fileName = path.join(dirName, `${relativeFileName}.json`); // create the `dirName` directory, if it does not exists if (!fs.existsSync(`./${dirName}/`)) fs.mkdirSync(`./${dirName}/`); diff --git a/deleteme.log b/deleteme.log new file mode 100644 index 000000000..ccdb22530 --- /dev/null +++ b/deleteme.log @@ -0,0 +1,92 @@ + +> program-examples@1.0.0 lint +> pnpx @biomejs/biome lint ./ + +Progress: resolved 1, reused 0, downloaded 0, added 0 +Packages: +2 +++ +Progress: resolved 9, reused 2, downloaded 0, added 2, done +./basics/rent/native/tests/test.ts:16:17 lint/suspicious/noAssignInExpressions ━━━━━━━━━━━━━━━━━━━━━ + + ! The assignment should not be in an expression. + + 14 │ constructor(properties) { + 15 │ Object.keys(properties).map((key) => { + > 16 │ return (this[key] = properties[key]); + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 │ }); + 18 │ } + + i The use of assignments in expressions is confusing. + Expressions are often considered as side-effect free. + + +./basics/program-derived-addresses/native/tests/test.ts:17:17 lint/suspicious/noAssignInExpressions ━━━━━━━━━━ + + ! The assignment should not be in an expression. + + 15 │ constructor(properties) { + 16 │ Object.keys(properties).map((key) => { + > 17 │ return (this[key] = properties[key]); + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 18 │ }); + 19 │ } + + i The use of assignments in expressions is confusing. + Expressions are often considered as side-effect free. + + +./basics/repository-layout/native/tests/test.ts:16:17 lint/suspicious/noAssignInExpressions ━━━━━━━━━━ + + ! The assignment should not be in an expression. + + 14 │ constructor(properties) { + 15 │ Object.keys(properties).map((key) => { + > 16 │ return (this[key] = properties[key]); + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 17 │ }); + 18 │ } + + i The use of assignments in expressions is confusing. + Expressions are often considered as side-effect free. + + +./basics/counter/native/ts/instructions/createIncrementInstruction.ts:7:40 lint/complexity/noBannedTypes ━━━━━━━━━━ + + ! Don't use '{}' as a type. + + 5 │ counter: PublicKey; + 6 │ }; + > 7 │ export type IncrementInstructionArgs = {}; + │ ^^ + 8 │ + 9 │ export function createIncrementInstruction(accounts: IncrementInstructionAccounts, args: IncrementInstructionArgs): TransactionInstruction { + + i Prefer explicitly define the object shape. '{}' means "any non-nullable value". + + +./tokens/token-2022/nft-meta-data-pointer/anchor-example/app/utils/wrappedConnection.ts:128:9 lint/style/noParameterAssign ━━━━━━━━━━ + + ! Reassigning a function parameter is confusing. + + 126 │ console.log(`Requested page${page}`); + 127 │ + > 128 │ page += 1; + │ ^^^^ + 129 │ response = await axios.post(process.env.NEXT_PUBLIC_RPC ? process.env.NEXT_PUBLIC_RPC : METAPLEX_READAPI, { + 130 │ jsonrpc: '2.0', + + i The parameter is declared here: + + 108 │ sortBy: any, + 109 │ limit: number, + > 110 │ page: number, + │ ^^^^^^^^^^^^ + 111 │ before: string, + 112 │ after: string, + + i Use a local variable instead. + + +Checked 7251 files in 409ms. No fixes needed. +Found 5 warnings. diff --git a/scripts/lib/get-recursive-file-list.ts b/scripts/lib/get-recursive-file-list.ts index 223598d2c..8c65fbea1 100644 --- a/scripts/lib/get-recursive-file-list.ts +++ b/scripts/lib/get-recursive-file-list.ts @@ -6,20 +6,20 @@ export function getRecursiveFileList(path: string): string[] { const files: string[] = []; const items = readdirSync(path); - items.forEach((item) => { - if (ignore.includes(item)) { - return; - } - // Check out if it's a directory or a file - const isDir = statSync(`${path}/${item}`).isDirectory(); - if (isDir) { - // If it's a directory, recursively call the method - files.push(...getRecursiveFileList(`${path}/${item}`)); - } else { - // If it's a file, add it to the array of files - files.push(`${path}/${item}`); + + for (const item of items) { + if (!ignore.includes(item)) { + // Check out if it's a directory or a file + const isDir = statSync(`${path}/${item}`).isDirectory(); + if (isDir) { + // If it's a directory, recursively call the method + files.push(...getRecursiveFileList(`${path}/${item}`)); + } else { + // If it's a file, add it to the array of files + files.push(`${path}/${item}`); + } } - }); + } return files.filter((file) => { // Remove package.json from the root directory diff --git a/tokens/create-token/native/tests/test.ts b/tokens/create-token/native/tests/test.ts index 47ccdeb00..e842cab2b 100644 --- a/tokens/create-token/native/tests/test.ts +++ b/tokens/create-token/native/tests/test.ts @@ -19,9 +19,9 @@ function createKeypairFromFile(path: string): Keypair { class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/nft-minter/native/tests/instructions.ts b/tokens/nft-minter/native/tests/instructions.ts index 88c738030..39ccae97b 100644 --- a/tokens/nft-minter/native/tests/instructions.ts +++ b/tokens/nft-minter/native/tests/instructions.ts @@ -2,9 +2,9 @@ import * as borsh from 'borsh'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/pda-mint-authority/native/tests/instructions.ts b/tokens/pda-mint-authority/native/tests/instructions.ts index b422ad1f6..00871d08d 100644 --- a/tokens/pda-mint-authority/native/tests/instructions.ts +++ b/tokens/pda-mint-authority/native/tests/instructions.ts @@ -2,9 +2,9 @@ import * as borsh from 'borsh'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/spl-token-minter/native/tests/instructions.ts b/tokens/spl-token-minter/native/tests/instructions.ts index 8af727c70..03479b679 100644 --- a/tokens/spl-token-minter/native/tests/instructions.ts +++ b/tokens/spl-token-minter/native/tests/instructions.ts @@ -2,9 +2,9 @@ import * as borsh from 'borsh'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/token-2022/default-account-state/native/tests/test.ts b/tokens/token-2022/default-account-state/native/tests/test.ts index f6abc2658..25a154bf3 100644 --- a/tokens/token-2022/default-account-state/native/tests/test.ts +++ b/tokens/token-2022/default-account-state/native/tests/test.ts @@ -16,9 +16,9 @@ import { start } from 'solana-bankrun'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/token-2022/mint-close-authority/native/tests/test.ts b/tokens/token-2022/mint-close-authority/native/tests/test.ts index 0a210ffe6..fd16b9635 100644 --- a/tokens/token-2022/mint-close-authority/native/tests/test.ts +++ b/tokens/token-2022/mint-close-authority/native/tests/test.ts @@ -8,9 +8,9 @@ import { start } from 'solana-bankrun'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/token-2022/multiple-extensions/native/tests/test.ts b/tokens/token-2022/multiple-extensions/native/tests/test.ts index 0b2699233..c73deed04 100644 --- a/tokens/token-2022/multiple-extensions/native/tests/test.ts +++ b/tokens/token-2022/multiple-extensions/native/tests/test.ts @@ -8,9 +8,9 @@ import { start } from 'solana-bankrun'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/token-2022/nft-meta-data-pointer/anchor-example/app/utils/wrappedConnection.ts b/tokens/token-2022/nft-meta-data-pointer/anchor-example/app/utils/wrappedConnection.ts index ffe891c4b..db48070ba 100644 --- a/tokens/token-2022/nft-meta-data-pointer/anchor-example/app/utils/wrappedConnection.ts +++ b/tokens/token-2022/nft-meta-data-pointer/anchor-example/app/utils/wrappedConnection.ts @@ -101,16 +101,17 @@ export class WrappedConnection extends Connection { } } - // This will loop through all pages and return all assets + // Loop through all pages and return all assets async getAllAssetsByGroup( groupKey: string, groupValue: string, sortBy: any, limit: number, - page: number, + startPage: number, before: string, - after: string, + after: string ): Promise { + let page = startPage; try { const events = []; let response = await axios.post(process.env.NEXT_PUBLIC_RPC ? process.env.NEXT_PUBLIC_RPC : METAPLEX_READAPI, { diff --git a/tokens/token-2022/non-transferable/native/tests/test.ts b/tokens/token-2022/non-transferable/native/tests/test.ts index 020d9fcee..b2ca6aa53 100644 --- a/tokens/token-2022/non-transferable/native/tests/test.ts +++ b/tokens/token-2022/non-transferable/native/tests/test.ts @@ -8,9 +8,9 @@ import { start } from 'solana-bankrun'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/token-2022/transfer-fee/native/tests/test.ts b/tokens/token-2022/transfer-fee/native/tests/test.ts index d150f9f12..566dd98e3 100644 --- a/tokens/token-2022/transfer-fee/native/tests/test.ts +++ b/tokens/token-2022/transfer-fee/native/tests/test.ts @@ -8,9 +8,9 @@ import { start } from 'solana-bankrun'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } } diff --git a/tokens/transfer-tokens/native/tests/instructions.ts b/tokens/transfer-tokens/native/tests/instructions.ts index f433aadcd..67769eed1 100644 --- a/tokens/transfer-tokens/native/tests/instructions.ts +++ b/tokens/transfer-tokens/native/tests/instructions.ts @@ -2,9 +2,9 @@ import * as borsh from 'borsh'; class Assignable { constructor(properties) { - Object.keys(properties).map((key) => { - return (this[key] = properties[key]); - }); + for (const [key, value] of Object.entries(properties)) { + this[key] = value; + } } }