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

Add ESLint and Prettier settings #70

Merged
merged 2 commits into from
Apr 3, 2024
Merged

Conversation

script-money
Copy link
Contributor

@script-money script-money commented Mar 30, 2024

A high-quality template library should not contain a lot of inconsistent code style. I have added a style check and fixed lint errors while attempting to maintain the original code style.

Summary by CodeRabbit

  • New Features
    • Introduced ESLint and Prettier configurations for improved code quality and consistency.
  • Documentation
    • Updated documentation to reflect new linting scripts and guidelines.
  • Refactor
    • Enhanced readability and consistency across various scripts with code formatting adjustments.
    • Modified functionality in script files for better error handling and log messaging.
  • Chores
    • Added linting scripts for JavaScript and TypeScript files to ensure code quality.

Copy link
Contributor

coderabbitai bot commented Mar 30, 2024

Walkthrough

The recent updates span across configuration, scripting, and formatting enhancements. A notable shift towards consistency in code style is evident, with a preference for single quotes and improved readability. Configuration files for ESLint and Prettier have been introduced, refining code quality checks and formatting standards. Script adjustments focus on error handling, logging improvements, and minor logic refinements without altering core functionalities. Overall, these changes aim to streamline development workflows and maintain code consistency.

Changes

Files Change Summary
.eslintrc.js, .prettierrc.js Introduced ESLint and Prettier configuration files for improved code quality and formatting standards.
package.json Added linting scripts for JavaScript and TypeScript.
contracts/arguments.js, hardhat.config.js, scripts/.../_deploy-config.js, scripts/.../_events.js, scripts/.../_helpers.js, scripts/.../_sanity-check-custom.js, scripts/.../_sanity-check-universal.js, scripts/.../_sanity-check.js, scripts/.../_send-packet-config.js, scripts/.../_set-contracts-config.js, scripts/.../_switch-clients.js, scripts/.../_update-vibc-address.js, scripts/.../_vibc-helpers.js, scripts/send-packet.js, scripts/send-universal-packet.js, scripts/deploy.js, scripts/private/... Updated string literals to single quotes, adjusted indentation and alignment for readability, and refined error handling. Script logic and control flow remain largely unchanged.
scripts/private/_create-channel-config.js, scripts/private/_create-channel.js Modified command execution and adjusted object structuring for improved functionality and readability.

🐇💻
To the land of code where brackets embrace,
A rabbit hopped in, leaving no trace.
With a flick and a hop, quotes aligned in grace,
Errors fled, leaving not a single case.
In a burrow so deep, where logic entwines,
The rabbit's work shines, as code beautifully refines.
🌟📘

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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a9cab6e and 26b2429.
Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (21)
  • .eslintrc.js (1 hunks)
  • .prettierrc.js (1 hunks)
  • contracts/arguments.js (1 hunks)
  • hardhat.config.js (3 hunks)
  • package.json (2 hunks)
  • scripts/deploy.js (4 hunks)
  • scripts/private/_create-channel-config.js (2 hunks)
  • scripts/private/_create-channel.js (4 hunks)
  • scripts/private/_deploy-config.js (3 hunks)
  • scripts/private/_events.js (8 hunks)
  • scripts/private/_helpers.js (5 hunks)
  • scripts/private/_sanity-check-custom.js (1 hunks)
  • scripts/private/_sanity-check-universal.js (1 hunks)
  • scripts/private/_sanity-check.js (1 hunks)
  • scripts/private/_send-packet-config.js (5 hunks)
  • scripts/private/_set-contracts-config.js (2 hunks)
  • scripts/private/_switch-clients.js (1 hunks)
  • scripts/private/_update-vibc-address.js (1 hunks)
  • scripts/private/_vibc-helpers.js (1 hunks)
  • scripts/send-packet.js (1 hunks)
  • scripts/send-universal-packet.js (1 hunks)
Files skipped from review due to trivial changes (7)
  • .prettierrc.js
  • contracts/arguments.js
  • scripts/deploy.js
  • scripts/private/_helpers.js
  • scripts/private/_update-vibc-address.js
  • scripts/send-packet.js
  • scripts/send-universal-packet.js
Additional Context Used
Additional comments not posted (36)
.eslintrc.js (1)

1-16: The ESLint configuration is well-structured and aligns with the PR objectives of enforcing code quality and style consistency. It's good to see the inclusion of eslint:recommended and plugin:prettier/recommended which ensures a solid base for linting and formatting. The ignorePatterns are appropriately set to exclude node_modules/ and lib/ from linting, which is a common practice. Overall, this configuration should serve as a strong foundation for maintaining code quality in the project.

scripts/private/_sanity-check.js (2)

