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

refactor: consolidate utility functions into utils/utils.ts #3957

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Manancode
Copy link

@Manancode Manancode commented Mar 24, 2025

fixes Consolidate utility functions by merging utils.ts files

  • Moved convertToJson and pause functions from scripts/utils.ts to utils/utils.ts
  • Updated import paths in all dependent files
  • Removed scripts/utils.ts file

This change improves code organization by having all utility functions in a single location.
Fixes the issue of having duplicate utils.ts files in different locations

Summary by CodeRabbit

  • Refactor

    • Reorganized internal utility modules to streamline dependency management and improve code clarity without affecting functionality.
  • Tests

    • Updated test references to align with the new module organization, ensuring consistency across the codebase.

These changes enhance maintainability and internal structure while keeping end-user functionality unchanged.

Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

Walkthrough

This pull request updates the import paths for utility functions across several files. The changes reflect a new directory structure, moving the source of the convertToJson and pause functions from ../utils (or similar) to ../../utils/utils. In addition, the functions in the utils/utils.ts file are now directly exported. The functional logic, error handling, and overall control flow remain unchanged.

Changes

Files Grouped Change Summary
scripts/casestudies/index.ts, scripts/tools/tools-object.ts, scripts/utils/readAndWriteJson.ts, tests/readAndWriteJson.test.js, tests/utils.test.js Updated import path for convertToJson from ../utils (or ../scripts/utils.ts in tests) to ../../utils/utils.
scripts/dashboard/build-dashboard.ts, scripts/markdown/check-edit-links.ts, scripts/tools/extract-tools-github.ts Updated import path for pause from ../utils to ../../utils/utils.
utils/utils.ts Changed convertToJson and pause to be directly exported functions; minor reformatting in the implementation of pause.

Possibly related issues

Possibly related PRs

Suggested labels

ready-to-merge, bounty

Suggested reviewers

  • derberg
  • magicmatatjahu
  • devilkiller-ag
  • sambhavgupta0705
  • asyncapi-bot-eve
  • Mayaleeeee
  • akshatnema

Poem

In the field of code I hop along,
Adjusting paths with a joyful song.
From ../utils to deeper ground,
New exports in utils are found.
With bytes and hops, our changes shine,
A bug-free code, oh so fine! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, 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 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.

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

netlify bot commented Mar 24, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9a4e12c
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67e1565d89b6a500089548ac
😎 Deploy Preview https://deploy-preview-3957--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Mar 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d678d06) to head (9a4e12c).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3957   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        20    -1     
  Lines          667       656   -11     
  Branches       113       112    -1     
=========================================
- Hits           667       656   -11     

☔ 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

@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

🧹 Nitpick comments (1)
tests/utils.test.js (1)

17-24: Optional: Simplify Error Handling in Test
Consider refactoring the error test for invalid input. Instead of a try-catch block and conditional assertions, leveraging Jest’s .toThrow matcher can improve readability and conciseness. For example:

test('should throw an error if input is invalid JSON and invalid YAML', () => {
  expect(() => convertToJson(invalidString)).toThrow(/Invalid content format/);
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d678d06 and 9a4e12c.

📒 Files selected for processing (9)
  • scripts/casestudies/index.ts (1 hunks)
  • scripts/dashboard/build-dashboard.ts (1 hunks)
  • scripts/markdown/check-edit-links.ts (1 hunks)
  • scripts/tools/extract-tools-github.ts (1 hunks)
  • scripts/tools/tools-object.ts (1 hunks)
  • scripts/utils/readAndWriteJson.ts (1 hunks)
  • tests/readAndWriteJson.test.js (2 hunks)
  • tests/utils.test.js (1 hunks)
  • utils/utils.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
tests/utils.test.js (1)
tests/readAndWriteJson.test.js (3)
  • require (2-2)
  • require (3-3)
  • require (4-4)
🔇 Additional comments (11)
scripts/tools/tools-object.ts (1)

8-8: Update Import Path for convertToJson
The import path has been correctly updated to reflect the new consolidation of utility functions. This change ensures that the file references the correct module in the new directory structure.

scripts/tools/extract-tools-github.ts (1)

7-7: Update Import for pause Function
The updated import statement from ../../utils/utils correctly reflects the new location of the pause utility, ensuring consistency across the project.

tests/utils.test.js (1)

1-1: Update Import Path for convertToJson in Tests
The import has been modified to use the new relative path (../utils/utils.ts), which aligns with the consolidated utilities file. Ensure that the extension is handled correctly based on your module resolution settings.

scripts/utils/readAndWriteJson.ts (1)

3-3: Update Import Path for convertToJson
The import path has been updated to ../../utils/utils, which correctly points to the consolidated utility functions. This change improves maintainability by centralizing shared utilities.

scripts/dashboard/build-dashboard.ts (1)

17-17: Update Import Path for pause Function
The import for the pause function is now updated to use the new consolidated file path (../../utils/utils), ensuring consistency across modules using this utility.

tests/readAndWriteJson.test.js (2)

2-2: Import path correctly updated to reflect new utility function location.

The import path has been correctly updated to import convertToJson from its new consolidated location in utils/utils.ts.


11-11: Mock reference properly updated to match the new import path.

The Jest mock path has been correctly updated to match the new location of the convertToJson function, maintaining the test's functionality.

scripts/markdown/check-edit-links.ts (1)

7-7: Import path correctly updated for the pause utility function.

The import path has been properly updated to reflect the new consolidated location of the pause function in utils/utils.ts.

scripts/casestudies/index.ts (1)

4-4: Import path correctly updated for the convertToJson utility function.

The import path has been properly updated to reflect the new consolidated location of the convertToJson function in utils/utils.ts.

utils/utils.ts (2)

11-11: Function correctly updated to use export declaration.

The convertToJson function is now directly exported using the export keyword, which improves module structure and eliminates the need for a separate export statement at the end of the file.


39-41: Function correctly updated to use export declaration.

The pause function is now directly exported using the export keyword, which improves module structure and eliminates the need for a separate export statement at the end of the file.

@Siddhant-Pragyan-Sinha
Copy link

Hey @Manancode , I think it would be better to compile all those three files into a single utils.ts file with changes in import statements and others to make it much more compact. I would like to collaborate on this issue with you. What are your thoughts about the idea?

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.

Consolidate utility functions by merging utils.ts files
2 participants