Skip to content

Commit

Permalink
feat: add prettier (solana-developers#356)
Browse files Browse the repository at this point in the history
* Prettier Setup

* Messed up a ts file to test

* Messing up a .rs file to test

* Messing up a .rs file again

* Reverted the .rs file back to original

* Format Script Added

* Code Formatted
  • Loading branch information
pratikbuilds authored May 20, 2022
1 parent a84f06e commit 2a6ffb1
Show file tree
Hide file tree
Showing 172 changed files with 2,455 additions and 1,519 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docs
node_modules
.github
.devcontainer
23 changes: 12 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The following is a set of guidelines on how to contribute
The cookbook is layed out in 4 different sections.

| Section | Description |
|-----------------|-----------------------------------------------------------------|
| --------------- | --------------------------------------------------------------- |
| Getting Started | Resources for starting development on Solana |
| Core Concepts | Building blocks of Solana that are good to know for development |
| Guides | Snack-sized guides about different tools for development |
Expand Down Expand Up @@ -68,13 +68,13 @@ at (http://localhost:8080/)

### Code Previews

The Solana Cookbook utilizes code previews to articulate exactly what code is needed
The Solana Cookbook utilizes code previews to articulate exactly what code is needed
for a reference, as well as the full source so that developers can reference any variables
needed.

While the preview highlights the needed code, it does not have to run alone.

We use the preview component `<SolanaCodeGroup>` with each language's snippet with
We use the preview component `<SolanaCodeGroup>` with each language's snippet with
`<SolanaCodeGroupItem>`.

#### Example Preview
Expand All @@ -85,10 +85,11 @@ Let's take the following code for getting a `Keypair` from a `secret`:
import { Keypair } from "@solana/web3.js";

const secret = Uint8Array.from([
174, 47, 154, 16, 202, 193, 206, 113, 199, 190, 53, 133, 169, 175, 31, 56, 222, 53, 138, 189, 224, 216, 117,
173, 10, 149, 53, 45, 73, 251, 237, 246, 15, 185, 186, 82, 177, 240, 148, 69, 241, 227, 167, 80, 141, 89, 240,
121, 121, 35, 172, 247, 68, 251, 226, 218, 48, 63, 176, 109, 168, 89, 238, 135,
]);
174, 47, 154, 16, 202, 193, 206, 113, 199, 190, 53, 133, 169, 175, 31, 56,
222, 53, 138, 189, 224, 216, 117, 173, 10, 149, 53, 45, 73, 251, 237, 246, 15,
185, 186, 82, 177, 240, 148, 69, 241, 227, 167, 80, 141, 89, 240, 121, 121,
35, 172, 247, 68, 251, 226, 218, 48, 63, 176, 109, 168, 89, 238, 135,
]);

