-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat: apply transforms on stdin #320
Conversation
Warning Rate Limit Exceeded@morgante has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 13 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe changes across various files in the CLI tool primarily focus on enhancing the flexibility and functionality of applying transformations. Key updates include direct application from stdin, the introduction of a new Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
crates/cli/src/commands/apply_pattern.rs (1)
Line range hint
16-16
: Unused import detected:log::debug
. This import should be removed if it's not being used in the file to keep the code clean and maintainable.- use log::debug;
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.
Actionable comments posted: 1
Out of diff range and nitpick comments (1)
crates/cli/src/analyze.rs (1)
146-146
: Ensure theApplyInput
parameter is properly documented.The
ApplyInput
parameter has been changed from a reference to a value type. Please ensure that this change is documented, especially since it affects how the function is called and how data is passed to it.
"Skipped {} since it is not a {} file", | ||
path_string, | ||
&compiled.language.to_string() | ||
), | ||
position: Position::first(), | ||
file: path_string.to_string(), | ||
engine_id: "marzano".to_string(), | ||
range: None, | ||
syntax_tree: None, | ||
source: None, | ||
}); | ||
let done_file = MatchResult::DoneFile(DoneFile { | ||
relative_file_path: path_string, | ||
has_results: Some(false), | ||
file_hash: None, | ||
from_cache: false, | ||
}); | ||
emitter.handle_results( | ||
vec![log, done_file], | ||
details, | ||
arg.dry_run, | ||
min_level, | ||
arg.format, | ||
&mut interactive, | ||
None, | ||
Some(processed), | ||
None, | ||
&compiled.language, | ||
); | ||
let file_walker = emit_error!( | ||
owned_emitter, | ||
&arg.visibility, | ||
expand_paths(&my_input.paths, Some(&[(&compiled.language).into()])) | ||
); | ||
|
||
for file in file_walker { | ||
let file = emit_error!(owned_emitter, &arg.visibility, file); | ||
if file.file_type().unwrap().is_dir() { | ||
continue; | ||
} | ||
if !&compiled.language.match_extension( | ||
file.path() | ||
.extension() | ||
.unwrap_or_default() | ||
.to_str() | ||
.unwrap_or_default(), | ||
) { | ||
processed.fetch_add(1, Ordering::SeqCst); | ||
let path_string = file.path().to_string_lossy().to_string(); | ||
if my_input.paths.contains(&file.path().to_path_buf()) { | ||
let log = MatchResult::AnalysisLog(AnalysisLog { | ||
level: 410, | ||
message: format!( | ||
"Skipped {} since it is not a {} file", | ||
path_string, | ||
&compiled.language.to_string() | ||
), | ||
position: Position::first(), | ||
file: path_string.to_string(), | ||
engine_id: "marzano".to_string(), | ||
range: None, | ||
syntax_tree: None, | ||
source: None, | ||
}); | ||
let done_file = MatchResult::DoneFile(DoneFile { | ||
relative_file_path: path_string, | ||
has_results: Some(false), | ||
file_hash: None, | ||
from_cache: false, | ||
}); | ||
emitter.handle_results( | ||
vec![log, done_file], | ||
details, | ||
arg.dry_run, | ||
min_level, | ||
arg.format, | ||
&mut interactive, | ||
None, | ||
Some(processed), | ||
None, | ||
&compiled.language, | ||
); | ||
} | ||
continue; | ||
} | ||
file_paths_tx.send(file.path().to_path_buf()).unwrap(); | ||
} | ||
continue; | ||
} | ||
file_paths_tx.send(file.path().to_path_buf()).unwrap(); | ||
} | ||
|
||
drop(file_paths_tx); | ||
drop(file_paths_tx); | ||
|
||
let found_paths = file_paths_rx.iter().collect::<Vec<_>>(); | ||
(found_paths.len(), Some(found_paths)) | ||
} | ||
ApplyInput::Virtual(ref virtual_info) => (virtual_info.files.len(), None), | ||
}; |
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.
Refactor to reduce complexity and improve readability.
The handling of ApplyInput::Disk
and ApplyInput::Virtual
within the match
statement is quite complex and lengthy. Consider refactoring this into separate functions or methods to handle each case. This would improve readability and maintainability of the code.
- let (found_count, disk_paths) = match my_input {
- ApplyInput::Disk(ref my_input) => {
- // existing code...
- }
- ApplyInput::Virtual(ref virtual_info) => (virtual_info.files.len(), None),
- };
+ let (found_count, disk_paths) = handle_input(my_input);
And then define handle_input
function elsewhere in the module.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
let (found_count, disk_paths) = match my_input { | |
ApplyInput::Disk(ref my_input) => { | |
let (file_paths_tx, file_paths_rx) = channel(); | |
for file in file_walker { | |
let file = emit_error!(owned_emitter, &arg.visibility, file); | |
if file.file_type().unwrap().is_dir() { | |
continue; | |
} | |
if !&compiled.language.match_extension( | |
file.path() | |
.extension() | |
.unwrap_or_default() | |
.to_str() | |
.unwrap_or_default(), | |
) { | |
processed.fetch_add(1, Ordering::SeqCst); | |
let path_string = file.path().to_string_lossy().to_string(); | |
if my_input.paths.contains(&file.path().to_path_buf()) { | |
let log = MatchResult::AnalysisLog(AnalysisLog { | |
level: 410, | |
message: format!( | |
"Skipped {} since it is not a {} file", | |
path_string, | |
&compiled.language.to_string() | |
), | |
position: Position::first(), | |
file: path_string.to_string(), | |
engine_id: "marzano".to_string(), | |
range: None, | |
syntax_tree: None, | |
source: None, | |
}); | |
let done_file = MatchResult::DoneFile(DoneFile { | |
relative_file_path: path_string, | |
has_results: Some(false), | |
file_hash: None, | |
from_cache: false, | |
}); | |
emitter.handle_results( | |
vec![log, done_file], | |
details, | |
arg.dry_run, | |
min_level, | |
arg.format, | |
&mut interactive, | |
None, | |
Some(processed), | |
None, | |
&compiled.language, | |
); | |
let file_walker = emit_error!( | |
owned_emitter, | |
&arg.visibility, | |
expand_paths(&my_input.paths, Some(&[(&compiled.language).into()])) | |
); | |
for file in file_walker { | |
let file = emit_error!(owned_emitter, &arg.visibility, file); | |
if file.file_type().unwrap().is_dir() { | |
continue; | |
} | |
if !&compiled.language.match_extension( | |
file.path() | |
.extension() | |
.unwrap_or_default() | |
.to_str() | |
.unwrap_or_default(), | |
) { | |
processed.fetch_add(1, Ordering::SeqCst); | |
let path_string = file.path().to_string_lossy().to_string(); | |
if my_input.paths.contains(&file.path().to_path_buf()) { | |
let log = MatchResult::AnalysisLog(AnalysisLog { | |
level: 410, | |
message: format!( | |
"Skipped {} since it is not a {} file", | |
path_string, | |
&compiled.language.to_string() | |
), | |
position: Position::first(), | |
file: path_string.to_string(), | |
engine_id: "marzano".to_string(), | |
range: None, | |
syntax_tree: None, | |
source: None, | |
}); | |
let done_file = MatchResult::DoneFile(DoneFile { | |
relative_file_path: path_string, | |
has_results: Some(false), | |
file_hash: None, | |
from_cache: false, | |
}); | |
emitter.handle_results( | |
vec![log, done_file], | |
details, | |
arg.dry_run, | |
min_level, | |
arg.format, | |
&mut interactive, | |
None, | |
Some(processed), | |
None, | |
&compiled.language, | |
); | |
} | |
continue; | |
} | |
file_paths_tx.send(file.path().to_path_buf()).unwrap(); | |
} | |
continue; | |
} | |
file_paths_tx.send(file.path().to_path_buf()).unwrap(); | |
} | |
drop(file_paths_tx); | |
drop(file_paths_tx); | |
let found_paths = file_paths_rx.iter().collect::<Vec<_>>(); | |
(found_paths.len(), Some(found_paths)) | |
} | |
ApplyInput::Virtual(ref virtual_info) => (virtual_info.files.len(), None), | |
}; | |
let (found_count, disk_paths) = handle_input(my_input); |
Fixes #300
Summary by CodeRabbit
New Features
Transformed
to enhance result formatting capabilities.Enhancements
Bug Fixes
Refactor
Documentation