From 42933de3ae1939c060bd8d825963cc49f6780017 Mon Sep 17 00:00:00 2001 From: Astrodevs CI Date: Mon, 23 Oct 2023 22:39:41 +0000 Subject: [PATCH 1/7] chore: create branch feature/173-no-project-file-differenciation-staging --- remove-me-721d707bd04a482faf07.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 remove-me-721d707bd04a482faf07.txt diff --git a/remove-me-721d707bd04a482faf07.txt b/remove-me-721d707bd04a482faf07.txt new file mode 100644 index 00000000..a6d71134 --- /dev/null +++ b/remove-me-721d707bd04a482faf07.txt @@ -0,0 +1 @@ +721d707bd04a482faf07 From 4c80cfbcacf7caf4bd5e3a8d27c771b90543f60b Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Wed, 25 Oct 2023 15:59:55 -0400 Subject: [PATCH 2/7] feat(solidity/linter): added a parse path method in linter + cleaning --- .../core/crates/linter-lib/src/linter.rs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/toolchains/solidity/core/crates/linter-lib/src/linter.rs b/toolchains/solidity/core/crates/linter-lib/src/linter.rs index 8e18632a..6066cec1 100644 --- a/toolchains/solidity/core/crates/linter-lib/src/linter.rs +++ b/toolchains/solidity/core/crates/linter-lib/src/linter.rs @@ -7,6 +7,7 @@ use crate::types::*; use std::fs; use glob::glob; +use osmium_libs_solidity_ast_extractor::YulExpr::Path; #[derive(Debug, Clone)] pub struct SolidFile { @@ -91,21 +92,13 @@ impl SolidLinter { } } + pub fn parse_file(&mut self, filepath: String) -> LintResult { let content = fs::read_to_string(filepath.clone())?; - let res = osmium_libs_solidity_ast_extractor::extract::extract_ast_from_content(&content)?; - - self._add_file(filepath.as_str(), res, content.as_str()); - let mut res: Vec = Vec::new(); - - for rule in &self.rules { - let mut diags = rule.diagnose(&self.files[self.files.len() - 1], &self.files); - res.append(&mut diags); - } - Ok(res) + self.parse_content(filepath, content.as_str()) } - pub fn parse_content(&mut self, filepath: String, content: &str) -> LintResult { + fn parse_content(&mut self, filepath: String, content: &str) -> LintResult { let res = osmium_libs_solidity_ast_extractor::extract::extract_ast_from_content(content)?; self._add_file(filepath.as_str(), res, content); @@ -118,7 +111,7 @@ impl SolidLinter { Ok(res) } - pub fn parse_folder(&mut self, folder: String) -> Vec { + fn parse_folder(&mut self, folder: String) -> Vec { let mut result: Vec = Vec::new(); if let Ok(entries) = glob(&(folder + "/**/*.sol")) { for entry in entries.flatten() { @@ -127,6 +120,13 @@ impl SolidLinter { } result } + pub fn parse_path(&mut self, path: String) -> Vec { + return if Path::new(&path).is_file() { + vec!(self.parse_file(path)) + } else { + self.parse_folder(path) + } + } pub fn delete_file(&mut self, path: String) { loop { From b51351180773337b2475a39b59547bdbb2116671 Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Mon, 30 Oct 2023 14:45:37 -0400 Subject: [PATCH 3/7] fix(solidity/linter): fixed path argument in cli and fixed bad import in linter-lib --- .../core/crates/linter-cli/src/main.rs | 73 +++++++------------ .../core/crates/linter-lib/src/linter.rs | 2 +- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/toolchains/solidity/core/crates/linter-cli/src/main.rs b/toolchains/solidity/core/crates/linter-cli/src/main.rs index 2aba0631..2dbdef7f 100644 --- a/toolchains/solidity/core/crates/linter-cli/src/main.rs +++ b/toolchains/solidity/core/crates/linter-cli/src/main.rs @@ -13,15 +13,7 @@ struct Args { default_value = ".", help = "Specify project path" )] - project_path: Vec, - - #[arg( - short = 'f', - long = "file", - default_value = "", - help = "Specify a single file to lint" - )] - file_to_lint: String, + project_path: String, #[arg( short = 'e', @@ -63,28 +55,17 @@ struct Args { init: bool, } -fn lint_folder(args: Args) -> Result<(), SolidHunterError> { - let mut linter: SolidLinter = SolidLinter::new(); - linter.initialize_rules(&args.rules_file)?; - let mut result = Vec::new(); - for path in args.project_path { - result.append(&mut linter.parse_folder(path)); - } - for res in result { - print_result(res); - } - Ok(()) -} - -fn print_result(result: LintResult) { - match result { - Ok(diags) => { - for diag in diags { - println!("{}", &diag); +fn print_result(results: Vec) { + for result in results { + match result { + Ok(diags) => { + for diag in diags { + println!("{}", &diag); + } + } + Err(e) => { + println!("{}", e); } - } - Err(e) => { - println!("{}", e); } } } @@ -118,30 +99,30 @@ fn main() -> Result<(), SolidHunterError> { return Ok(()); } - if !args.to_json && args.file_to_lint.is_empty() { - lint_folder(args)?; - } else if !args.file_to_lint.is_empty() { + if !args.project_path.is_empty() { let mut linter: SolidLinter = SolidLinter::new(); linter.initialize_rules(&args.rules_file)?; - let result = linter.parse_file(args.file_to_lint); + let result = linter.parse_path(args.project_path); if !args.to_json { print_result(result); } else { - match result { - Ok(diags) => { - let json = serde_json::to_string_pretty(&diags); - match json { - Ok(j) => { - println!("{}", j); - } - Err(e) => { - println!("{}", e); + for res in result { + match res { + Ok(diags) => { + let json = serde_json::to_string_pretty(&diags); + match json { + Ok(j) => { + println!("{}", j); + } + Err(e) => { + println!("{}", e); + } } } - } - Err(e) => { - println!("{}", e); + Err(e) => { + println!("{}", e); + } } } } diff --git a/toolchains/solidity/core/crates/linter-lib/src/linter.rs b/toolchains/solidity/core/crates/linter-lib/src/linter.rs index 6066cec1..ccf3358b 100644 --- a/toolchains/solidity/core/crates/linter-lib/src/linter.rs +++ b/toolchains/solidity/core/crates/linter-lib/src/linter.rs @@ -7,7 +7,7 @@ use crate::types::*; use std::fs; use glob::glob; -use osmium_libs_solidity_ast_extractor::YulExpr::Path; +use std::path::Path; #[derive(Debug, Clone)] pub struct SolidFile { From 2fc6fe530324f8aca6b92ab3f951d623a228e906 Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Mon, 30 Oct 2023 15:08:24 -0400 Subject: [PATCH 4/7] fix(solidity/linter): fixed lint errors --- toolchains/solidity/core/crates/linter-lib/src/linter.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/toolchains/solidity/core/crates/linter-lib/src/linter.rs b/toolchains/solidity/core/crates/linter-lib/src/linter.rs index ccf3358b..79af540b 100644 --- a/toolchains/solidity/core/crates/linter-lib/src/linter.rs +++ b/toolchains/solidity/core/crates/linter-lib/src/linter.rs @@ -92,13 +92,12 @@ impl SolidLinter { } } - pub fn parse_file(&mut self, filepath: String) -> LintResult { let content = fs::read_to_string(filepath.clone())?; self.parse_content(filepath, content.as_str()) } - fn parse_content(&mut self, filepath: String, content: &str) -> LintResult { + pub fn parse_content(&mut self, filepath: String, content: &str) -> LintResult { let res = osmium_libs_solidity_ast_extractor::extract::extract_ast_from_content(content)?; self._add_file(filepath.as_str(), res, content); @@ -111,7 +110,7 @@ impl SolidLinter { Ok(res) } - fn parse_folder(&mut self, folder: String) -> Vec { + pub fn parse_folder(&mut self, folder: String) -> Vec { let mut result: Vec = Vec::new(); if let Ok(entries) = glob(&(folder + "/**/*.sol")) { for entry in entries.flatten() { @@ -121,8 +120,8 @@ impl SolidLinter { result } pub fn parse_path(&mut self, path: String) -> Vec { - return if Path::new(&path).is_file() { - vec!(self.parse_file(path)) + if Path::new(&path).is_file() { + vec![self.parse_file(path)] } else { self.parse_folder(path) } From 2537c9e45c237b1f551f831e98dc3d68761555d2 Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Thu, 2 Nov 2023 17:29:56 -0400 Subject: [PATCH 5/7] feat(solidity/linter/cli): updated version as breaking change and deleted remove-me --- remove-me-721d707bd04a482faf07.txt | 1 - toolchains/solidity/core/crates/linter-cli/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 remove-me-721d707bd04a482faf07.txt diff --git a/remove-me-721d707bd04a482faf07.txt b/remove-me-721d707bd04a482faf07.txt deleted file mode 100644 index a6d71134..00000000 --- a/remove-me-721d707bd04a482faf07.txt +++ /dev/null @@ -1 +0,0 @@ -721d707bd04a482faf07 diff --git a/toolchains/solidity/core/crates/linter-cli/Cargo.toml b/toolchains/solidity/core/crates/linter-cli/Cargo.toml index d929a24d..ae6e7b2b 100644 --- a/toolchains/solidity/core/crates/linter-cli/Cargo.toml +++ b/toolchains/solidity/core/crates/linter-cli/Cargo.toml @@ -2,7 +2,7 @@ name = "solidhunter" description = "Fast solidity linter cli" repository = "https://github.com/astrodevs-labs/osmium" -version = "0.0.3" +version = "0.1.0" edition = "2021" license = "GPL-3.0-or-later" From 4df7fbc64320cf0f65f97260043faf55d528fbea Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Thu, 2 Nov 2023 18:15:14 -0400 Subject: [PATCH 6/7] fix(solidty/linter/cli): fixed path argument cli --- .../solidity/core/crates/linter-cli/Cargo.toml | 2 +- .../core/crates/linter-cli/src/main.rs | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/toolchains/solidity/core/crates/linter-cli/Cargo.toml b/toolchains/solidity/core/crates/linter-cli/Cargo.toml index ae6e7b2b..37c03646 100644 --- a/toolchains/solidity/core/crates/linter-cli/Cargo.toml +++ b/toolchains/solidity/core/crates/linter-cli/Cargo.toml @@ -5,7 +5,7 @@ repository = "https://github.com/astrodevs-labs/osmium" version = "0.1.0" edition = "2021" license = "GPL-3.0-or-later" - +authors = ["AstroDevs-Labs"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/toolchains/solidity/core/crates/linter-cli/src/main.rs b/toolchains/solidity/core/crates/linter-cli/src/main.rs index 2dbdef7f..c713ec22 100644 --- a/toolchains/solidity/core/crates/linter-cli/src/main.rs +++ b/toolchains/solidity/core/crates/linter-cli/src/main.rs @@ -1,4 +1,4 @@ -use clap::Parser; +use clap::{arg, Parser}; use solidhunter_lib::errors::SolidHunterError; use solidhunter_lib::linter::SolidLinter; use solidhunter_lib::rules::rule_impl::create_rules_file; @@ -8,13 +8,11 @@ use solidhunter_lib::types::LintResult; #[command(author, version, about, long_about = None)] struct Args { #[arg( - short = 'p', - long = "path", + required = false, default_value = ".", - help = "Specify project path" + help = "Path to the project to lint" )] - project_path: String, - + path: String, #[arg( short = 'e', long = "exclude", @@ -32,7 +30,7 @@ struct Args { #[arg( short = 'j', - long = "json_output", + long = "json", default_value = "false", help = "Outputs a json format instead" )] @@ -86,7 +84,7 @@ fn main() -> Result<(), SolidHunterError> { if args.verbose { println!("Verbose output enabled"); - println!("Project path: {:?}", args.project_path); + println!("Project path: {:?}", args.path); println!("Exclude path: {:?}", args.ignore_path); println!("Using rules file: {}", args.rules_file); println!("Verbose output: {}", args.verbose); @@ -99,11 +97,11 @@ fn main() -> Result<(), SolidHunterError> { return Ok(()); } - if !args.project_path.is_empty() { + if args.path.is_empty() { let mut linter: SolidLinter = SolidLinter::new(); linter.initialize_rules(&args.rules_file)?; - let result = linter.parse_path(args.project_path); + let result = linter.parse_path(args.path); if !args.to_json { print_result(result); } else { From 7a497c4390a31e7619e320a418c7379ab2a6e68a Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Thu, 2 Nov 2023 18:48:29 -0400 Subject: [PATCH 7/7] feat(solidity/linter/lib): updated version --- toolchains/solidity/core/crates/linter-cli/Cargo.toml | 2 +- toolchains/solidity/core/crates/linter-lib/Cargo.toml | 2 +- toolchains/solidity/core/crates/linter-server/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/toolchains/solidity/core/crates/linter-cli/Cargo.toml b/toolchains/solidity/core/crates/linter-cli/Cargo.toml index 37c03646..99a84c6f 100644 --- a/toolchains/solidity/core/crates/linter-cli/Cargo.toml +++ b/toolchains/solidity/core/crates/linter-cli/Cargo.toml @@ -9,7 +9,7 @@ authors = ["AstroDevs-Labs"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -solidhunter-lib = { path = "../linter-lib", version = "0.0.3" } +solidhunter-lib = { path = "../linter-lib", version = "0.0.4" } clap = { version = "4.0.29", features = ["derive"] } colored = "2" serde = { version = "1.0.149", features = ["derive"] } diff --git a/toolchains/solidity/core/crates/linter-lib/Cargo.toml b/toolchains/solidity/core/crates/linter-lib/Cargo.toml index 86b68ed2..ab114db9 100644 --- a/toolchains/solidity/core/crates/linter-lib/Cargo.toml +++ b/toolchains/solidity/core/crates/linter-lib/Cargo.toml @@ -2,7 +2,7 @@ name = "solidhunter-lib" description = "Solidhunter/Osmium solidity linter library" repository = "https://github.com/astrodevs-labs/osmium" -version = "0.0.3" +version = "0.0.4" edition = "2021" authors = ["Astrodevs Labs"] license = "GPL-3.0-or-later" diff --git a/toolchains/solidity/core/crates/linter-server/Cargo.toml b/toolchains/solidity/core/crates/linter-server/Cargo.toml index 5939bc56..d45dd078 100644 --- a/toolchains/solidity/core/crates/linter-server/Cargo.toml +++ b/toolchains/solidity/core/crates/linter-server/Cargo.toml @@ -11,5 +11,5 @@ crate-type = ["cdylib", "rlib"] [dependencies] osmium-libs-lsp-handler = { path = "../../../../../libs/lsp-handler", version = "0.0.2" } -solidhunter-lib = { path = "../linter-lib", version = "0.0.3" } +solidhunter-lib = { path = "../linter-lib", version = "0.0.4" } js-sys = "0.3.64" \ No newline at end of file