3-3: Switching to single quotes for the import statement aligns with the project's new code style guidelines. This change enhances consistency across the codebase.


10-16: The adjustment in indentation and the modification of the callback function to handle only error and stdout parameters are in line with best practices for readability and simplicity. Removing stderr from the callback parameters simplifies error handling, assuming that error logging is adequately handled through error.

package.json (2)

7-9: Adding linting scripts lint and lint:fix to the package.json file is a commendable step towards enforcing code quality and style consistency. These scripts provide a convenient way for developers to check and fix linting issues across JavaScript and TypeScript files.


28-32: The addition of ESLint and Prettier dependencies (eslint, eslint-config-prettier, eslint-plugin-prettier, and prettier) is crucial for implementing the linting and formatting rules defined in the project. These versions seem up-to-date as of the last knowledge update. Ensure that these dependencies are kept up-to-date to leverage improvements and security patches.

scripts/private/_send-packet-config.js (3)

1-2: Updating import statements to use single quotes is consistent with the project's new code style guidelines. This change enhances readability and maintains consistency across the codebase.


13-13: The adjustment in the exec function call to handle errors differently by removing the stderr parameter simplifies error handling. This change is acceptable as long as error logging is adequately handled through error.


29-29: Changing console log messages to use single quotes instead of double quotes aligns with the project's code style guidelines. Consistent use of quotes improves code readability.

hardhat.config.js (4)

1-2: Changing the require statements for hardhat-toolbox and hardhat-foundry to use single quotes is consistent with the project's code style guidelines. This enhances readability and consistency.


13-13: Updating the optimizer settings to include a comma after runs: 200 improves readability and follows best practices for object notation in JavaScript.


19-27: Adjusting the network configurations for 'base' and 'optimism' to have accounts inline and use lowercase keys improves readability and consistency. It's important to ensure that these changes do not affect the functionality of network configurations.


44-58: Modifying the custom chain configurations for 'base' and 'optimism' to use single quotes for keys and URLs aligns with the project's code style guidelines. Ensure that the URLs and chain IDs are correct and functional.

scripts/private/_set-contracts-config.js (3)

7-7: Using single quotes for string literals in error messages and usage instructions aligns with the project's code style guidelines. This change enhances consistency and readability.


13-13: Consistently using single quotes for the universalBoolean variable's value comparison improves code readability and maintains consistency across the codebase.


34-46: The function updateConfig is well-implemented, with clear and concise error handling. Using single quotes for string literals within this function aligns with the project's code style guidelines. Ensure that the JSON formatting and file writing operations are correctly executed without unintended side effects.

scripts/private/_deploy-config.js (2)

1-1: Using single quotes in the require statement for child_process aligns with the project's code style guidelines. This change enhances consistency across the codebase.


52-52: Changing the console error message to use single quotes instead of double quotes is consistent with the project's code style guidelines. This enhances readability and maintains consistency.

scripts/private/_create-channel-config.js (2)

16-16: Removing the stderr parameter in the callback of the exec function simplifies error handling. This change is acceptable as long as error logging is adequately handled through error.


42-42: Adjusting the template string formatting for console output enhances readability and maintains consistency with the project's code style guidelines. Ensure that the template string placeholders correctly reflect the intended values.

scripts/private/_sanity-check-custom.js (3)

7-10: The import statements have been updated to use single quotes consistently, which aligns with the newly established code style guidelines.


52-60: The error message for a failed sanity check is detailed and provides clear instructions for resolution. This is a good practice for error messages as it aids in quicker issue identification and resolution.


66-68: The catch block for the async main function is correctly setting the process.exitCode to 1 upon encountering an error, which is a good practice for indicating failure in scripts intended to be run from the command line.

scripts/private/_create-channel.js (4)

13-29: The createDummyProof function has been updated to structure the proof object differently. Ensure that the new structure aligns with the expected format for proofs in the rest of the application.


62-62: The createChannel function call has been updated with revised parameters, including the use of createDummyProof(). It's important to ensure that these changes are reflected in any related documentation or tests.


71-80: The logging for channel creation is clear and informative, providing details about the new channel and its counterparty. This is good for debugging and operational monitoring.


90-90: The catch block for the async main function correctly sets the process.exitCode to 1 upon encountering an error, which is a good practice for indicating failure in scripts intended to be run from the command line.

scripts/private/_switch-clients.js (2)

7-85: The restructuring of the configuration update process in flipConfig function is comprehensive, including handling backup values and toggling the proofsEnabled flag. Ensure that the backup mechanism is thoroughly tested, especially in scenarios where the script might be interrupted or fail, to prevent loss of configuration data.


83-84: The error handling in the catch block of flipConfig function is appropriate, logging the error message and exiting with a non-zero status. This is good practice for scripts intended to be run from the command line.

