Skip to content

feat: add new options recoverErrors and singleLine support #104

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

Merged
merged 3 commits into from
Apr 7, 2025

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Apr 7, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced Error Recovery: The system now includes an option that improves error handling during processing for increased reliability.
    • Single-Line Formatting: A new setting enables outputs to be formatted in a single-line layout, providing a cleaner and more streamlined presentation.
    • Updated Configuration Options: New parameters for recoverErrors and singleLine have been added to enhance functionality.

@JounQin JounQin requested a review from Copilot April 7, 2025 08:49
Copy link

changeset-bot bot commented Apr 7, 2025

🦋 Changeset detected

Latest commit: 0da3d81

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sh-syntax Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 7, 2025

Walkthrough

The pull request introduces two new options—recoverErrors and singleLine—to enhance error recovery and single-line processing across the codebase. Changes were made to update function signatures and internal structures in Go files (main.go and processor/main.go), including reordering existing parameters and adding new fields to option structures. In TypeScript files (src/processor.ts and src/types.ts), similar enhancements were made to parameter and interface definitions. Additionally, loop constructs in processor/structs.go were refactored to use range-based iteration. A new changeset entry documents these updates.

Changes

Files Change Summary
.changeset/ninety-rings-guess.md Added a new changeset entry documenting the introduction of recoverErrors and singleLine options.
main.go, processor/main.go Updated the process function signature and modified option structures (ParserOptions and PrinterOptions) to include recoverErrors and singleLine; parameters were reordered, and Parse/Print functions were updated to handle the new options.
processor/structs.go Refactored loop constructs in functions (e.g., mapComments, mapWord, mapRedirects, mapStmts) to use the for i := range construct instead of traditional for-loops based on slice lengths.
src/processor.ts, src/types.ts Extended the getProcessor function and corresponding type interfaces to support new recoverErrors and singleLine parameters/properties; the variant parameter was repositioned from the inner function to the outer function in TypeScript.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TS as getProcessor (TS)
    participant GO as process (Go)
    participant Parser as Parse (Go)
    participant Printer as Print (Go)

    Client->>TS: Call getProcessor(recoverErrors, singleLine, variant)
    TS->>GO: Invoke process(..., recoverErrors, singleLine, ...)
    GO->>Parser: Parse(text, options {RecoverErrors})
    GO->>Printer: Print(text, options {SingleLine})
    Parser-->>GO: Return parsed file or error
    Printer-->>GO: Return formatted text or error
    GO-->>TS: Return processed result
    TS-->>Client: Return final output
Loading

Poem

I'm a little rabbit with ears so bright,
Hopping through code in the soft moonlight.
I've added new options to help errors mend,
And made single lines dance without end.
With for-loops now nimble and paths refined,
I celebrate these changes with joy in my mind! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/processor.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa72b1 and 0da3d81.

📒 Files selected for processing (4)
  • main.go (4 hunks)
  • processor/main.go (5 hunks)
  • processor/structs.go (5 hunks)
  • src/processor.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • processor/structs.go
  • main.go
🧰 Additional context used
🧬 Code Definitions (1)
processor/main.go (2)
src/types.ts (2)
  • LangVariant (3-8)
  • LangVariant (10-10)
main.go (1)
  • Parse (45-47)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
🔇 Additional comments (11)
src/processor.ts (5)

48-75: Well-documented function with comprehensive JSDoc!

The JSDoc comment thoroughly explains the processor function, including all parameters, return values, and exceptions. It clearly documents the new recoverErrors and singleLine options.


85-87: Good implementation of the recoverErrors parameter

The recoverErrors parameter is properly added with a default value of 0, which is appropriate for ensuring backward compatibility with existing code that doesn't explicitly pass this parameter.


96-97: Good implementation of the singleLine parameter

The singleLine parameter is properly added with a default value of false, maintaining backward compatibility with existing code.


185-189: Parameter flow correctly updated

The variant parameter is now correctly passed directly from the outer function parameters, and the recoverErrors parameter is properly passed to the WebAssembly process function.


197-198: New parameter properly passed to the WebAssembly function

The singleLine parameter is correctly passed to the WebAssembly process function, completing the implementation of this new option.

processor/main.go (6)

15-20: Good addition of the RecoverErrors field to ParserOptions

The RecoverErrors field is properly added to the ParserOptions struct with the correct integer type. The struct formatting is also clean with aligned field names.


29-30: Good implementation of the SingleLine field in PrinterOptions

