Skip to content

Commit

Permalink
refactor: adding lint script and fixing lint and test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
notdanilo committed Nov 29, 2024
1 parent 7278d99 commit 817dd70
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
dist
build
test-ledger
clients/bolt-sdk/lib
clients/bolt-sdk/lib
cli/src/templates/**/*
2 changes: 1 addition & 1 deletion cli/src/rust_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
Expand Down
6 changes: 5 additions & 1 deletion cli/src/templates/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
)]
}

Expand Down
17 changes: 11 additions & 6 deletions cli/src/templates/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
)]
}

Expand All @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion cli/src/templates/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
)]
}
27 changes: 23 additions & 4 deletions cli/src/templates/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
)
}
13 changes: 13 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
set -e
SCRIPT_DIR=$(dirname "$0")
PROJECT_DIR="$SCRIPT_DIR/.."
pushd "$PROJECT_DIR"
Expand Down
2 changes: 1 addition & 1 deletion tests/bolt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 817dd70

Please sign in to comment.