Skip to content

Commit f87dfc2

Browse files
committed
fix lint
1 parent 0d3b0f7 commit f87dfc2

File tree

15 files changed

+166
-102
lines changed

15 files changed

+166
-102
lines changed

CLAUDE.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ coda/
6969
## Core Packages
7070

7171
### 1. **@macalinao/coda** - CLI for client generation
72-
- Zero-config by default (looks for `./target/idl/program.json`)
72+
- Zero-config by default (looks for `./idls/*.json`)
7373
- Configurable via `coda.config.mjs`
7474
- Generates TypeScript clients with full type safety
7575
- Built on Codama for extensibility
76+
- Supports glob patterns for IDL discovery
7677

7778
### 2. **@macalinao/codama-instruction-accounts-dedupe-visitor**
7879
- Flattens nested account structures from Anchor IDL
@@ -100,6 +101,12 @@ coda/
100101

101102
## Configuration (coda.config.mjs)
102103

104+
### Default Configuration
105+
Coda automatically discovers IDLs without any configuration:
106+
- Looks for `./idls/*.json` by default
107+
- Place your IDL files in the `idls/` directory
108+
- No config file needed for basic usage!
109+
103110
### Single IDL Configuration
104111
For projects with a single program (like [token-metadata](https://github.com/macalinao/coda/tree/master/clients/token-metadata)):
105112

@@ -121,22 +128,15 @@ export default defineConfig({
121128
});
122129
```
123130

124-
### Multiple IDL Configuration
131+
### Multiple IDL Configuration with Glob Pattern
125132
For projects with multiple programs (like [quarry](https://github.com/macalinao/coda/tree/master/clients/quarry)):
126133

127134
```javascript
128135
import { defineConfig } from "@macalinao/coda";
129136

130137
export default defineConfig({
131-
// Array of IDL paths for multiple programs
132-
idlPath: [
133-
"./idls/quarry_mine.json",
134-
"./idls/quarry_mint_wrapper.json",
135-
"./idls/quarry_operator.json",
136-
"./idls/quarry_merge_mine.json",
137-
"./idls/quarry_redeemer.json",
138-
"./idls/quarry_registry.json",
139-
],
138+
// Use glob pattern to match all IDLs
139+
idlPath: "./idls/*.json",
140140
outputDir: "./src/generated",
141141

142142
// Optional: Add PDAs and other visitors for each program
@@ -146,6 +146,38 @@ export default defineConfig({
146146
});
147147
```
148148

149+
### Multiple IDL Configuration with Array
150+
You can also explicitly list IDL files:
151+
152+
```javascript
153+
import { defineConfig } from "@macalinao/coda";
154+
155+
export default defineConfig({
156+
// Array of specific IDL paths
157+
idlPath: [
158+
"./idls/program1.json",
159+
"./idls/program2.json",
160+
"./custom/path/program3.json",
161+
],
162+
outputDir: "./src/generated",
163+
});
164+
```
165+
166+
### Advanced Glob Patterns
167+
Use specific patterns to match only certain IDLs:
168+
169+
```javascript
170+
import { defineConfig } from "@macalinao/coda";
171+
172+
export default defineConfig({
173+
// Match only IDLs starting with "quarry_"
174+
idlPath: "./idls/quarry_*.json",
175+
// Or combine multiple patterns
176+
// idlPath: ["./idls/quarry_*.json", "./extra/*.json"],
177+
outputDir: "./src/generated",
178+
});
179+
```
180+
149181
## Code Style Guidelines
150182

151183
### TypeScript

biome.json renamed to biome.jsonc

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
"defaultBranch": "master"
88
},
99
"files": {
10-
"ignoreUnknown": false
10+
"ignoreUnknown": false,
11+
"includes": [
12+
"**",
13+
"!docs/.next",
14+
"!out",
15+
"!**/bun.lock",
16+
"!apps/example-dapp/src/routeTree.gen.ts"
17+
]
1118
},
1219
"formatter": {
1320
"enabled": true,
@@ -18,23 +25,19 @@
1825
"lineEnding": "lf",
1926
"lineWidth": 80,
2027
"attributePosition": "auto",
21-
"bracketSpacing": true,
22-
"includes": [
23-
"**",
24-
"!**/bun.lock",
25-
"!apps/example-dapp/src/routeTree.gen.ts"
26-
]
28+
"bracketSpacing": true
2729
},
2830
"linter": {
2931
"enabled": true,
30-
"domains": {
31-
"project": "recommended"
32-
},
32+
// "domains": {
33+
// "project": "recommended"
34+
// },
3335
"rules": {
3436
"recommended": true,
35-
"nursery": {
36-
"noFloatingPromises": "error"
37-
},
37+
// this thing lags super hard
38+
// "nursery": {
39+
// "noFloatingPromises": "error"
40+
// },
3841
"complexity": {
3942
"useSimplifiedLogicExpression": "error"
4043
},
@@ -69,24 +72,14 @@
6972
"noUnusedVariables": "warn",
7073
"noUnusedImports": "error"
7174
}
72-
},
73-
"includes": [
74-
"**",
75-
"!**/bun.lock",
76-
"!apps/example-dapp/src/routeTree.gen.ts"
77-
]
75+
}
7876
},
7977
"assist": {
8078
"actions": {
8179
"source": {
8280
"organizeImports": "on"
8381
}
84-
},
85-
"includes": [
86-
"**",
87-
"!**/bun.lock",
88-
"!apps/example-dapp/src/routeTree.gen.ts"
89-
]
82+
}
9083
},
9184
"javascript": {
9285
"formatter": {

bun.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@macalinao/codama-renderers-js-esm": "workspace:*",
8888
"codama": "*",
8989
"commander": "^14.0.0",
90+
"glob": "^11.0.3",
9091
},
9192
"devDependencies": {
9293
"@macalinao/eslint-config": "catalog:",

clients/quarry/coda.config.mjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ import {
88
import { renameVisitor } from "@macalinao/codama-rename-visitor";
99

1010
export default defineConfig({
11-
// Load all Quarry IDLs
12-
idlPath: [
13-
"./idls/quarry_mine.json",
14-
"./idls/quarry_mint_wrapper.json",
15-
"./idls/quarry_operator.json",
16-
"./idls/quarry_merge_mine.json",
17-
"./idls/quarry_redeemer.json",
18-
"./idls/quarry_registry.json",
19-
],
2011
outputDir: "./src/generated",
2112

2213
visitors: [

clients/token-metadata/coda.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const addCustomPDAsVisitor = addPdasVisitor({
2828
});
2929

3030
export default defineConfig({
31-
idlPath: "./idls/token_metadata.json",
3231
outputDir: "./src/generated",
3332
visitors: [addCustomPDAsVisitor],
3433
});

docs/content/docs/index.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Generate your first client:
2424

2525
```bash
2626
# From default Anchor build location (./target/idl/program.json)
27-
bunx @macalinao/coda generate
27+
coda generate
2828

2929
# From custom IDL location
30-
bunx @macalinao/coda generate --idl ./idls/my_program.json
30+
coda generate --idl ./idls/my_program.json
3131

3232
# Initialize a configuration file
33-
bunx @macalinao/coda init
33+
coda init
3434
```
3535

3636
## How It Works
@@ -44,6 +44,7 @@ bunx @macalinao/coda init
4444
## Generated Client Structure
4545

4646
The generated client provides:
47+
4748
- **Instructions**: Typed builders for all program instructions
4849
- **Accounts**: Decoders and fetchers for all account types
4950
- **Types**: All TypeScript types from the IDL
@@ -62,12 +63,12 @@ const instruction = createTransferInstruction({
6263
source: sourceAddress,
6364
destination: destAddress,
6465
authority: authorityAddress,
65-
amount: 1000n
66+
amount: 1000n,
6667
});
6768
```
6869

6970
## Next Steps
7071

7172
- [Installation](/docs/installation) - Different ways to install Coda
7273
- [Configuration](/docs/configuration) - Customize generation with `coda.config.mjs`
73-
- [API Reference](/docs/api) - Explore pre-built client libraries
74+
- [API Reference](/docs/api) - Explore pre-built client libraries

docs/scripts/generate-api-docs.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bun
22

3-
import fs from "fs/promises";
4-
import path from "path";
5-
import { fileURLToPath } from "url";
3+
import fs from "node:fs/promises";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
66
import yaml from "yaml";
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -20,7 +20,7 @@ interface PackageInfo {
2020
async function ensureDir(dir: string): Promise<void> {
2121
try {
2222
await fs.mkdir(dir, { recursive: true });
23-
} catch (e) {
23+
} catch (_e) {
2424
// Directory exists
2525
}
2626
}
@@ -40,15 +40,15 @@ async function getClientPackages(): Promise<PackageInfo[]> {
4040
description: pkg.description || "",
4141
version: pkg.version,
4242
});
43-
} catch (e) {
43+
} catch (_e) {
4444
// Not a package directory
4545
}
4646
}
4747

4848
return packages;
4949
}
5050

51-
function createFrontmatter(data: Record<string, any>): string {
51+
function createFrontmatter(data: Record<string, unknown>): string {
5252
return `---\n${yaml.stringify(data).trim()}\n---`;
5353
}
5454

@@ -74,7 +74,7 @@ ${pkg.description}
7474
7575
- Version: ${pkg.version}
7676
- [View Documentation](./${pkg.dir})
77-
`
77+
`,
7878
)
7979
.join("\n")}
8080
@@ -145,30 +145,30 @@ import { /* exports */ } from "${pkg.name}";
145145
"programs",
146146
];
147147

148-
for (const module of modules) {
149-
const moduleDir = path.join(srcDir, module);
150-
const moduleOutDir = path.join(outDir, module);
148+
for (const m of modules) {
149+
const moduleDir = path.join(srcDir, m);
150+
const moduleOutDir = path.join(outDir, m);
151151

152152
try {
153153
const files = await fs.readdir(moduleDir);
154154
const tsFiles = files.filter(
155-
(f) => f.endsWith(".ts") && f !== "index.ts"
155+
(f) => f.endsWith(".ts") && f !== "index.ts",
156156
);
157157

158158
if (tsFiles.length > 0) {
159159
await ensureDir(moduleOutDir);
160160

161161
// Generate module index
162162
const moduleFrontmatter = createFrontmatter({
163-
title: module.charAt(0).toUpperCase() + module.slice(1),
164-
description: `${module} for ${pkg.name}`,
163+
title: m.charAt(0).toUpperCase() + m.slice(1),
164+
description: `${m} for ${pkg.name}`,
165165
});
166166

167167
const moduleContent = `${moduleFrontmatter}
168168
169-
# ${module.charAt(0).toUpperCase() + module.slice(1)}
169+
# ${m.charAt(0).toUpperCase() + m.slice(1)}
170170
171-
## Available ${module.charAt(0).toUpperCase() + module.slice(1)}
171+
## Available ${m.charAt(0).toUpperCase() + m.slice(1)}
172172
173173
${tsFiles
174174
.map((file) => {
@@ -205,21 +205,21 @@ For detailed type information, please refer to the source code or use your IDE's
205205

206206
await fs.writeFile(
207207
path.join(moduleOutDir, `${name}.mdx`),
208-
fileContent
208+
fileContent,
209209
);
210210
}
211211
}
212-
} catch (e) {
212+
} catch (_e) {
213213
// Module doesn't exist
214214
}
215215
}
216216

217217
// Generate meta.json
218218
const availableModules: string[] = [];
219-
for (const module of modules) {
219+
for (const mod of modules) {
220220
try {
221-
await fs.access(path.join(outDir, module));
222-
availableModules.push(module);
221+
await fs.access(path.join(outDir, mod));
222+
availableModules.push(mod);
223223
} catch {
224224
// Module doesn't exist
225225
}
@@ -232,7 +232,7 @@ For detailed type information, please refer to the source code or use your IDE's
232232

233233
await fs.writeFile(
234234
path.join(outDir, "meta.json"),
235-
JSON.stringify(metaContent, null, 2)
235+
JSON.stringify(metaContent, null, 2),
236236
);
237237
}
238238

@@ -254,4 +254,4 @@ async function main(): Promise<void> {
254254
console.log("API documentation generated successfully!");
255255
}
256256

257-
main().catch(console.error);
257+
main().catch(console.error);

0 commit comments

Comments
 (0)