The SingleLine field is properly added to the PrinterOptions struct with the Boolean type, which is consistent with the other formatting options.


38-43: Well-documented Parse function

The Parse function is now well-documented with a clear comment that explains its purpose, parameters, and return values, including the new RecoverErrors functionality.


52-54: Good conditional handling of the RecoverErrors option

The code correctly checks if RecoverErrors is not 0 before applying the option, which is an efficient approach that avoids setting unnecessary default values.


61-66: Well-documented Print function

The Print function is now well-documented with a clear comment that explains its purpose, parameters, and return values, including the new SingleLine functionality.


80-81: Good implementation of the SingleLine printer option

The SingleLine option is correctly passed to the syntax printer, enabling the new formatting capability.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

codesandbox-ci bot commented Apr 7, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

sonarqubecloud bot commented Apr 7, 2025

Copy link
Contributor

github-actions bot commented Apr 7, 2025

size-limit report 📦

Path Size
lib/browser.js 121 B (0%)
lib/index.js 378 B (0%)

Copy link

pkg-pr-new bot commented Apr 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/sh-syntax@104

commit: 0da3d81

Copy link
Contributor

github-actions bot commented Apr 7, 2025

📊 Package size report   0.1%↑

File Before After
lib/index.cjs 6.6 kB 1%↑6.7 kB
lib/processor.js 3.2 kB 2%↑3.3 kB
lib/processor.js.map 3.4 kB 2%↑3.5 kB
lib/types.d.ts 1.8 kB 3%↑1.8 kB
main.wasm 779.4 kB 0.08%↑780.1 kB
Total (Includes all files) 826.9 kB 0.1%↑827.8 kB
Tarball size 303.3 kB 0.05%↑303.5 kB
Unchanged files
File Size
index.d.cts 62 B
lib/browser.d.ts 95 B
lib/browser.js 130 B
lib/browser.js.map 171 B
lib/index.d.ts 709 B
lib/index.js 818 B
lib/index.js.map 950 B
lib/processor.d.ts 707 B
lib/shim.d.ts 11 B
lib/shim.js 279 B
lib/shim.js.map 342 B
lib/types.js 140 B
lib/types.js.map 223 B
LICENSE 1.1 kB
package.json 3.5 kB
README.md 7.1 kB
vendors/wasm_exec.cjs 16.0 kB
vendors/wasm_exec.d.cts 98 B

🤖 This report was automatically generated by pkg-size-action

Copy link

codecov bot commented Apr 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.25%. Comparing base (ccabf8a) to head (0da3d81).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #104      +/-   ##
==========================================
+ Coverage   96.15%   96.25%   +0.09%     
==========================================
  Files           4        4              
  Lines          78       80       +2     
  Branches       30       32       +2     
==========================================
+ Hits           75       77       +2     
  Misses          3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccabf8a and 1aa72b1.

