This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(solidity/linter/core): corrected reason string end character
chore(solidity/linter/core): removed useless default data for reason string
- Loading branch information
1 parent
bccb3d5
commit ba700c1
Showing
5 changed files
with
78 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,6 @@ mod stmts; | |
pub use stmts::*; | ||
|
||
pub use finder::*; | ||
|
||
mod expr_call; | ||
pub use expr_call::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* expr_call.rs | ||
* Function to retrieve expr calls from AST | ||
* author: EnergyCube | ||
* | ||
* !!! UNTESTED !!! | ||
*/ | ||
use syn_solidity::{ExprCall, Visit}; | ||
|
||
struct CallVisitor { | ||
calls: Vec<ExprCall>, | ||
} | ||
|
||
impl CallVisitor { | ||
pub fn new() -> Self { | ||
Self { calls: Vec::new() } | ||
} | ||
} | ||
|
||
impl<'ast> Visit<'ast> for CallVisitor { | ||
fn visit_expr_call(&mut self, i: &ExprCall) { | ||
self.calls.push(i.clone()); | ||
syn_solidity::visit::visit_expr_call(self, i); | ||
} | ||
} | ||
|
||
pub fn retrieve_expr_call_nodes(ast: &syn_solidity::File) -> Vec<ExprCall> { | ||
let mut visitor = CallVisitor::new(); | ||
visitor.visit_file(ast); | ||
visitor.calls | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use proc_macro2::TokenStream; | ||
|
||
use super::*; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::str::FromStr; | ||
|
||
#[test] | ||
fn test_retrieve_expr_call_nodes_empty() { | ||
let source = String::from("pragma solidity ^0.8.0;"); | ||
let tokens = TokenStream::from_str(source.as_str()).unwrap(); | ||
let ast = syn_solidity::parse2(tokens).unwrap(); | ||
let res = retrieve_expr_call_nodes(&ast); | ||
assert_eq!(res.len(), 0); | ||
} | ||
|
||
#[test] | ||
fn test_retrieve_expr_call_nodes_one() { | ||
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
path.push("tests"); | ||
path.push("files"); | ||
path.push("expr_calls"); | ||
path.push("one.sol"); | ||
let source = fs::read_to_string(path).unwrap(); | ||
let tokens = TokenStream::from_str(source.as_str()).unwrap(); | ||
let ast = syn_solidity::parse2(tokens).unwrap(); | ||
let res = retrieve_expr_call_nodes(&ast); | ||
assert_eq!(res.len(), 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
contract One { | ||
|
||
function emptyfn() public { } | ||
|
||
function emptyCall() public { | ||
emptyCall(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
toolchains/solidity/linter/core/solidhunter-lib/testdata/ReasonString/findings.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
reason-string:8:37:8:133 | ||
reason-string:8:37:8:75 | ||
reason-string:11:8:11:15 |