Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move lints to workspace #149

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ keywords = ["foundry", "solidity", "solc", "ethereum", "ethers"]
edition = "2021"
exclude = [".github/", "scripts/", "test-data/"]

[workspace.lints.clippy]
dbg-macro = "warn"
manual-string-new = "warn"
uninlined-format-args = "warn"
use-self = "warn"

[workspace.lints.rust]
rust-2018-idioms = "deny"
# unreachable-pub = "warn"
unused-must-use = "deny"

[workspace.lints.rustdoc]
all = "warn"

[workspace.dependencies]
foundry-compilers-artifacts-solc = { path = "crates/artifacts/solc", version = "0.7.0" }
foundry-compilers-artifacts-vyper = { path = "crates/artifacts/vyper", version = "0.7.0" }
Expand Down
10 changes: 3 additions & 7 deletions crates/artifacts/artifacts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true
[lints]
workspace = true

[dependencies]
foundry-compilers-artifacts-solc.workspace = true
foundry-compilers-artifacts-vyper.workspace = true

[features]
async = ["foundry-compilers-artifacts-solc/async"]
async = ["foundry-compilers-artifacts-solc/async"]
1 change: 1 addition & 0 deletions crates/artifacts/artifacts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Meta crate reexporting all artifacts types.

#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

pub use foundry_compilers_artifacts_solc as solc;
pub use foundry_compilers_artifacts_vyper as vyper;
Expand Down
8 changes: 2 additions & 6 deletions crates/artifacts/solc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true
[lints]
workspace = true

[dependencies]
foundry-compilers-core.workspace = true
Expand Down
58 changes: 29 additions & 29 deletions crates/artifacts/solc/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ impl CompactBytecode {
}