⛔ Files ignored due to path filters (1)
  • main.wasm is excluded by !**/*.wasm
📒 Files selected for processing (6)
  • .changeset/ninety-rings-guess.md (1 hunks)
  • main.go (3 hunks)
  • processor/main.go (4 hunks)
  • processor/structs.go (4 hunks)
  • src/processor.ts (4 hunks)
  • src/types.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
processor/main.go (1)
src/types.ts (2)
  • LangVariant (3-8)
  • LangVariant (10-10)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
🔇 Additional comments (14)
.changeset/ninety-rings-guess.md (1)

1-5: LGTM, good documentation of new features.

The changeset entry correctly documents the addition of the two new options: recoverErrors and singleLine. This follows best practices for changelog management.

src/types.ts (2)

15-16: Interface updates look good.

The ShParserOptions interface has been correctly extended with the stopAt and recoverErrors options, following the existing pattern for optional properties.


26-26: Interface addition is well structured.

The singleLine option is properly added to the ShPrinterOptions interface with the correct type and optional modifier.

src/processor.ts (3)

57-59: Parameter additions look good.

The stopAt and recoverErrors parameters are correctly added with appropriate default values.


68-69: New singleLine option is well implemented.

The singleLine parameter is correctly added with a default value of false.


115-120: Parameter handling improved.

The refactoring of how variant is passed to the process function eliminates redundancy, and the new parameters are correctly passed through to the underlying implementation.

Also applies to: 157-161, 169-170

main.go (4)

63-64: Parameter order change and new parameter addition.

The function signature has been modified to add recoverErrors int parameter after stopAt []byte. The parameter order change ensures consistency with the order in the ParserOptions struct. This matches the changes in processor/main.go where RecoverErrors field was added to the ParserOptions struct.


73-73: New option added: singleLine boolean parameter.

The singleLine parameter has been added before functionNextLine, properly aligned with other boolean formatting options. This matches the changes in processor/main.go where SingleLine field was added to the PrinterOptions struct.


79-84: Updated ParserOptions initialization with new RecoverErrors field.

The parserOptions struct initialization has been updated to include the new RecoverErrors field, passing the value from the function parameter. The structure remains clean and well-organized.


97-97: Added SingleLine configuration to printerOptions.

The SingleLine field is now properly initialized with the singleLine parameter value. This completes the implementation of the new formatting option.

processor/main.go (4)

15-20: Updated ParserOptions struct with new RecoverErrors field.

The ParserOptions struct has been updated to include a new RecoverErrors int field. The field ordering is logical with related fields grouped together. This change aligns with the syntax.RecoverErrors functionality from the mvdan.cc/sh/v3/syntax package.


29-29: Added SingleLine option to PrinterOptions struct.

The new SingleLine bool field has been added to the PrinterOptions struct. This provides control over single-line output formatting in the shell syntax printer.


47-49: Implemented conditional application of RecoverErrors option.

The implementation conditionally applies the RecoverErrors option only when the value is non-zero, which is a good practice. This provides flexibility to control the error recovery behavior during parsing.


70-70: Applied SingleLine option in printer configuration.

The SingleLine option is now properly passed to the underlying syntax printer. This completes the implementation chain from the public API through to the actual syntax printer configuration.

@JounQin
Copy link
Member Author

JounQin commented Apr 7, 2025

@coderabbitai generate docstrings

Copy link
Contributor

coderabbitai bot commented Apr 7, 2025

✅ Actions performed

Docstrings generation started.

coderabbitai bot added a commit that referenced this pull request Apr 7, 2025
Docstrings generation was requested by @JounQin.

* #104 (comment)

The following files were modified:

* `main.go`
* `processor/main.go`
* `processor/structs.go`
* `src/processor.ts`
Copy link
Contributor

coderabbitai bot commented Apr 7, 2025

Note

Generated docstrings for this pull request at #105

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JounQin <[email protected]>
Copy link

sonarqubecloud bot commented Apr 7, 2025

@JounQin
Copy link
Member Author

JounQin commented Apr 7, 2025

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

@coderabbitai This project uses yarn v4, the deps are just fine there.

Copy link
Contributor

coderabbitai bot commented Apr 7, 2025

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the project structure and package management setup
echo "Checking project structure and package management:"
ls -la
echo "-------------------"
echo "Checking package.json:"
cat package.json | jq '{ name, dependencies, devDependencies, packageManager }'
echo "-------------------"
echo "Checking for yarn files:"
ls -la .yarn* 2>/dev/null || echo "No .yarn* files found"
ls -la yarn* 2>/dev/null || echo "No yarn* files found"
echo "-------------------"
echo "Yarn version if available:"
yarn --version 2>/dev/null || echo "Yarn command not available in sandbox"

Length of output: 4280


🏁 Script executed:

#!/bin/bash
# Check the .yarnrc.yml configuration and any custom Yarn v4 settings
echo "Checking .yarnrc.yml:"
cat .yarnrc.yml
echo "-------------------"
echo "Checking for any docstring generation-related files:"
find src -name "*.ts" | head -5
echo "-------------------"
echo "Checking typescript configuration:"
cat tsconfig.json
echo "-------------------"
echo "Let's see the structure of the PR changes:"
git show --name-only HEAD

Length of output: 2893


@JounQin Thank you for the clarification. I understand this project uses Yarn v4.8.1, and the dependencies are properly configured. I can see the docstrings were successfully generated and committed in PR #105, so the dependency warning was indeed a false positive. Is there anything else you need help with regarding the new recoverErrors and singleLine options?


✏️ Learnings added
Learnt from: JounQin
URL: https://github.com/un-ts/sh-syntax/pull/104

Timestamp: 2025-04-07T09:49:34.585Z
Learning: The sh-syntax project uses Yarn v4.8.1 for package management, and dependency warnings related to the package structure should be ignored as false positives.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Actions performed

Comments resolved.

@JounQin JounQin merged commit ece2ff4 into main Apr 7, 2025
38 checks passed
@JounQin JounQin deleted the feat/new_options branch April 7, 2025 09:50
@github-actions github-actions bot mentioned this pull request Apr 7, 2025
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.

1 participant