coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

fix unused variable warning on new projects #2930

Closed mikemaccana closed 2 months ago

mikemaccana commented 2 months ago

Running anchor init and then anchor build always returns:

warning: unused variable: `ctx`
 --> programs/deleteme/src/lib.rs:9:23
  |
9 |     pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
  |                       ^^^ help: if this is intentional, prefix it with an underscore: `_ctx`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `deleteme` (lib) generated 1 warning (run `cargo fix --lib -p deleteme` to apply 1 suggestion)

This is a bit of an unnecessary distraction. This PR silences the warning by simply logging the program ID in the default function handler.

Additionally, context is spelt context to be consistent with the rest of Anchor. Right now prelude, program, initialize, handler, wallet, are all full words without contractions but ctx is contracted, and when discussing Anchor we have to consistently remind people of this by saying "context, spelled 'see tee ecks'". It's a change, but people that already know anchor should easily understand that context is ctx and people new to anchor can save some unnecessary confusion.

vercel[bot] commented 2 months ago

@mikemaccana is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

mikemaccana commented 2 months ago

Got It,ctx it is. Updated.