Skip to content

Commit 62865c6

Browse files
Add rustfmt configuration (#4354)
1 parent 4c98123 commit 62865c6

File tree

130 files changed

+1516
-1264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1516
-1264
lines changed

.github/workflows/reusable-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
path: ${{ env.CARGO_CACHE_PATH }}
5555
key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
5656
- run: cargo build
57-
- run: cargo fmt -- --check
57+
- run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt && cargo +nightly fmt -- --check
5858
- run: cargo clippy --all-targets -- -D warnings
5959
# FIXME: Enable `idl-build`
6060
- run: cargo test --workspace --exclude avm --features allow-missing-optionals,anchor-debug,derive,event-cpi,init-if-needed,lazy-account

avm/src/lib.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
use anyhow::{anyhow, bail, Context, Error, Result};
2-
use cargo_toml::Manifest;
3-
use chrono::{TimeZone, Utc};
4-
use reqwest::header::USER_AGENT;
5-
use reqwest::StatusCode;
6-
use semver::{Prerelease, Version};
7-
use serde::{de, Deserialize};
8-
use std::fs;
9-
use std::io::{BufRead, Write};
10-
use std::path::PathBuf;
11-
use std::process::{Command, Stdio};
12-
use std::sync::LazyLock;
1+
use {
2+
anyhow::{anyhow, bail, Context, Error, Result},
3+
cargo_toml::Manifest,
4+
chrono::{TimeZone, Utc},
5+
reqwest::{header::USER_AGENT, StatusCode},
6+
semver::{Prerelease, Version},
7+
serde::{de, Deserialize},
8+
std::{
9+
fs,
10+
io::{BufRead, Write},
11+
path::PathBuf,
12+
process::{Command, Stdio},
13+
sync::LazyLock,
14+
},
15+
};
1316

1417
/// Checked at most once per hour.
1518
const UPDATE_CHECK_INTERVAL_SECS: i64 = 60 * 60;
@@ -165,7 +168,8 @@ pub fn ensure_paths() {
165168
if !linked {
166169
if let Err(e) = fs::copy(&target, &anchor_in_cargo) {
167170
eprintln!(
168-
"Failed to place `anchor` in {}: {}.\nAdd {} to your PATH or create a symlink manually.",
171+
"Failed to place `anchor` in {}: {}.\nAdd {} to your PATH or \
172+
create a symlink manually.",
169173
cargo_bin.display(),
170174
e,
171175
bin_dir.display()
@@ -800,8 +804,8 @@ pub fn check_avm_version_and_warn() {
800804
UpdateCacheState::Success(ts, latest) if now - ts < UPDATE_CHECK_INTERVAL_SECS => {
801805
if latest > current {
802806
eprintln!(
803-
"A new version of avm is available: {latest} (you have {current}). \
804-
Run `avm self-update` to upgrade."
807+
"A new version of avm is available: {latest} (you have {current}). Run `avm \
808+
self-update` to upgrade."
805809
);
806810
}
807811
}
@@ -816,8 +820,8 @@ pub fn check_avm_version_and_warn() {
816820
write_update_cache_success(&latest);
817821
if latest > current {
818822
eprintln!(
819-
"A new version of avm is available: {latest} (you have {current}). \
820-
Run `avm self-update` to upgrade."
823+
"A new version of avm is available: {latest} (you have {current}). Run \
824+
`avm self-update` to upgrade."
821825
);
822826
}
823827
}
@@ -879,11 +883,11 @@ pub fn self_update(include_pre_release: bool, bleeding_edge: bool) -> Result<()>
879883

880884
#[cfg(test)]
881885
mod tests {
882-
use crate::*;
883-
use semver::Version;
884-
use std::fs;
885-
use std::io::Write;
886-
use std::path::Path;
886+
use {
887+
crate::*,
888+
semver::Version,
889+
std::{fs, io::Write, path::Path},
890+
};
887891

888892
#[test]
889893
fn test_ensure_paths() {

avm/src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use anyhow::{anyhow, Error, Result};
2-
use avm::InstallTarget;
3-
use clap::{CommandFactory, Parser, Subcommand};
4-
use semver::Version;
5-
use std::ffi::OsStr;
1+
use {
2+
anyhow::{anyhow, Error, Result},
3+
avm::InstallTarget,
4+
clap::{CommandFactory, Parser, Subcommand},
5+
semver::Version,
6+
std::ffi::OsStr,
7+
};
68

79
#[derive(Parser)]
810
#[clap(name = "avm", about = "Anchor version manager", version)]
@@ -216,8 +218,7 @@ fn main() -> Result<()> {
216218

217219
#[cfg(test)]
218220
mod tests {
219-
use super::*;
220-
use avm::InstallTarget;
221+
use {super::*, avm::InstallTarget};
221222

222223
// --- is_pre_release ---
223224

cli/src/account.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use anyhow::{anyhow, Result};
2-
use clap::Parser;
3-
use solana_commitment_config::CommitmentConfig;
4-
use solana_pubkey::Pubkey;
5-
use solana_rpc_client::rpc_client::RpcClient;
6-
use std::fs::File;
7-
use std::io::Write;
8-
use std::path::PathBuf;
9-
10-
use crate::config::{Config, ConfigOverride};
1+
use {
2+
crate::config::{Config, ConfigOverride},
3+
anyhow::{anyhow, Result},
4+
clap::Parser,
5+
solana_commitment_config::CommitmentConfig,
6+
solana_pubkey::Pubkey,
7+
solana_rpc_client::rpc_client::RpcClient,
8+
std::{fs::File, io::Write, path::PathBuf},
9+
};
1110

1211
#[derive(Debug, Parser)]
1312
pub struct ShowAccountCommand {

cli/src/bin/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use anchor_cli::Opts;
2-
use anyhow::Result;
3-
use clap::Parser;
1+
use {anchor_cli::Opts, anyhow::Result, clap::Parser};
42

53
fn main() -> Result<()> {
64
anchor_cli::entry(Opts::parse())

cli/src/checks.rs

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::{fs, path::Path};
2-
3-
use anyhow::{anyhow, Result};
4-
use semver::{Version, VersionReq};
5-
6-
use crate::{
7-
config::{Config, Manifest, PackageManager, WithPath},
8-
VERSION,
1+
use {
2+
crate::{
3+
config::{Config, Manifest, PackageManager, WithPath},
4+
VERSION,
5+
},
6+
anyhow::{anyhow, Result},
7+
semver::{Version, VersionReq},
8+
std::{fs, path::Path},
99
};
1010

1111
/// Check whether `overflow-checks` codegen option is enabled.
@@ -18,10 +18,8 @@ pub fn check_overflow(cargo_toml_path: impl AsRef<Path>) -> Result<bool> {
1818
.as_ref()
1919
.and_then(|profile| profile.overflow_checks)
2020
.ok_or(anyhow!(
21-
"`overflow-checks` is not enabled. To enable, add:\n\n\
22-
[profile.release]\n\
23-
overflow-checks = true\n\n\
24-
in workspace root Cargo.toml",
21+
"`overflow-checks` is not enabled. To enable, \
22+
add:\n\n[profile.release]\noverflow-checks = true\n\nin workspace root Cargo.toml",
2523
))
2624
}
2725

@@ -48,11 +46,8 @@ pub fn check_anchor_version(cfg: &WithPath<Config>) -> Result<()> {
4846
if let Some(ver) = mismatched_lang_version {
4947
eprintln!(
5048
"WARNING: `anchor-lang` version({ver}) and the current CLI version({cli_version}) \
51-
don't match.\n\n\t\
52-
This can lead to unwanted behavior. To use the same CLI version, add:\n\n\t\
53-
[toolchain]\n\t\
54-
anchor_version = \"{ver}\"\n\n\t\
55-
to Anchor.toml\n"
49+
don't match.\n\n\tThis can lead to unwanted behavior. To use the same CLI version, \
50+
add:\n\n\t[toolchain]\n\tanchor_version = \"{ver}\"\n\n\tto Anchor.toml\n"
5651
);
5752
}
5853

@@ -78,10 +73,9 @@ pub fn check_anchor_version(cfg: &WithPath<Config>) -> Result<()> {
7873
};
7974

8075
eprintln!(
81-
"WARNING: `@anchor-lang/core` version({ver}) and the current CLI version\
82-
({cli_version}) don't match.\n\n\t\
83-
This can lead to unwanted behavior. To fix, upgrade the package by running:\n\n\t\
84-
{update_cmd} @anchor-lang/core@{cli_version}\n"
76+
"WARNING: `@anchor-lang/core` version({ver}) and the current CLI \
77+
version({cli_version}) don't match.\n\n\tThis can lead to unwanted behavior. To fix, \
78+
upgrade the package by running:\n\n\t{update_cmd} @anchor-lang/core@{cli_version}\n"
8579
);
8680
}
8781

@@ -135,11 +129,10 @@ pub fn check_deps(cfg: &WithPath<Config>) -> Result<()> {
135129
})
136130
.for_each(|man| {
137131
eprintln!(
138-
"WARNING: Adding `solana-program` as a separate dependency might cause conflicts.\n\
139-
To solve, remove the `solana-program` dependency and use the exported crate from \
140-
`anchor-lang`.\n\
141-
`use solana_program` becomes `use anchor_lang::solana_program`.\n\
142-
Program name: `{}`\n",
132+
"WARNING: Adding `solana-program` as a separate dependency might cause \
133+
conflicts.\nTo solve, remove the `solana-program` dependency and use the \
134+
exported crate from `anchor-lang`.\n`use solana_program` becomes `use \
135+
anchor_lang::solana_program`.\nProgram name: `{}`\n",
143136
man.package().name()
144137
)
145138
});
@@ -187,12 +180,10 @@ in `{manifest_path:?}`."#
187180
.filter(|(_, dep)| dep.req_features().contains(&"idl-build".into()))
188181
.for_each(|(name, _)| {
189182
eprintln!(
190-
"WARNING: `idl-build` feature of crate `{name}` is enabled by default. \
191-
This is not the intended usage.\n\n\t\
192-
To solve, do not enable the `idl-build` feature and include crates that have \
193-
`idl-build` feature in the `idl-build` feature list:\n\n\t\
194-
[features]\n\t\
195-
idl-build = [\"{name}/idl-build\", ...]\n"
183+
"WARNING: `idl-build` feature of crate `{name}` is enabled by default. This is \
184+
not the intended usage.\n\n\tTo solve, do not enable the `idl-build` feature and \
185+
include crates that have `idl-build` feature in the `idl-build` feature \
186+
list:\n\n\t[features]\n\tidl-build = [\"{name}/idl-build\", ...]\n"
196187
)
197188
});
198189

@@ -205,11 +196,10 @@ in `{manifest_path:?}`."#
205196
.unwrap_or_default()
206197
.then(|| {
207198
eprintln!(
208-
"WARNING: `idl-build` feature of `anchor-spl` is not enabled. \
209-
This is likely to result in cryptic compile errors.\n\n\t\
210-
To solve, add `anchor-spl/idl-build` to the `idl-build` feature list:\n\n\t\
211-
[features]\n\t\
212-
idl-build = [\"anchor-spl/idl-build\", ...]\n"
199+
"WARNING: `idl-build` feature of `anchor-spl` is not enabled. This is likely to \
200+
result in cryptic compile errors.\n\n\tTo solve, add `anchor-spl/idl-build` to \
201+
the `idl-build` feature list:\n\n\t[features]\n\tidl-build = \
202+
[\"anchor-spl/idl-build\", ...]\n"
213203
)
214204
});
215205

cli/src/config.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
use crate::{get_keypair, is_hidden, keys_sync, DEFAULT_RPC_PORT};
2-
use anchor_client::Cluster;
3-
use anchor_lang_idl::types::Idl;
4-
use anyhow::{anyhow, bail, Context, Error, Result};
5-
use clap::{Parser, ValueEnum};
6-
use dirs::home_dir;
7-
use heck::ToSnakeCase;
8-
use reqwest::Url;
9-
use serde::de::{self, MapAccess, Visitor};
10-
use serde::ser::SerializeMap;
11-
use serde::{Deserialize, Deserializer, Serialize, Serializer};
12-
use solana_cli_config::{Config as SolanaConfig, CONFIG_FILE};
13-
use solana_clock::Slot;
14-
use solana_commitment_config::CommitmentLevel;
15-
use solana_keypair::Keypair;
16-
use solana_pubkey::Pubkey;
17-
use solana_signer::Signer;
18-
use std::collections::{BTreeMap, HashMap};
19-
use std::convert::TryFrom;
20-
use std::fs::{self, File};
21-
use std::io::prelude::*;
22-
use std::marker::PhantomData;
23-
use std::ops::Deref;
24-
use std::path::Path;
25-
use std::path::PathBuf;
26-
use std::process::Command;
27-
use std::str::FromStr;
28-
use std::{fmt, io};
29-
use walkdir::WalkDir;
1+
use {
2+
crate::{get_keypair, is_hidden, keys_sync, DEFAULT_RPC_PORT},
3+
anchor_client::Cluster,
4+
anchor_lang_idl::types::Idl,
5+
anyhow::{anyhow, bail, Context, Error, Result},
6+
clap::{Parser, ValueEnum},
7+
dirs::home_dir,
8+
heck::ToSnakeCase,
9+
reqwest::Url,
10+
serde::{
11+
de::{self, MapAccess, Visitor},
12+
ser::SerializeMap,
13+
Deserialize, Deserializer, Serialize, Serializer,
14+
},
15+
solana_cli_config::{Config as SolanaConfig, CONFIG_FILE},
16+
solana_clock::Slot,
17+
solana_commitment_config::CommitmentLevel,
18+
solana_keypair::Keypair,
19+
solana_pubkey::Pubkey,
20+
solana_signer::Signer,
21+
std::{
22+
collections::{BTreeMap, HashMap},
23+
convert::TryFrom,
24+
fmt,
25+
fs::{self, File},
26+
io::{self, prelude::*},
27+
marker::PhantomData,
28+
ops::Deref,
29+
path::{Path, PathBuf},
30+
process::Command,
31+
str::FromStr,
32+
},
33+
walkdir::WalkDir,
34+
};
3035

3136
pub const SURFPOOL_HOST: &str = "127.0.0.1";
3237
/// Wrapper around CommitmentLevel to support case-insensitive parsing
@@ -1034,7 +1039,8 @@ fn canonicalize_filepath_from_origin(
10341039
let result = fs::canonicalize(&file_path)
10351040
.with_context(|| {
10361041
format!(
1037-
"Error reading (possibly relative) path: {}. If relative, this is the path that was used as the current path: {}",
1042+
"Error reading (possibly relative) path: {}. If relative, this is the path that \
1043+
was used as the current path: {}",
10381044
&file_path.as_ref().display(),
10391045
&origin.as_ref().display()
10401046
)

cli/src/keygen.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
use std::{
2-
fs,
3-
io::{self, Write},
4-
path::Path,
1+
use {
2+
crate::{config::ConfigOverride, get_keypair, KeygenCommand},
3+
anyhow::{anyhow, bail, Result},
4+
bip39::{Language, Mnemonic, MnemonicType, Seed},
5+
console::{Key, Term},
6+
dirs::home_dir,
7+
solana_instruction::{AccountMeta, Instruction},
8+
solana_keypair::Keypair,
9+
solana_pubkey::Pubkey,
10+
solana_signer::{EncodableKey, Signer},
11+
solana_transaction::Message,
12+
std::{
13+
fs,
14+
io::{self, Write},
15+
path::Path,
16+
},
517
};
618

7-
use anyhow::{anyhow, bail, Result};
8-
use bip39::{Language, Mnemonic, MnemonicType, Seed};
9-
use console::{Key, Term};
10-
use dirs::home_dir;
11-
use solana_instruction::{AccountMeta, Instruction};
12-
use solana_keypair::Keypair;
13-
use solana_pubkey::Pubkey;
14-
use solana_signer::{EncodableKey, Signer};
15-
use solana_transaction::Message;
16-
17-
use crate::{config::ConfigOverride, get_keypair, KeygenCommand};
18-
1919
/// Secure password input with asterisk visual feedback
2020
/// - show_spaces: if true, spaces are visible (for seed phrases); if false, all characters are asterisks (for passphrases)
2121
fn secure_input(prompt: &str, show_spaces: bool) -> Result<String> {
@@ -351,8 +351,10 @@ fn keygen_verify(pubkey: Pubkey, keypair_path: Option<String>) -> Result<()> {
351351

352352
#[cfg(test)]
353353
mod tests {
354-
use super::*;
355-
use tempfile::{tempdir, TempDir};
354+
use {
355+
super::*,
356+
tempfile::{tempdir, TempDir},
357+
};
356358

357359
fn tmp_outfile_path(out_dir: &TempDir, name: &str) -> String {
358360
let path = out_dir.path().join(name);
@@ -433,7 +435,8 @@ mod tests {
433435
#[test]
434436
fn test_keypair_from_seed_consistency() {
435437
// Test that the same seed phrase produces the same keypair
436-
let test_phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
438+
let test_phrase = "abandon abandon abandon abandon abandon abandon abandon abandon \
439+
abandon abandon abandon about";
437440

438441
let mnemonic = Mnemonic::from_phrase(test_phrase, Language::English).unwrap();
439442
let seed1 = Seed::new(&mnemonic, "");

0 commit comments

Comments
 (0)