magicant / yash-rs

Reimplementation of yash, an extended POSIX shell
65 stars 3 forks source link

Various fixes #363

Closed magicant closed 6 months ago

magicant commented 6 months ago

Addresses issues in #336

Summary by CodeRabbit

coderabbitai[bot] commented 6 months ago

Walkthrough

The updates primarily focus on refining error handling, renaming entities for better clarity, and enhancing the script's robustness in handling unset variables. Changes in yash scripts and semantics modules improve readability and functionality, ensuring smoother operations and clearer error communications in various scripting scenarios.

Changes

Files Change Summaries
.../scripted_test/for-p.sh, .../scripted_test/option-p.sh, .../scripted_test/param-p.sh Removal of TODO comments and enhancements in unset variables handling.
.../CHANGELOG.md, .../src/command/compound_command/for_loop.rs Renaming for clarity, adjustments in error handling, and loop behavior modifications.
.../src/expansion.rs, .../src/expansion/initial.rs, .../src/expansion/initial/param.rs, .../src/expansion/initial/param/switch.rs Renaming EmptyError to VacantError, reorganization of public entities, and updates in error handling logic related to unset variables.

πŸ‡βœ¨ In the land of code, where the yash trees grow, A rabbit hopped by, with updates in tow. "No more TODOs!", it cheerily said, As clearer paths it began to tread. With each hop and jump, the code did enhance, In the world of yash, even rabbits can dance! πŸŽ‰πŸΎ


