From 817dd707ff63a98fa526d65ad75d6b2d86468aa8 Mon Sep 17 00:00:00 2001 From: Danilo Guanabara Date: Fri, 29 Nov 2024 01:51:38 -0300 Subject: [PATCH] refactor: adding lint script and fixing lint and test errors --- .prettierignore | 3 ++- cli/src/rust_template.rs | 2 +- cli/src/templates/component/mod.rs | 6 +++++- cli/src/templates/program/mod.rs | 17 +++++++++++------ cli/src/templates/system/mod.rs | 6 +++++- cli/src/templates/workspace/mod.rs | 27 +++++++++++++++++++++++---- scripts/lint.sh | 13 +++++++++++++ scripts/test.sh | 1 - tests/bolt.ts | 2 +- 9 files changed, 61 insertions(+), 16 deletions(-) create mode 100755 scripts/lint.sh diff --git a/.prettierignore b/.prettierignore index 6db9896..aff2cad 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,4 +6,5 @@ node_modules dist build test-ledger -clients/bolt-sdk/lib \ No newline at end of file +clients/bolt-sdk/lib +cli/src/templates/**/* \ No newline at end of file diff --git a/cli/src/rust_template.rs b/cli/src/rust_template.rs index 0c40f18..22e73e8 100644 --- a/cli/src/rust_template.rs +++ b/cli/src/rust_template.rs @@ -47,7 +47,7 @@ pub(crate) fn create_system(name: &str) -> Result<()> { pub fn create_program(name: &str, template: ProgramTemplate) -> Result<()> { let program_path = Path::new("programs").join(name); let common_files = vec![ - ("Cargo.toml".into(), workspace_manifest().into()), + ("Cargo.toml".into(), workspace_manifest()), (program_path.join("Cargo.toml"), cargo_toml(name)), (program_path.join("Xargo.toml"), xargo_toml().into()), ]; diff --git a/cli/src/templates/component/mod.rs b/cli/src/templates/component/mod.rs index 98e7241..3de9b63 100644 --- a/cli/src/templates/component/mod.rs +++ b/cli/src/templates/component/mod.rs @@ -12,7 +12,11 @@ pub fn create_component_template_simple(name: &str, program_path: &Path) -> File let program_name = name.to_upper_camel_case(); vec![( program_path.join("src").join("lib.rs"), - format!(include_str!("lib.rs"), program_id=program_id, program_name=program_name) + format!( + include_str!("lib.rs"), + program_id = program_id, + program_name = program_name + ), )] } diff --git a/cli/src/templates/program/mod.rs b/cli/src/templates/program/mod.rs index 8765865..fb18071 100644 --- a/cli/src/templates/program/mod.rs +++ b/cli/src/templates/program/mod.rs @@ -7,7 +7,11 @@ pub fn create_program_template_single(name: &str, program_path: &Path) -> Files let program_name = name.to_snake_case(); vec![( program_path.join("src").join("lib.rs"), - format!(include_str!("single.lib.rs"), program_id=program_id, program_name=program_name), + format!( + include_str!("single.lib.rs"), + program_id = program_id, + program_name = program_name + ), )] } @@ -19,16 +23,17 @@ pub fn create_program_template_multiple(name: &str, program_path: &Path) -> File vec![ ( src_path.join("lib.rs"), - format!(include_str!("multiple.lib.rs"), program_id=program_id, program_name=program_name), + format!( + include_str!("multiple.lib.rs"), + program_id = program_id, + program_name = program_name + ), ), ( src_path.join("constants.rs"), include_str!("constants.rs").into(), ), - ( - src_path.join("error.rs"), - include_str!("error.rs").into(), - ), + (src_path.join("error.rs"), include_str!("error.rs").into()), ( src_path.join("instructions").join("mod.rs"), include_str!("instructions/mod.rs").into(), diff --git a/cli/src/templates/system/mod.rs b/cli/src/templates/system/mod.rs index dc79ec0..bdd60ca 100644 --- a/cli/src/templates/system/mod.rs +++ b/cli/src/templates/system/mod.rs @@ -8,6 +8,10 @@ pub fn create_system_template_simple(name: &str, program_path: &Path) -> Files { let program_name = name.to_snake_case(); vec![( program_path.join("src").join("lib.rs"), - format!(include_str!("lib.rs"), program_id=program_id, program_name=program_name) + format!( + include_str!("lib.rs"), + program_id = program_id, + program_name = program_name + ), )] } diff --git a/cli/src/templates/workspace/mod.rs b/cli/src/templates/workspace/mod.rs index d2fab9b..c49e2ec 100644 --- a/cli/src/templates/workspace/mod.rs +++ b/cli/src/templates/workspace/mod.rs @@ -3,7 +3,11 @@ use heck::ToSnakeCase; pub const ANCHOR_VERSION: &str = anchor_cli::VERSION; pub fn workspace_manifest() -> String { - format!(include_str!("workspace.toml"), VERSION=VERSION, ANCHOR_VERSION=ANCHOR_VERSION) + format!( + include_str!("workspace.toml"), + VERSION = VERSION, + ANCHOR_VERSION = ANCHOR_VERSION + ) } pub fn package_json(jest: bool) -> String { @@ -36,13 +40,23 @@ pub fn ts_mocha(name: &str) -> String { pub fn cargo_toml(name: &str) -> String { let snake_case_name = name.to_snake_case(); - format!(include_str!("Cargo.toml"), name=name, snake_case_name=snake_case_name, VERSION=VERSION) + format!( + include_str!("Cargo.toml"), + name = name, + snake_case_name = snake_case_name, + VERSION = VERSION + ) } /// TODO: Remove serde dependency pub fn cargo_toml_with_serde(name: &str) -> String { let snake_case_name = name.to_snake_case(); - format!(include_str!("Cargo.serde.toml"), name=name, snake_case_name=snake_case_name, VERSION=VERSION) + format!( + include_str!("Cargo.serde.toml"), + name = name, + snake_case_name = snake_case_name, + VERSION = VERSION + ) } pub fn xargo_toml() -> &'static str { @@ -59,5 +73,10 @@ pub fn prettier_ignore() -> &'static str { pub(crate) fn types_cargo_toml() -> String { let name = "bolt-types"; let snake_case_name = name.to_snake_case(); - format!(include_str!("types.Cargo.toml"), name=name, snake_case_name=snake_case_name, VERSION=VERSION) + format!( + include_str!("types.Cargo.toml"), + name = name, + snake_case_name = snake_case_name, + VERSION = VERSION + ) } diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100755 index 0000000..73468d1 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,13 @@ +set -e +SCRIPT_DIR=$(dirname "$0") +PROJECT_DIR="$SCRIPT_DIR/.." +pushd "$PROJECT_DIR" +echo "### Checking formatting..." +cargo fmt -- --check --verbose + +echo "### Checking clippy..." +cargo clippy -- --deny=warnings + +echo "### Checking yarn lint..." +yarn lint +popd diff --git a/scripts/test.sh b/scripts/test.sh index e72020f..ed68311 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,4 +1,3 @@ -set -e SCRIPT_DIR=$(dirname "$0") PROJECT_DIR="$SCRIPT_DIR/.." pushd "$PROJECT_DIR" diff --git a/tests/bolt.ts b/tests/bolt.ts index 7b3efd7..44db671 100644 --- a/tests/bolt.ts +++ b/tests/bolt.ts @@ -22,9 +22,9 @@ import { ApproveSystem, RemoveSystem, type Program, + anchor, web3, } from "../clients/bolt-sdk"; -import * as anchor from "@coral-xyz/anchor"; enum Direction { Left = "Left",