Skip to content

Commit

Permalink
Make anchor-ts and hardhat-ts aliass for anchor and hardhat (…
Browse files Browse the repository at this point in the history
…respectively)
  • Loading branch information
smoelius committed Jul 3, 2024
1 parent 9361d6d commit de21f2e
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-testing-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
- name: Install Anchor
if: ${{ runner.os != 'Windows' }}
run: |
cp backends/src/anchor_ts/rfc8032_test_vector.json ~/.config/solana/id.json
cp backends/src/anchor/rfc8032_test_vector.json ~/.config/solana/id.json
if [[ "$(anchor --version)" != 'anchor-cli 0.27.0' ]]; then
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install 0.27.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Options:
--deny <WARNING> Treat <WARNING> as an error; `--deny all` treats all warnings as errors
--dump Dump sqlite database contents to the console
--dump-candidates Dump removal candidates and exit (for debugging)
--framework <FRAMEWORK> Assume testing framework is <FRAMEWORK> [possible values: anchor-ts, auto, foundry, go, hardhat-ts, rust]
--framework <FRAMEWORK> Assume testing framework is <FRAMEWORK> [possible values: anchor, auto, foundry, go, hardhat, rust]
--no-dry-run Do not perform dry runs
--no-sqlite Do not output to an sqlite database
--quiet Do not output to the console
Expand Down
12 changes: 6 additions & 6 deletions backends/src/anchor_ts/mod.rs → backends/src/anchor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use std::{
use subprocess::Exec;
use toml_edit::{DocumentMut, Value};

pub struct AnchorTs {
pub struct Anchor {
mocha_adapter: ParseAdapter<ts::mocha::Mocha>,
anchor_toml: PathBuf,
document: DocumentMut,
prefix: String,
suffix: String,
}

impl AnchorTs {
impl Anchor {
pub fn applicable(context: &LightContext) -> Result<bool> {
context
.root
Expand All @@ -47,9 +47,9 @@ impl AnchorTs {
}
}

impl Interface for AnchorTs {}
impl Interface for Anchor {}

impl ParseHigh for AnchorTs {
impl ParseHigh for Anchor {
fn parse(
&mut self,
context: &LightContext,
Expand All @@ -60,7 +60,7 @@ impl ParseHigh for AnchorTs {
}
}

impl RunHigh for AnchorTs {
impl RunHigh for Anchor {
fn dry_run(&self, context: &LightContext, source_file: &Path) -> Result<()> {
ts::utils::install_node_modules(context)?;

Expand Down Expand Up @@ -134,7 +134,7 @@ impl RunHigh for AnchorTs {
}
}

impl AnchorTs {
impl Anchor {
fn check(&self, context: &LightContext, source_file: &Path) -> Result<()> {
let _backup: Backup = self.patch_anchor_toml(source_file, true)?;

Expand Down
10 changes: 5 additions & 5 deletions backends/src/hardhat_ts/mod.rs → backends/src/hardhat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use necessist_core::{
use std::path::Path;
use subprocess::Exec;

pub struct HardhatTs {
pub struct Hardhat {
mocha_adapter: ParseAdapter<ts::mocha::Mocha>,
}

impl HardhatTs {
impl Hardhat {
pub fn applicable(context: &LightContext) -> Result<bool> {
context
.root
Expand All @@ -28,9 +28,9 @@ impl HardhatTs {
}
}

impl Interface for HardhatTs {}
impl Interface for Hardhat {}

impl ParseHigh for HardhatTs {
impl ParseHigh for Hardhat {
fn parse(
&mut self,
context: &LightContext,
Expand All @@ -41,7 +41,7 @@ impl ParseHigh for HardhatTs {
}
}

impl RunHigh for HardhatTs {
impl RunHigh for Hardhat {
fn dry_run(&self, context: &LightContext, source_file: &Path) -> Result<()> {
ts::utils::install_node_modules(context)?;

Expand Down
26 changes: 14 additions & 12 deletions backends/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ use subprocess::Exec;

// Framework modules

mod anchor_ts;
use anchor_ts::AnchorTs;
mod anchor;
use anchor::Anchor;

mod foundry;
use foundry::Foundry;

mod go;
use go::Go;

mod hardhat_ts;
use hardhat_ts::HardhatTs;
mod hardhat;
use hardhat::Hardhat;

mod rust;
use rust::Rust;
Expand All @@ -50,32 +50,34 @@ use utils::{OutputAccessors, OutputStrippedOfAnsiScapes};
#[non_exhaustive]
#[remain::sorted]
pub enum Identifier {
AnchorTs,
#[value(alias("anchor-ts"))]
Anchor,
Foundry,
Go,
HardhatTs,
#[value(alias("hardhat-ts"))]
Hardhat,
Rust,
}

impl Applicable for Identifier {
fn applicable(&self, context: &LightContext) -> Result<bool> {
match *self {
Self::AnchorTs => AnchorTs::applicable(context),
Self::Anchor => Anchor::applicable(context),
Self::Foundry => Foundry::applicable(context),
Self::Go => Go::applicable(context),
Self::HardhatTs => HardhatTs::applicable(context),
Self::Hardhat => Hardhat::applicable(context),
Self::Rust => Rust::applicable(context),
}
}
}

impl ToImplementation for Identifier {
// smoelius: `AnchorTs` and `HardhatTs` implement the `ParseLow` interface indirectly through
// smoelius: `Anchor` and `Hardhat` implement the `ParseLow` interface indirectly through
// `ts::Mocha`. They implement the high-level `Run` interface directly.
fn to_implementation(&self, context: &LightContext) -> Result<Option<Box<dyn Interface>>> {
match *self {
Self::AnchorTs => {
let anchor = AnchorTs::new(context)?;
Self::Anchor => {
let anchor = Anchor::new(context)?;
Ok(Some(Box::new(anchor)))
}

Expand All @@ -87,7 +89,7 @@ impl ToImplementation for Identifier {
Go::new(),
))),

Self::HardhatTs => Ok(Some(Box::new(HardhatTs::new()))),
Self::Hardhat => Ok(Some(Box::new(Hardhat::new()))),

Self::Rust => Ok(Some(implementation_as_interface(ParseRunAdapter::new)(
Rust::new(),
Expand Down
2 changes: 1 addition & 1 deletion backends/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{any::type_name, cell::RefCell, convert::Infallible, path::Path, rc::Rc
// of the `File`. The lifetime of a `Storage` is only what it takes to parse the `File`. `Storage`
// is wrapped in a `RefCell`.
//
// - framework: Rust, HardhatTs, etc. Implements the `ParseLow` trait, i.e., contains callbacks such
// - framework: Rust, Hardhat, etc. Implements the `ParseLow` trait, i.e., contains callbacks such
// `statement_is_call`, which are used by the `GenericVisitor` (below). Most callbacks are passed
// a reference to the `Storage`.
//
Expand Down
1 change: 0 additions & 1 deletion necessist/README.md

This file was deleted.

Loading

0 comments on commit de21f2e

Please sign in to comment.