(async () => {
const keypair = Keypair.fromSecretKey(secret);
Expand All @@ -101,8 +102,8 @@ The preview for the above code could be:
const keypair = Keypair.fromSecretKey(secret);
```

The developer can see exactly the method required to get a Keypair from a secret key
in the preview, but can view the full source on the component to understand the example
The developer can see exactly the method required to get a Keypair from a secret key
in the preview, but can view the full source on the component to understand the example
further.

## How Can I Contribute?
Expand Down Expand Up @@ -134,10 +135,10 @@ General flow for making a contribution:
4. Push your work back up to your fork
5. Submit a Pull request so that we can review your changes

**NOTE**: Be sure to merge the latest from "upstream" before making a
**NOTE**: Be sure to merge the latest from "upstream" before making a
pull request!

## Contribution Rewards

All those who successfully contribute to the Solana Cookbook will get an exclusive
All those who successfully contribute to the Solana Cookbook will get an exclusive
Glasseater NFT from the Superteam DAO. If you have already contributed, [claim your Glasseater NFT now](https://alpha.layer3.xyz/task/contribute-to-the-solana-cookbook)!
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ The Cookbook is welcome to any and all contributions. Please refer to
the project's style when contributing new snippets of code.

### Structure
Currently we have "topics" under `/docs` and the code for those topics

Currently we have "topics" under `/docs` and the code for those topics
lives under `/code/<topic>`.

### References
Expand Down Expand Up @@ -61,6 +62,7 @@ It will take some time to start, the documentation can then be viewed
at (http://localhost:8080/)

### Committing

We are using [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
for this repository.

Expand All @@ -77,13 +79,14 @@ The general flow for making a contribution:
4. Push your work back up to your fork
5. Submit a Pull request so that we can review your changes

**NOTE**: Be sure to merge the latest from "upstream" before making a
**NOTE**: Be sure to merge the latest from "upstream" before making a
pull request!

You can find tasks on the [project board](https://github.com/solana-developers/solana-cookbook/projects/1)
You can find tasks on the [project board](https://github.com/solana-developers/solana-cookbook/projects/1)
or create an issue and assign it to yourself.

### Contribution Rewards

The first 25 successful contributors to the Solana Cookbook will get an exclusive Glasseater NFT from the [Superteam DAO](https://superteam.fun). Use this NFT to get direct access to exclusive Solana Ecosystem jobs. If you have already contributed, [claim your Glasseater NFT now](https://alpha.layer3.xyz/task/contribute-to-the-solana-cookbook)!

### [NOTE: Documentation changes/edits will not be considered for Contribution Rewards]
Expand Down
42 changes: 21 additions & 21 deletions code/account-maps/deriving-pda/client.preview.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
(async () => {
const connection = new Connection("http://localhost:8899", "confirmed");
async () => {
const connection = new Connection("http://localhost:8899", "confirmed");

const [blogAccount] = await PublicKey.findProgramAddress(
[Buffer.from("blog"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);
const [blogAccount] = await PublicKey.findProgramAddress(
[Buffer.from("blog"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);

const [postAccount] = await PublicKey.findProgramAddress(
[Buffer.from("post"), Buffer.from("slug-1"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);
const [postAccount] = await PublicKey.findProgramAddress(
[Buffer.from("post"), Buffer.from("slug-1"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);

const blogAccountInfo = await connection.getAccountInfo(blogAccount);
const blogAccountState = BLOG_ACCOUNT_DATA_LAYOUT.decode(
blogAccountInfo.data
);
console.log("Blog account state: ", blogAccountState);
const blogAccountInfo = await connection.getAccountInfo(blogAccount);
const blogAccountState = BLOG_ACCOUNT_DATA_LAYOUT.decode(
blogAccountInfo.data
);
console.log("Blog account state: ", blogAccountState);

const postAccountInfo = await connection.getAccountInfo(postAccount);
const postAccountState = POST_ACCOUNT_DATA_LAYOUT.decode(
postAccountInfo.data
);
console.log("Post account state: ", postAccountState);
})
const postAccountInfo = await connection.getAccountInfo(postAccount);
const postAccountState = POST_ACCOUNT_DATA_LAYOUT.decode(
postAccountInfo.data
);
console.log("Post account state: ", postAccountState);
};
60 changes: 30 additions & 30 deletions code/account-maps/deriving-pda/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@ import * as borsh from "@project-serum/borsh";
import { PublicKey } from "@solana/web3.js";

export const BLOG_ACCOUNT_DATA_LAYOUT = borsh.struct([
borsh.publicKey("authorityPubkey"),
borsh.u8("bump"),
borsh.u8("postCount"),
borsh.publicKey("authorityPubkey"),
borsh.u8("bump"),
borsh.u8("postCount"),
]);

export const POST_ACCOUNT_DATA_LAYOUT = borsh.struct([
borsh.publicKey("author"),
borsh.publicKey("blog"),
borsh.u8("bump"),
borsh.str("slug"),
borsh.str("title"),
borsh.str("content"),
borsh.publicKey("author"),
borsh.publicKey("blog"),
borsh.u8("bump"),
borsh.str("slug"),
borsh.str("title"),
borsh.str("content"),
]);

(async () => {
const connection = new Connection("http://localhost:8899", "confirmed");
async () => {
const connection = new Connection("http://localhost:8899", "confirmed");

const [blogAccount] = await PublicKey.findProgramAddress(
[Buffer.from("blog"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);
const [blogAccount] = await PublicKey.findProgramAddress(
[Buffer.from("blog"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);

const [postAccount] = await PublicKey.findProgramAddress(
[Buffer.from("post"), Buffer.from("slug-1"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);
const [postAccount] = await PublicKey.findProgramAddress(
[Buffer.from("post"), Buffer.from("slug-1"), user.publicKey.toBuffer()],
MY_PROGRAM_ID
);

const blogAccountInfo = await connection.getAccountInfo(blogAccount);
const blogAccountState = BLOG_ACCOUNT_DATA_LAYOUT.decode(
blogAccountInfo.data
);
console.log("Blog account state: ", blogAccountState);
const blogAccountInfo = await connection.getAccountInfo(blogAccount);
const blogAccountState = BLOG_ACCOUNT_DATA_LAYOUT.decode(
blogAccountInfo.data
);
console.log("Blog account state: ", blogAccountState);

const postAccountInfo = await connection.getAccountInfo(postAccount);
const postAccountState = POST_ACCOUNT_DATA_LAYOUT.decode(
const postAccountInfo = await connection.getAccountInfo(postAccount);
const postAccountState = POST_ACCOUNT_DATA_LAYOUT.decode(
postAccountInfo.data
);
console.log("Post account state: ", postAccountState);
})
);
console.log("Post account state: ", postAccountState);
};
80 changes: 40 additions & 40 deletions code/account-maps/trivial/client.preview.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
const insertABIx = new TransactionInstruction({
programId: MY_PROGRAM_ID,
keys: [
programId: MY_PROGRAM_ID,
keys: [
{
pubkey: userA.publicKey,
isSigner: true,
isWritable: true,
pubkey: userA.publicKey,
isSigner: true,
isWritable: true,
},
{
pubkey: userB.publicKey,
isSigner: false,
isWritable: false,
pubkey: userB.publicKey,
isSigner: false,
isWritable: false,
},
{
pubkey: mapKey,
isSigner: false,
isWritable: true,
pubkey: mapKey,
isSigner: false,
isWritable: true,
},
],
data: Buffer.from(Uint8Array.of(1)),
],
data: Buffer.from(Uint8Array.of(1)),
});

const insertBCIx = new TransactionInstruction({
programId: MY_PROGRAM_ID,
keys: [
programId: MY_PROGRAM_ID,
keys: [
{
pubkey: userB.publicKey,
isSigner: true,
isWritable: true,
pubkey: userB.publicKey,
isSigner: true,
isWritable: true,
},
{
pubkey: userC.publicKey,
isSigner: false,
isWritable: false,
pubkey: userC.publicKey,
isSigner: false,
isWritable: false,
},
{
pubkey: mapKey,
isSigner: false,
isWritable: true,
pubkey: mapKey,
isSigner: false,
isWritable: true,
},
],
data: Buffer.from(Uint8Array.of(1)),
],
data: Buffer.from(Uint8Array.of(1)),
});

const insertCAIx = new TransactionInstruction({
programId: MY_PROGRAM_ID,
keys: [
programId: MY_PROGRAM_ID,
keys: [
{
pubkey: userC.publicKey,
isSigner: true,
isWritable: true,
pubkey: userC.publicKey,
isSigner: true,
isWritable: true,
},
{
pubkey: userA.publicKey,
isSigner: false,
isWritable: false,
pubkey: userA.publicKey,
isSigner: false,
isWritable: false,
},
{
pubkey: mapKey,
isSigner: false,
isWritable: true,
pubkey: mapKey,
isSigner: false,
isWritable: true,
},
],
data: Buffer.from(Uint8Array.of(1)),
],
data: Buffer.from(Uint8Array.of(1)),
});

const tx = new Transaction();
tx.add(initMapIx);
tx.add(insertABIx);
tx.add(insertBCIx);
tx.add(insertCAIx);
tx.add(insertCAIx);
Loading

0 comments on commit 2a6ffb1

Please sign in to comment.