Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix(solidity/linter/core): now run foundry naming rule on public and …
Browse files Browse the repository at this point in the history
…external functions only
  • Loading branch information
0xmemorygrinder committed Oct 9, 2023
1 parent 5f5bbb8 commit 70fa9b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ impl RuleType for FoundryFuncName {

for contract in contracts {
for function in ast_extractor::retriever::retrieve_functions_nodes(&contract) {
let visibility = function.attributes.iter().find(|attr| matches!(attr, ast_extractor::FunctionAttribute::Visibility(_)));
let visibility = match visibility {
Some(ast_extractor::FunctionAttribute::Visibility(visibility)) => visibility,
_ => continue,
};

if !matches!(visibility, ast_extractor::Visibility::Public(_)) && !matches!(visibility, ast_extractor::Visibility::External(_)) {
continue;
}
if let Some(name) = function.name {
if !re.is_match(&name.as_string()) && !self.excluded.contains(&name.as_string()) {
let span = name.span();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
pragma solidity 0.8.0;

contract Test {
function testFail_Add42() external {} // should pass

function test_NumberIs42() public {} // should pass

function testFail_Subtract43() public {} // should pass

function testFuzz_FuzzyTest() public {} // should pass

function numberIs42() public {} // should fail

function YoloNamingBecauseSkipped() internal {} // should pass

function YoloNamingBacausePrivate() private {} // should pass
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foundry-func-name:10:13:10:23
foundry-func-name:12:13:12:23

0 comments on commit 70fa9b5

Please sign in to comment.