Skip to content

Commit

Permalink
Fix Eslint and TypeScript errors in JS renderers (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva authored Mar 22, 2024
1 parent 29a43db commit 86e231f
Show file tree
Hide file tree
Showing 30 changed files with 1,240 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-socks-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@metaplex-foundation/kinobi": patch
---

Fix Eslint and TypeScript errors in JS renderers
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"build": "rimraf dist && tsc && tsc -p test/tsconfig.json && pnpm build:njk",
"build:njk": "copyfiles -u 1 src/**/*.njk dist/cjs/ && copyfiles -u 1 src/**/*.njk dist/test/src/",
"build:docs": "typedoc",
"test": "ava && node ./test/testFile.cjs",
"test": "ava && node ./test/testFile.cjs && pnpm test:js && pnpm test:js-experimental",
"test:js": "(cd ./test/packages/js && pnpm install && pnpm build)",
"test:js-experimental": "(cd ./test/packages/js-experimental && pnpm install && pnpm build && pnpm lint)",
"lint": "prettier -c ./src/ && eslint . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "prettier --write ./src && eslint . --ext .js,.jsx,.ts,.tsx",
"package:change": "changeset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export async function {{ fetchMaybeFromSeedsFunction }}(
): Promise<{{ accountMaybeType }}> {
const { programAddress, ...fetchConfig } = config;
const [address] = await {{ findPdaFunction }}({% if hasVariableSeeds %}seeds, {% endif %}{ programAddress });
return {{ fetchMaybeFunction }}(rpc, address, fetchConfig);
return await {{ fetchMaybeFunction }}(rpc, address, fetchConfig);
}
2 changes: 1 addition & 1 deletion src/renderers/js-experimental/fragments/pdaFunction.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function {{ findPdaFunction }}(
config: { programAddress?: Address | undefined } = {},
): Promise<ProgramDerivedAddress> {
const { programAddress = '{{ program.publicKey }}' as Address<'{{ program.publicKey }}'> } = config;
return getProgramDerivedAddress({ programAddress, seeds: [
return await getProgramDerivedAddress({ programAddress, seeds: [
{% for seed in seeds %}
{% if seed.kind === 'programIdPdaSeedNode' %}
getAddressEncoder().encode(programAddress),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
export function {{ dataEnumFunction }}(kind: '{{ getVariant(variant.name) }}'): GetDataEnumKind<{{ looseName }}, '{{ getVariant(variant.name) }}'>;
{% endif %}
{% endfor %}
export function {{ dataEnumFunction }}<K extends {{ looseName }}['{{ dataEnumDiscriminator }}']>(
export function {{ dataEnumFunction }}<K extends {{ looseName }}['{{ dataEnumDiscriminator }}'], Data>(
kind: K,
data?: any,
): Extract<{{ looseName }}, { {{ dataEnumDiscriminator }}: K }> {
data?: Data,
) {
return Array.isArray(data) ? { {{ dataEnumDiscriminator }}: kind, fields: data } : { {{ dataEnumDiscriminator }}: kind, ...(data ?? {}) };
}

Expand Down
6 changes: 5 additions & 1 deletion src/renderers/js/templates/instructionsPage.njk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export function {{ instruction.name | camelCase }}(
{% include "instructionsPageResolvedInputs.njk" %}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(resolvedAccounts).sort((a,b) => a.index - b.index);
{% if hasAccounts %}
const orderedAccounts: ResolvedAccount[] = Object.values(resolvedAccounts).sort((a,b) => a.index - b.index);
{% else %}
const orderedAccounts: ResolvedAccount[] = Object.values(resolvedAccounts as ResolvedAccountsWithIndices);
{% endif %}

{% include "instructionsPageRemainingAccounts.njk" %}

Expand Down
12 changes: 12 additions & 0 deletions test/packages/js-experimental/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: ['@solana/eslint-config-solana'],
rules: {
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'prefer-destructuring': 'off',
'simple-import-sort/imports': 'off',
'sort-keys-fix/sort-keys-fix': 'off',
'typescript-sort-keys/interface': 'off',
},
ignorePatterns: ['.eslintrc.js'],
};
6 changes: 4 additions & 2 deletions test/packages/js-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "",
"main": "src/index.ts",
"scripts": {
"build": "tsc"
"build": "tsc",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --no-eslintrc -c .eslintrc.js"
},
"keywords": [],
"author": "",
Expand All @@ -19,6 +20,7 @@
"@solana/signers": "2.0.0-experimental.a7a613a"
},
"devDependencies": {
"typescript": "^5.4.3"
"@solana/eslint-config-solana": "^3.0.3",
"typescript": "^5.3.0"
}
}
Loading

0 comments on commit 86e231f

Please sign in to comment.