-
Notifications
You must be signed in to change notification settings - Fork 5
implemented new changes regarding issue 5 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use regex::Regex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::collections::HashSet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::collections::HashMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::fs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::io; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn extract_env_variables(source: &str) -> Vec<String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,4 +33,54 @@ pub fn extract_env_variables(source: &str) -> Vec<String> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut result: Vec<String> = vars.into_iter().collect(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result.sort(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn parse_env_file(path: &str) -> io::Result<HashMap<String, String>> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let content = fs::read_to_string(path)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut vars = HashMap::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for line in content.lines() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let line = line.trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if line.is_empty() || line.starts_with('#') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some((key, value)) = line.split_once('=') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vars.insert( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key.trim().to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value.trim().to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok(vars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn validate_env( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extracted: &[String], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: &HashMap<String, String>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("Validation Report"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("\nMissing Variables:"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for var in extracted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !env.contains_key(var) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("- {}", var); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("\nUnused Variables:"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for key in env.keys() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !extracted.contains(key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("- {}", key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("\nEmpty Variables:"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (key, value) in env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if value.trim().is_empty() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| println!("- {}", key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Sort report entries before printing. Lines 74-83 iterate Suggested fix println!("\nUnused Variables:");
- for key in env.keys() {
- if !extracted.contains(key) {
- println!("- {}", key);
- }
- }
+ let mut unused: Vec<_> = env
+ .keys()
+ .filter(|key| !extracted.contains(*key))
+ .cloned()
+ .collect();
+ unused.sort();
+ for key in unused {
+ println!("- {}", key);
+ }
println!("\nEmpty Variables:");
- for (key, value) in env {
- if value.trim().is_empty() {
- println!("- {}", key);
- }
- }
+ let mut empty: Vec<_> = env
+ .iter()
+ .filter(|(_, value)| value.trim().is_empty())
+ .map(|(key, _)| key.clone())
+ .collect();
+ empty.sort();
+ for key in empty {
+ println!("- {}", key);
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| mod env_validator; | ||
|
|
||
| fn main() { | ||
| println!("issue 4!!!"); | ||
| println!("issue 4/5/6 solution"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject malformed env records instead of skipping them.
Any non-empty, non-comment line without
=is silently dropped here, and=valueis accepted with an empty key. That turns env-file typos into missing configuration while still returningOk(...).Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents