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.
merge: PR #195 from feature/185-ignore-linting-file-staging
185 - Ignore linting file
- Loading branch information
Showing
23 changed files
with
202 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 @@ | ||
.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
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
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
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
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,63 @@ | ||
use crate::errors::SolidHunterError; | ||
use glob::glob; | ||
use std::path::Path; | ||
|
||
fn parse_line(line: &str, path: &Path) -> Vec<String> { | ||
let mut files = Vec::new(); | ||
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 | ||
} | ||
|
||
fn parse_solihunterignore(filepath: &String) -> Result<Vec<String>, SolidHunterError> { | ||
let mut excluded_files = Vec::new(); | ||
let content = std::fs::read_to_string(filepath)?; | ||
|
||
for line in content.lines() { | ||
excluded_files.append(&mut parse_line(line, Path::new(filepath))); | ||
} | ||
|
||
Ok(excluded_files) | ||
} | ||
|
||
fn get_solidhunterignore_paths(filepath: &String) -> Result<Vec<String>, SolidHunterError> { | ||
let mut ignored_files = Vec::new(); | ||
|
||
if let Ok(entries) = glob(&format!("{}/**/.solidhunterignore", filepath)) { | ||
for entry in entries.flatten() { | ||
ignored_files.push(entry.into_os_string().into_string().unwrap()) | ||
} | ||
} | ||
|
||
Ok(ignored_files) | ||
} | ||
|
||
pub fn get_excluded_files(filepaths: &Vec<String>) -> Result<Vec<String>, SolidHunterError> { | ||
let mut excluded_files = Vec::new(); | ||
|
||
for filepath in filepaths { | ||
let path = Path::new(filepath); | ||
|
||
if path.is_file() { | ||
continue; | ||
} | ||
|
||
let solidhunterignore_paths = get_solidhunterignore_paths(filepath)?; | ||
|
||
for solidhunterignore_path in solidhunterignore_paths { | ||
if let Ok(mut excluded) = parse_solihunterignore(&solidhunterignore_path) { | ||
excluded_files.append(&mut excluded); | ||
} | ||
} | ||
} | ||
Ok(excluded_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod errors; | ||
mod ignore; | ||
pub mod linter; | ||
pub mod rules; | ||
pub mod types; |
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": "const-name-snakecase", | ||
"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 @@ | ||
test/test.sol |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
1 change: 1 addition & 0 deletions
1
...s/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test/.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 @@ | ||
./test2.sol |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test/test.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test/test2.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test2.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
1 change: 1 addition & 0 deletions
1
.../solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test2/.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 |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test2/test.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
5 changes: 5 additions & 0 deletions
5
toolchains/solidity/core/crates/linter-lib/testdata/SolidhunterIgnore/test/test2/test2.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,5 @@ | ||
pragma solidity 0.8.0; | ||
|
||
contract Test { | ||
string public constant symbol = "TEST"; | ||
} |
Oops, something went wrong.