From a68906bfb9072b588590be8c2dde6f943494d750 Mon Sep 17 00:00:00 2001 From: Vara Prasad Bandaru Date: Wed, 6 Mar 2024 18:45:04 +0530 Subject: [PATCH] Update scripts/update_readmes.sh to parse anchor non anchor fields in cargo.toml --- README.md | 2 +- lints/arbitrary_cpi/Cargo.toml | 4 +++ lints/bump_seed_canonicalization/Cargo.toml | 4 +++ lints/insecure_account_close/Cargo.toml | 4 +++ lints/missing_owner_check/Cargo.toml | 4 +++ lints/missing_signer_check/Cargo.toml | 4 +++ lints/type_cosplay/Cargo.toml | 4 +++ scripts/update_readmes.sh | 29 ++++++++++++++++++--- 8 files changed, 50 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 832562a..c64e316 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The lints are inspired by the [Sealevel Attacks]. (See also @pencilflip's [Twitt The current lints are: -| Library | Description | Anchor | Non-Anchor | +| Library | Description | Anchor | Non Anchor | | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------------------ | | [`arbitrary_cpi`](lints/arbitrary_cpi) | lint for [5-arbitrary-cpi](https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/5-arbitrary-cpi) | | :heavy_check_mark: | | [`bump_seed_canonicalization`](lints/bump_seed_canonicalization) | lint for [6-bump-seed-canonicalization](https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/7-bump-seed-canonicalization) | | :heavy_check_mark: | diff --git a/lints/arbitrary_cpi/Cargo.toml b/lints/arbitrary_cpi/Cargo.toml index 82caf05..3633b12 100644 --- a/lints/arbitrary_cpi/Cargo.toml +++ b/lints/arbitrary_cpi/Cargo.toml @@ -40,3 +40,7 @@ dylint_testing = "2.6" [package.metadata.rust-analyzer] rustc_private = true + +[package.metadata] +anchor_programs = false +non_anchor_programs = true diff --git a/lints/bump_seed_canonicalization/Cargo.toml b/lints/bump_seed_canonicalization/Cargo.toml index 458172f..690d26e 100644 --- a/lints/bump_seed_canonicalization/Cargo.toml +++ b/lints/bump_seed_canonicalization/Cargo.toml @@ -43,3 +43,7 @@ dylint_testing = "2.6" [package.metadata.rust-analyzer] rustc_private = true + +[package.metadata] +anchor_programs = false +non_anchor_programs = true diff --git a/lints/insecure_account_close/Cargo.toml b/lints/insecure_account_close/Cargo.toml index 3967ee2..95a7052 100644 --- a/lints/insecure_account_close/Cargo.toml +++ b/lints/insecure_account_close/Cargo.toml @@ -43,3 +43,7 @@ dylint_testing = "2.6" [package.metadata.rust-analyzer] rustc_private = true + +[package.metadata] +anchor_programs = true +non_anchor_programs = true diff --git a/lints/missing_owner_check/Cargo.toml b/lints/missing_owner_check/Cargo.toml index 76d2f20..7dbed79 100644 --- a/lints/missing_owner_check/Cargo.toml +++ b/lints/missing_owner_check/Cargo.toml @@ -48,3 +48,7 @@ dylint_testing = "2.6" [package.metadata.rust-analyzer] rustc_private = true + +[package.metadata] +anchor_programs = true +non_anchor_programs = true diff --git a/lints/missing_signer_check/Cargo.toml b/lints/missing_signer_check/Cargo.toml index de69b6a..567ba6a 100644 --- a/lints/missing_signer_check/Cargo.toml +++ b/lints/missing_signer_check/Cargo.toml @@ -35,3 +35,7 @@ dylint_testing = "2.6" [package.metadata.rust-analyzer] rustc_private = true + +[package.metadata] +anchor_programs = true +non_anchor_programs = true diff --git a/lints/type_cosplay/Cargo.toml b/lints/type_cosplay/Cargo.toml index 2cedcbd..77e6391 100644 --- a/lints/type_cosplay/Cargo.toml +++ b/lints/type_cosplay/Cargo.toml @@ -55,3 +55,7 @@ dylint_testing = "2.6" [package.metadata.rust-analyzer] rustc_private = true + +[package.metadata] +anchor_programs = false +non_anchor_programs = true diff --git a/scripts/update_readmes.sh b/scripts/update_readmes.sh index 0be168a..a38348a 100755 --- a/scripts/update_readmes.sh +++ b/scripts/update_readmes.sh @@ -25,10 +25,31 @@ cat ../README.md | while read X; do if [[ "$X" =~ ^\| ]]; then if [[ -z "$LISTED" ]]; then - echo '| Library | Description |' - echo '| - | - |' - grep -H '^description = "[^"]*"$' */Cargo.toml | - sed 's,^\([^/]*\)/Cargo.toml:description = "\([^"]*\)"$,| [`\1`](lints/\1) | \2 |,' + echo '| Library | Description | Anchor | Non Anchor |' + echo '| - | - | - | - |' + for CARGO_TOML in */Cargo.toml; do + DESC=$( + grep -H '^description = "[^"]*"$' "$CARGO_TOML" | + sed 's,^\([^/]*\)/Cargo.toml:description = "\([^"]*\)"$,| [`\1`](lints/\1) | \2,' + ) + ANCHOR=$( + grep '^anchor_programs = \(true\|false\)$' "$CARGO_TOML" | + sed 's,^anchor_programs = \([a-z]*\)$,\1,' + ) + NON_ANCHOR=$( + grep '^non_anchor_programs = \(true\|false\)$' "$CARGO_TOML" | + sed 's,^non_anchor_programs = \([a-z]*\)$,\1,' + ) + ANCHOR_COLUMN=" " + if [[ "$ANCHOR" == "true" ]]; then + ANCHOR_COLUMN=":heavy_check_mark:" + fi + NON_ANCHOR_COLUMN=" " + if [[ "$NON_ANCHOR" == "true" ]]; then + NON_ANCHOR_COLUMN=":heavy_check_mark:" + fi + echo "$DESC | $ANCHOR_COLUMN | $NON_ANCHOR_COLUMN |" + done LISTED=1 fi continue