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.
feat(solidity/linter): load solidhunter ignore by default and tests
- Loading branch information
Showing
9 changed files
with
48 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,29 +1,35 @@ | ||
use std::path::Path; | ||
use glob::glob; | ||
use crate::errors::SolidHunterError; | ||
|
||
fn parse_line (line: &str) -> Vec<String> { | ||
fn parse_line(line: &str, path: &Path) -> Vec<String> { | ||
let mut files = Vec::new(); | ||
|
||
if let Ok(entries) = glob(line) { | ||
for entry in entries.flatten() { | ||
files.push(entry.into_os_string().into_string().unwrap()) | ||
let line = line.replace("./", ""); | ||
if let Some(parent) = path.parent() { | ||
if let Some(filepath) = parent.join(line).to_str() { | ||
if let Ok(entries) = glob(filepath) { | ||
for entry in entries.flatten() { | ||
files.push(entry.into_os_string().into_string().unwrap()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
files | ||
} | ||
|
||
pub fn get_ignored_files (filepath: &str) -> Result<Vec<String>, SolidHunterError> { | ||
pub fn get_ignored_files(filepath: &str) -> Result<Vec<String>, SolidHunterError> { | ||
let mut ignored_files = Vec::new(); | ||
let path = Path::new(filepath); | ||
|
||
if !std::path::Path::new(filepath).is_file() { | ||
if !path.is_file() { | ||
return Ok(ignored_files); | ||
} | ||
|
||
let file = std::fs::read_to_string(filepath)?; | ||
let file = std::fs::read_to_string(path)?; | ||
|
||
for line in file.lines() { | ||
ignored_files.append(&mut parse_line(line)) | ||
ignored_files.append(&mut parse_line(line, path)) | ||
} | ||
Ok(ignored_files) | ||
} |
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
8 changes: 8 additions & 0 deletions
8
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/.solidhunter.json
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 @@ | ||
{ | ||
"name": "solidhunter", "rules": [ | ||
{ | ||
"id": "avoid-tx-origin", | ||
"severity": "WARNING" | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/.solidhunterignore
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 @@ | ||
*.sol |
10 changes: 10 additions & 0 deletions
10
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/file.sol
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,10 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
function awesome() public returns (address) { | ||
return tx.origin; | ||
} | ||
function notAwesome() public returns (address) { | ||
return msg.sender; | ||
} | ||
} |
Empty file.
Empty file.
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