scripts/private/_vibc-helpers.js (2)

1-2: The update to use single quotes for string literals aligns with the newly established code style guidelines.


10-20: The getIbcApp function correctly handles errors by logging them and returning early. This is good practice for error handling in asynchronous functions.

scripts/private/_sanity-check-universal.js (2)

7-9: The import statements have been updated to use single quotes consistently, which aligns with the newly established code style guidelines.


119-121: The catch block for the async main function correctly sets the process.exitCode to 1 upon encountering an error, which is a good practice for indicating failure in scripts intended to be run from the command line.

scripts/private/_events.js (4)

1-3: The update to use single quotes for string literals aligns with the newly established code style guidelines.


45-73: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [56-87]

The handling of ConnectIbcChannel events is well-implemented, with detailed logging. As with the previous comment, verify that event listeners are correctly removed.

Verification successful

Given the limitations of the provided script output and the need for a more in-depth analysis of the codebase to understand the usage of the dispatcher and event listeners, it's clear that the initial verification script did not contribute to verifying the correct removal of event listeners. To proceed, we should search the codebase for other instances where listeners are added to the dispatcher. This will help us understand if removing all listeners after handling a ConnectIbcChannel event is the correct approach and does not inadvertently affect the application's functionality.


Based on the provided context, the application consistently removes all listeners after handling specific events, suggesting a deliberate design choice to prevent memory leaks and ensure that the dispatcher is ready for new events without interference from previous listeners. This approach aligns with the intention to prevent memory leaks by clearing event listeners after their relevant events have been processed. Without additional context on the application's overall design and requirements, it appears that the event listeners are correctly removed as intended by the developers.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Suggest verifying that event listeners are correctly removed to prevent memory leaks.
echo "Verify event listener removal."

Length of output: 70



Script:

#!/bin/bash
# Search for instances where listeners are added to the dispatcher
grep -r "dispatcher.on" .
# Search for instances where listeners are removed
grep -r "dispatcher.removeAllListeners" .

Length of output: 1228


77-97: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [89-108]

The CloseIbcChannel event handling is correctly implemented with detailed logging. Ensure that the removal of event listeners is handled properly to avoid memory leaks.

Verification successful

To verify the proper management and removal of event listeners to prevent memory leaks, I will search for instances where event listeners are added or removed within the scripts/private/_events.js file and potentially related files. This will help in understanding the pattern of event listener management.


To accurately assess the management of event listeners and ensure that their removal is handled properly to avoid memory leaks, I need to correct the regex error and search again for instances where event listeners are added. This will provide a comprehensive view of how event listeners are managed in the _events.js file.


The verification process has shown that the _events.js file adds event listeners for various events and consistently removes them using removeAllListeners(). This pattern of adding and then removing event listeners suggests a deliberate effort to manage event listeners properly and avoid memory leaks. Therefore, the initial review comment's concern about ensuring the proper removal of event listeners to avoid memory leaks is addressed by the observed code pattern.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Suggest verifying that event listeners are correctly removed to prevent memory leaks.
echo "Verify event listener removal."

Length of output: 70



Script:

#!/bin/bash
# Search for patterns of adding and removing event listeners in _events.js and potentially related files.
echo "Searching for event listener management patterns in _events.js:"
rg --context 5 ".on(" scripts/private/_events.js
echo "Searching for event listener removal patterns in _events.js:"
rg --context 5 ".removeAllListeners()" scripts/private/_events.js

Length of output: 1969



Script:

#!/bin/bash
# Correcting the regex error and searching for patterns of adding event listeners in _events.js.
echo "Corrected search for event listener addition patterns in _events.js:"
rg --context 5 "\.on\(" scripts/private/_events.js

Length of output: 3511


140-156: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [120-213]

The listenForIbcPacketEvents function and related event handling are well-structured with clear logging. As with channel event listeners, verify the correct removal of packet event listeners.

scripts/private/_sanity-check-custom.js Show resolved Hide resolved
scripts/private/_sanity-check-custom.js Show resolved Hide resolved
scripts/private/_vibc-helpers.js Show resolved Hide resolved
scripts/private/_vibc-helpers.js Show resolved Hide resolved
scripts/private/_sanity-check-universal.js Show resolved Hide resolved
scripts/private/_sanity-check-universal.js Show resolved Hide resolved
scripts/private/_sanity-check-universal.js Show resolved Hide resolved
scripts/private/_events.js Show resolved Hide resolved
Copy link
Contributor

@tmsdkeys tmsdkeys left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

@tmsdkeys tmsdkeys merged commit 61e3747 into open-ibc:main Apr 3, 2024
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.

2 participants