impl From<Bytecode> for CompactBytecode {
fn from(bcode: Bytecode) -> CompactBytecode {
CompactBytecode {
fn from(bcode: Bytecode) -> Self {
Self {
object: bcode.object,
source_map: bcode.source_map,
link_references: bcode.link_references,
Expand All @@ -114,8 +114,8 @@ impl From<Bytecode> for CompactBytecode {
}

impl From<CompactBytecode> for Bytecode {
fn from(bcode: CompactBytecode) -> Bytecode {
Bytecode {
fn from(bcode: CompactBytecode) -> Self {
Self {
object: bcode.object,
source_map: bcode.source_map,
link_references: bcode.link_references,
Expand All @@ -127,8 +127,8 @@ impl From<CompactBytecode> for Bytecode {
}

impl From<BytecodeObject> for Bytecode {
fn from(object: BytecodeObject) -> Bytecode {
Bytecode {
fn from(object: BytecodeObject) -> Self {
Self {
object,
function_debug_data: Default::default(),
opcodes: Default::default(),
Expand Down Expand Up @@ -243,16 +243,16 @@ impl BytecodeObject {
/// Returns a reference to the underlying `Bytes` if the object is a valid bytecode.
pub fn as_bytes(&self) -> Option<&Bytes> {
match self {
BytecodeObject::Bytecode(bytes) => Some(bytes),
BytecodeObject::Unlinked(_) => None,
Self::Bytecode(bytes) => Some(bytes),
Self::Unlinked(_) => None,
}
}

/// Returns the underlying `Bytes` if the object is a valid bytecode.
pub fn into_bytes(self) -> Option<Bytes> {
match self {
BytecodeObject::Bytecode(bytes) => Some(bytes),
BytecodeObject::Unlinked(_) => None,
Self::Bytecode(bytes) => Some(bytes),
Self::Unlinked(_) => None,
}
}

Expand All @@ -266,27 +266,27 @@ impl BytecodeObject {
/// Returns a reference to the underlying `String` if the object is unlinked.
pub fn as_str(&self) -> Option<&str> {
match self {
BytecodeObject::Bytecode(_) => None,
BytecodeObject::Unlinked(s) => Some(s.as_str()),
Self::Bytecode(_) => None,
Self::Unlinked(s) => Some(s.as_str()),
}
}

/// Returns the unlinked `String` if the object is unlinked.
pub fn into_unlinked(self) -> Option<String> {
match self {
BytecodeObject::Bytecode(_) => None,
BytecodeObject::Unlinked(code) => Some(code),
Self::Bytecode(_) => None,
Self::Unlinked(code) => Some(code),
}
}

/// Whether this object is still unlinked.
pub fn is_unlinked(&self) -> bool {
matches!(self, BytecodeObject::Unlinked(_))
matches!(self, Self::Unlinked(_))
}

/// Whether this object a valid bytecode.
pub fn is_bytecode(&self) -> bool {
matches!(self, BytecodeObject::Bytecode(_))
matches!(self, Self::Bytecode(_))
}

/// Returns `true` if the object is a valid bytecode and not empty.
Expand All @@ -300,9 +300,9 @@ impl BytecodeObject {
///
/// Returns the string if it is a valid
pub fn resolve(&mut self) -> Option<&Bytes> {
if let BytecodeObject::Unlinked(unlinked) = self {
if let Self::Unlinked(unlinked) = self {
if let Ok(linked) = hex::decode(unlinked) {
*self = BytecodeObject::Bytecode(linked.into());
*self = Self::Bytecode(linked.into());
}
}
self.as_bytes()
Expand All @@ -317,7 +317,7 @@ impl BytecodeObject {
///
/// See also: <https://docs.soliditylang.org/en/develop/using-the-compiler.html#library-linking>
pub fn link_fully_qualified(&mut self, name: impl AsRef<str>, addr: Address) -> &mut Self {
if let BytecodeObject::Unlinked(ref mut unlinked) = self {
if let Self::Unlinked(ref mut unlinked) = self {
let name = name.as_ref();
let place_holder = utils::library_hash_placeholder(name);
// the address as hex without prefix
Expand Down Expand Up @@ -361,7 +361,7 @@ impl BytecodeObject {

/// Returns whether the bytecode contains a matching placeholder using the qualified name.
pub fn contains_fully_qualified_placeholder(&self, name: impl AsRef<str>) -> bool {
if let BytecodeObject::Unlinked(unlinked) = self {
if let Self::Unlinked(unlinked) = self {
let name = name.as_ref();
unlinked.contains(&utils::library_hash_placeholder(name))
|| unlinked.contains(&utils::library_fully_qualified_placeholder(name))
Expand All @@ -379,15 +379,15 @@ impl BytecodeObject {
// Returns an empty bytecode object
impl Default for BytecodeObject {
fn default() -> Self {
BytecodeObject::Bytecode(Default::default())
Self::Bytecode(Default::default())
}
}

impl AsRef<[u8]> for BytecodeObject {
fn as_ref(&self) -> &[u8] {
match self {
BytecodeObject::Bytecode(code) => code.as_ref(),
BytecodeObject::Unlinked(code) => code.as_bytes(),
Self::Bytecode(code) => code.as_ref(),
Self::Unlinked(code) => code.as_bytes(),
}
}
}
Expand Down Expand Up @@ -436,8 +436,8 @@ impl DeployedBytecode {
}

impl From<Bytecode> for DeployedBytecode {
fn from(bcode: Bytecode) -> DeployedBytecode {
DeployedBytecode { bytecode: Some(bcode), immutable_references: Default::default() }
fn from(bcode: Bytecode) -> Self {
Self { bytecode: Some(bcode), immutable_references: Default::default() }
}
}

Expand Down Expand Up @@ -480,17 +480,17 @@ impl CompactDeployedBytecode {
}

impl From<DeployedBytecode> for CompactDeployedBytecode {
fn from(bcode: DeployedBytecode) -> CompactDeployedBytecode {
CompactDeployedBytecode {
fn from(bcode: DeployedBytecode) -> Self {
Self {
bytecode: bcode.bytecode.map(|d_bcode| d_bcode.into()),
immutable_references: bcode.immutable_references,
}
}
}

impl From<CompactDeployedBytecode> for DeployedBytecode {
fn from(bcode: CompactDeployedBytecode) -> DeployedBytecode {
DeployedBytecode {
fn from(bcode: CompactDeployedBytecode) -> Self {
Self {
bytecode: bcode.bytecode.map(|d_bcode| d_bcode.into()),
immutable_references: bcode.immutable_references,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/artifacts/solc/src/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl ConfigurableContractArtifact {

impl From<ConfigurableContractArtifact> for CompactContractBytecode {
fn from(artifact: ConfigurableContractArtifact) -> Self {
CompactContractBytecode {
Self {
abi: artifact.abi.map(Into::into),
bytecode: artifact.bytecode,
deployed_bytecode: artifact.deployed_bytecode,
Expand Down
2 changes: 1 addition & 1 deletion crates/artifacts/solc/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl From<serde_json::Value> for CompactContract {
map.remove("bin-runtime").and_then(|val| serde_json::from_value(val).ok());
Self { abi, bin, bin_runtime }
} else {
CompactContract::default()
Self::default()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/artifacts/solc/src/hh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> From<&'a HardhatArtifact> for CompactContractBytecodeCow<'a> {

impl From<HardhatArtifact> for CompactContract {
fn from(artifact: HardhatArtifact) -> Self {
CompactContract {
Self {
abi: Some(artifact.abi),
bin: artifact.bytecode,
bin_runtime: artifact.deployed_bytecode,
Expand All @@ -73,7 +73,7 @@ impl From<HardhatArtifact> for ContractBytecode {
bcode.into()
});

ContractBytecode { abi: Some(artifact.abi), bytecode, deployed_bytecode }
Self { abi: Some(artifact.abi), bytecode, deployed_bytecode }
}
}

Expand Down
Loading