olivroy / reuseme

Collections of Utility Functions to Work Across Projects
https://olivroy.github.io/reuseme/
Other
4 stars 2 forks source link

Improve `rename_files2()` #18

Closed olivroy closed 5 months ago

olivroy commented 5 months ago

Goal

to have cleaner code Move into helper functions Clarify how we want `warn_conflicts to behave

Todo

Note

adding a suffix often means we are adding precision, I would expect rename_files2() to be less picky. all good

Tests

Add some for individuals parts

It is okay to recalculate things many times.

Summary by CodeRabbit

coderabbitai[bot] commented 5 months ago

Walkthrough

The recent updates focus on enhancing file management functions in R scripts, including better conflict handling in renaming operations and making functions more robust and informative. Changes also include deprecation of outdated parameters, addition of new utility functions, and updates to documentation and testing to align with these improvements.

Changes

File Path Change Summary
R/.../files-conflicts.R Updated solve_file_name_conflict to return count of conflicts and added logic for message display.
R/.../rename-files.R Revamped rename_files2 with new parameters; deprecated force. Improved conflict handling logic.
R/utils.R Added basename_remove_ext function.
R/screenshot.R Updated screenshot function to include checks and new warn_conflicts parameter.
TODO.R Updated to reflect deprecation of an RStudio addin feature in light of new version capabilities.
man/.../rename_files2.Rd Enhanced documentation for rename_files2 with additional parameters and detailed behavior description.
tests/... Extensive updates in test cases to reflect changes in file renaming logic and new utility functions.

🐇✨ In the land of code and script,
A rabbit hopped, its updates slick.
Files renamed with care, no conflicts to stick,
With each line of code, the changes click.
Celebrate we do, with a carrot thick!
🥕🎉


Recent Review Details **Configuration used: CodeRabbit UI**
Commits Files that changed from the base of the PR and between 4bfb104c6ba280d9d8b9c15c84a1711b30839af6 and 00eaa12133842578b2d21187754f4d1a25ee2591.
Files selected for processing (8) * R/files-conflicts.R (5 hunks) * R/rename-files.R (3 hunks) * R/screenshot.R (2 hunks) * TODO.R (1 hunks) * man/rename_files2.Rd (2 hunks) * tests/testthat/_ref/my-analysis.R (1 hunks) * tests/testthat/_snaps/rename-files.md (2 hunks) * tests/testthat/test-rename-files.R (3 hunks)
Files skipped from review as they are similar to previous changes (3) * R/files-conflicts.R * R/rename-files.R * man/rename_files2.Rd
Additional Context Used
LanguageTool (3)
tests/testthat/_snaps/rename-files.md (3)
Near line 43: Possible spelling mistake found. Context: ...b.R' without issue. # rename_files2(): priorizes references if name is generic or widely... --- Near line 43: You might be missing the article “the” here. Context: ...ename_files2(): priorizes references if name is generic or widely used in files ... --- Near line 75: It seems that the correct verb form here is “return”. Context: ...iles in some locations. # Helper files returns the expected input Code comp...
Additional comments not posted (17)
tests/testthat/_ref/my-analysis.R (2)
`6-6`: The comment provides context about the data being manipulated, which is good for maintainability. --- `10-11`: Using `fs::path()` for constructing file paths is a best practice in R for ensuring cross-platform compatibility.
TODO.R (1)
`2-2`: Updating the TODO comment to reflect that the RStudio addin is no longer needed with RStudio 2023.12 helps keep the documentation current and prevents unnecessary work.
tests/testthat/_snaps/rename-files.md (6)
`8-10`: The added instructions in the snapshot provide clear guidance on how to handle file path changes, which enhances user understanding and interaction with the function. --- `17-26`: The snapshot updates reflect the new `overwrite` parameter and provide a detailed view of the function's behavior when testing messages without action, which is crucial for accurate documentation. --- `31-32`: Setting `warn_conflicts` to "none" and observing the function's behavior in this scenario is well-documented in the snapshot, which is important for understanding edge cases. --- `50-51`: The snapshot effectively demonstrates how the function prioritizes references when dealing with generic or widely used file names, which is a critical aspect of the functionality. --- `58-65`: The handling of overridden preferences is clearly documented in the snapshot, showing how the function behaves with the `warn_conflicts` set to "all". This is essential for users who need to understand the impact of this setting. --- `70-85`: The introduction of the `check_referenced_files()` function in the code snapshot provides a clear example of its usage and the type of feedback it generates, which is valuable for debugging and ensuring file integrity.
tests/testthat/test-rename-files.R (7)
`2-14`: Setting up a temporary directory and creating test files at the beginning of the test script is a good practice as it isolates the test environment and ensures that tests do not interfere with each other or with the user's files. --- `15-17`: The TODO comment about adding a test for `my-streets-raw.csv` is clear and actionable. It's good to see that this task is being tracked for future implementation. --- `26-38`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [20-32] The test cases for preventing dangerous file renaming are comprehensive, covering scenarios with missing extensions and non-existent files. This thorough testing is crucial for ensuring the robustness of the `rename_files2()` function. --- `41-131`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [35-46] The test cases for preventing file renaming due to conflicts are well-structured, using snapshots to capture the expected behavior. This approach helps verify that the function behaves as expected in scenarios with potential conflicts. --- `54-56`: The test case for renaming files when forced provides a clear example of the function's behavior with the `warn_conflicts` set to "none" and `overwrite` enabled. This is important for understanding how the function handles forceful actions. --- `64-85`: The test cases for handling short file names and overridden preferences are effectively documented, showing how the function behaves in these specific scenarios. This detailed testing is essential for ensuring that the function can handle a variety of input conditions. --- `92-130`: The test cases for deprecated parameters and checking referenced files are comprehensive, covering the expected deprecation warnings and the behavior of the `check_referenced_files()` function. This thorough testing ensures that deprecated features are handled correctly and that the function's file checking capabilities are robust.
R/screenshot.R (1)
`168-178`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [171-196] The conditional check for the presence of certain file types before setting the `bullets` variable is a good practice, as it ensures that the function behaves correctly based on the content of the directory. Additionally, the use of the `warn_conflicts` parameter in the `rename_files2()` call is aligned with the function's need to handle potential naming conflicts without user intervention.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.