Skip to content
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

Merged
merged 12 commits into from
May 9, 2024
Merged

feat: apply transforms on stdin #320

merged 12 commits into from
May 9, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented May 9, 2024

Fixes #300

Summary by CodeRabbit

  • New Features

    • Added new functionality to handle transformations directly from standard input for JavaScript and Python files.
    • Introduced a new output format option Transformed to enhance result formatting capabilities.
  • Enhancements

    • Improved pattern application processes to support both disk and virtual inputs.
    • Enhanced command functions to more efficiently handle flags and parameters without unnecessary conversions.
  • Bug Fixes

    • Updated match patterns in command functions to include new variants, ensuring comprehensive handling of cases.
  • Refactor

    • Optimized function signatures and parameter passing across various modules to streamline operations and improve performance.
  • Documentation

    • No visible changes to end-users.

@morgante morgante marked this pull request as ready for review May 9, 2024 09:55
@morgante morgante requested a review from a team as a code owner May 9, 2024 09:55
Copy link
Contributor

coderabbitai bot commented May 9, 2024

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 6494c04 and 206f0b3.

Walkthrough

The 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 Transformed output format, and refined handling of input types and output destinations. These modifications aim to streamline the application process and expand the tool's usability in different operational contexts.

Changes

Files Change Summary
crates/cli/src/commands/apply.rs, crates/cli/src/commands/apply_pattern.rs, crates/cli_bin/tests/apply.rs Direct application from stdin, handling transformation inputs, and testing these functionalities.
crates/cli/src/commands/check.rs, crates/cli/src/messenger_variant.rs, crates/cli/src/result_formatting.rs Introduction and handling of the Transformed output format, including new structures and enum variants for message handling.
crates/cli/src/flags.rs, crates/cli/src/commands/mod.rs, crates/cli/src/commands/plumbing.rs Modifications to output formats, command execution adjustments, and argument handling improvements.

Assessment against linked issues

Objective Addressed Explanation
Apply directly on stdin (#300)

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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;

@morgante morgante changed the title feat: apply stdin feat: apply transforms on stdin May 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 the ApplyInput 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.

Comment on lines +193 to +262
"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),
};
Copy link
Contributor

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.

Suggested change
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);

@morgante morgante merged commit 44ae505 into main May 9, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply directly on stdin
2 participants