Recent Review Details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between a12c23f04820e8200932d59620740ee83833cf38 and 82704c2f7ba9a18ce5627f70fdf13ed9f11fa08b.
Files selected for processing (9) * yash-cli/tests/scripted_test/for-p.sh (1 hunks) * yash-cli/tests/scripted_test/option-p.sh (1 hunks) * yash-cli/tests/scripted_test/param-p.sh (1 hunks) * yash-semantics/CHANGELOG.md (1 hunks) * yash-semantics/src/command/compound_command/for_loop.rs (3 hunks) * yash-semantics/src/expansion.rs (5 hunks) * yash-semantics/src/expansion/initial.rs (1 hunks) * yash-semantics/src/expansion/initial/param.rs (6 hunks) * yash-semantics/src/expansion/initial/param/switch.rs (19 hunks)
Additional Context Used
LanguageTool (15)
yash-semantics/CHANGELOG.md (15)
Near line 3: Possible spelling mistake found. Context: # Changelog All notable changes to `yash-semantics` will be documented in this file. The ... --- Near line 5: Only proper nouns start with an uppercase character (there are exceptions for headlines). Context: ... in this file. The format is based on [Keep a Changelog](https://keepachangelog.com... --- Near line 12: Possible spelling mistake found. Context: ...nreleased ### Added - Support for the `ErrExit` shell option in multi-command pipeline... --- Near line 18: This sentence does not start with an uppercase letter. Context: ...enamed to `Vacancy`. - `EmptyError` was renamed to `VacantError`. - `EmptyE... --- Near line 18: Possible spelling mistake found. Context: ...ncy`. - `EmptyError` was renamed to `VacantError`. - `EmptyError::state` was renamed... --- Near line 19: This sentence does not start with an uppercase letter. Context: ...VacantError`. - `EmptyError::state` was renamed to `VacantError::vacancy`. - `e... --- Near line 19: Possible spelling mistake found. Context: ... - `EmptyError::state` was renamed to `VacantError::vacancy`. - `expansion::ErrorCause::Em... --- Near line 20: This sentence does not start with an uppercase letter. Context: ...`expansion::ErrorCause::EmptyExpansion` was renamed to `expansion::ErrorCause::Vaca... --- Near line 20: Possible spelling mistake found. Context: ...orCause::EmptyExpansion` was renamed to `expansion::ErrorCause::VacantExpansion`. - `::handle` now returns `Divert::Exit` instead of `Di... --- Near line 22: Possible spelling mistake found. Context: ...instead of `Divert::Interrupt` when the `ErrExit` shell option is applicable. ### Fixed... --- Near line 28: This sentence does not start with an uppercase letter. Context: ...tatus. - `::expand` now correctly expands an unset parameter wi... --- Near line 29: Did you mean β€œshe'll”? Context: ... empty string regardless of the `Unset` shell option. Previously, it would expand t... --- Near line 34: Unpaired symbol: β€˜[’ seems to be missing Context: ... rather than an empty string. ## [0.1.0] - 2024-04-13 ### Added - Initial impl... --- Near line 38: Possible spelling mistake found. Context: ... Added - Initial implementation of the `yash-semantics` crate [0.1.0]: https://github.com/mag...
ShellCheck (16)
yash-cli/tests/scripted_test/for-p.sh (2)
[error] 36-36: Couldn't parse this for loop. Fix to allow more checks. --- [error] 37-37: Unexpected keyword/token. Fix any mentioned problems and try again.
yash-cli/tests/scripted_test/option-p.sh (7)
[error] 92-92: Was this intended as a comment? Use # in sh. --- [error] 98-98: Was this intended as a comment? Use # in sh. --- [info] 192-192: The mentioned syntax error was in this explicit subshell. --- [error] 203-203: You need a space after the [ and before the ]. --- [error] 203-203: Couldn't parse this test expression. Fix to allow more checks. --- [error] 203-203: When breaking lines in [ ], you need \ before the linefeed. --- [error] 204-204: Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.
yash-cli/tests/scripted_test/param-p.sh (7)
[warning] 10-10: This } is literal. Check expression (missing ;/\n?) or quote it. --- [error] 14-14: You need a space after the [ and before the ]. --- [error] 14-14: Couldn't parse this test expression. Fix to allow more checks. --- [error] 14-14: You are missing a required space here. --- [warning] 14-14: This } is literal. Check expression (missing ;/\n?) or quote it. --- [error] 14-14: When breaking lines in [ ], you need \ before the linefeed. --- [error] 15-15: Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.
Learnings (1)
yash-cli/tests/scripted_test/option-p.sh (1)
``` User: magicant PR: magicant/yash-rs#320 File: yash/tests/scripted_test/readonly-p.sh:0-0 Timestamp: 2023-11-23T12:47:34.276Z Learning: The test case for verifying the behavior when attempting to reassign a read-only variable in `yash/tests/scripted_test/readonly-p.sh` has been updated to check for an error or exit status. ```
Additional comments not posted (18)
yash-semantics/CHANGELOG.md (1)
`16-20`: The renaming of entities in the `expansion::initial` module and the behavior change in error handling are well-documented. Ensure that all references to these entities across the project are updated to reflect these changes.
yash-semantics/src/expansion/initial.rs (1)
`83-84`: The export of `Vacancy` and `VacantError` from the `param` module aligns with the renaming strategy described. Ensure that all references to these entities in the codebase are updated accordingly.
yash-semantics/src/expansion/initial/param.rs (5)
`58-59`: Renaming `ValueState` to `Vacancy` and `EmptyError` to `VacantError` aligns with the broader effort to clarify the codebase. --- `85-90`: The error handling logic for the `nounset` option is correctly implemented to throw an error when a parameter is unset. This aligns with the POSIX shell behavior. --- `102-102`: Initializing `value` to `Some(Value::scalar("0"))` when it is `None` is a sensible default for handling unset values, especially in the context of length calculations. --- `192-202`: The test `length_of_unset` effectively checks the behavior of the length modifier when the variable is unset, ensuring it returns "0" as expected. --- `331-345`: The test `nounset_option_is_ignored_if_there_is_switch` verifies that the `nounset` option is correctly ignored when a switch modifier is used, which is a crucial behavior to test.
yash-semantics/src/command/compound_command/for_loop.rs (3)
`32-32`: Importing `ExitStatus` is necessary for the new logic to set the exit status correctly in the loop. --- `75-78`: The addition of a check for empty values before executing the loop body and setting the exit status to `SUCCESS` when the body is not executed is a good practice. It prevents unnecessary execution and correctly reflects the outcome. --- `139-139`: The test `without_words_without_positional_parameters` correctly verifies that the loop does not execute when there are no values and that the exit status is set to `SUCCESS`.
yash-semantics/src/expansion.rs (5)
`86-86`: Renaming `EmptyError` to `VacantError` in the import statement is consistent with the renaming throughout the codebase. --- `138-138`: Updating the `ErrorCause` enum to include `VacantExpansion` with the new `VacantError` type maintains consistency in error handling. --- `156-156`: The method `message` in `ErrorCause` now correctly refers to `VacantError` for generating error messages, ensuring that the error handling remains consistent and clear. --- `171-171`: The `label` method update to use `VacantError` ensures that the error annotations are accurate and informative. --- `190-190`: The `related_location` method correctly does not return a location for `VacantExpansion`, which is appropriate since this error type does not relate to a specific code location.
yash-semantics/src/expansion/initial/param/switch.rs (3)
`38-41`: LGTM! The `Vacancy` enum is well-defined and appropriately documented. --- `52-61`: LGTM! The `Vacancy::of` function correctly categorizes the vacancy states and uses good encapsulation practices. --- `106-106`: LGTM! The `message_or_default` method provides a sensible default message handling.
--- 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.