Skip to content

Switch from eslintrc.json to es.config.js #2483

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

Closed
wants to merge 16 commits into from

Conversation

Suyash878
Copy link
Contributor

@Suyash878 Suyash878 commented Aug 25, 2024

What kind of change does this PR introduce?
Bug fix

Issue Number:
Fixes #2472

Did you add tests for your changes?
Not relevant

Snapshots/Videos:
image

If relevant, did you update the documentation?
Not relevant here.

Summary
This PR migrates the deprecated version of eslintrc.json to eslint.config.js.
Now eslint will correctly fix all the linting issues which was not the case earlier as mentioned in the screenshot of the issue raised.

Does this PR introduce a breaking change?
Not sure if relevant here.

Other information
None

Have you read the contributing guide?
Yes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a "Videos" section in the CONTRIBUTING.md file to enhance resource accessibility for contributors.
  • Bug Fixes

    • Improved error handling by allowing console logging for unhandled promise rejections, aiding in debugging.
  • Documentation

    • Minor formatting adjustments in README.md to enhance visual structure.
    • Enhanced navigability in the CONTRIBUTING.md document.
  • Refactor

    • Updated ESLint configuration to enforce stricter code quality standards, especially for TypeScript.
    • Modified pre-commit hook to streamline the commit process, though it may affect staging behavior.
  • Chores

    • Updated various development dependencies in package.json to improve linting capabilities and ensure compatibility with modern JavaScript features.
    • Introduced scripts to automate ESLint checks and prevent unauthorized file modifications.

Copy link

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

coderabbitai bot commented Aug 25, 2024

Warning

Rate limit exceeded

@Suyash878 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 54 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 5d42029 and 58e998d.

Walkthrough

The changes primarily involve transitioning from a deprecated ESLint configuration file format (.eslintrc.json) to a new format (eslint.config.mjs). This update includes the introduction of a comprehensive ESLint setup tailored for TypeScript projects, modifications to various scripts and documentation, and enhancements to error handling and type declaration clarity across multiple files. Additionally, there are adjustments to pre-commit hooks and updates to development dependencies.

Changes

Files Change Summary
.husky/pre-commit Removed line that staged files, potentially affecting commit completeness; removed shebang and sourcing line, compromising pre-commit checks except TypeScript type checking.
CONTRIBUTING.md Added a "Videos" section to the TOC and improved formatting.
README.md Minor formatting adjustments, including indentation changes.
eslint.config.mjs Introduced ESLint configuration for TypeScript with integrated plugins and specific rules for code quality.
package.json Added and updated ESLint-related dependencies, enhancing linting capabilities.
setup.ts Removed ESLint directives suppressing linting warnings, increasing standard compliance.
src/resolvers/Mutation/updateAgendaCategory.ts Removed ESLint directive for non-compliance, promoting adherence to linting rules.
tests/helpers/userAndOrg.ts Reformatted type declaration for clarity without changing semantics.
tests/resolvers/UserTag/childTags.spec.ts Removed ESLint directive for non-null assertions, enforcing stricter TypeScript checks.
tests/resolvers/UserTag/usersAssignedTo.spec.ts Removed comment disabling ESLint rule for non-null assertions, promoting code quality.
tests/resolvers/middleware/currentUserExists.spec.ts Eliminated ESLint directive for explicit any types, enhancing type safety.
delete.sh Introduced a script to automate ESLint checks on modified files.
delete2.sh Created a script to prevent changes to unauthorized files, ensuring project integrity.

Assessment against linked issues

Objective Addressed Explanation
Switch from eslintrc.json to eslint.config.js (#[2472])
Ensure compatibility with new ESLint configurations (#[2472])

🐇 Hop, hop, here we go,
With new rules in a tidy row!
The code is clear, the linting tight,
Our project's path is shining bright!
So let’s celebrate with a little cheer,
For changes made, so let’s all steer! 🥕


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.
    • @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 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

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a87b45a and 3fdd754.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (12)
  • .husky/pre-commit (1 hunks)
  • CONTRIBUTING.md (2 hunks)
  • README.md (2 hunks)
  • config/vitestSetup.ts (1 hunks)
  • eslint.config.mjs (1 hunks)
  • package.json (2 hunks)
  • setup.ts (2 hunks)
  • src/resolvers/Mutation/updateAgendaCategory.ts (1 hunks)
  • tests/helpers/userAndOrg.ts (1 hunks)
  • tests/resolvers/UserTag/childTags.spec.ts (1 hunks)
  • tests/resolvers/UserTag/usersAssignedTo.spec.ts (1 hunks)
  • tests/resolvers/middleware/currentUserExists.spec.ts (1 hunks)
Files skipped from review due to trivial changes (8)
  • CONTRIBUTING.md
  • README.md
  • config/vitestSetup.ts
  • setup.ts
  • src/resolvers/Mutation/updateAgendaCategory.ts
  • tests/helpers/userAndOrg.ts
  • tests/resolvers/UserTag/usersAssignedTo.spec.ts
  • tests/resolvers/middleware/currentUserExists.spec.ts
Additional context used
Learnings (1)
tests/resolvers/UserTag/childTags.spec.ts (2)
Learnt from: meetulr
PR: PalisadoesFoundation/talawa-api#2460
File: tests/resolvers/Mutation/assignUserTag.spec.ts:35-44
Timestamp: 2024-08-15T13:37:37.956Z
Learning: The variable `testSubTag1` is used in the `assignUserTag` test suite to verify that ancestor tags are correctly assigned.
Learnt from: meetulr
PR: PalisadoesFoundation/talawa-api#2460
File: tests/resolvers/Mutation/unassignUserTag.spec.ts:32-37
Timestamp: 2024-08-15T13:37:28.099Z
Learning: The variable `testSubTag1` is used in the `unassignUserTag` tests to verify the unassignment of child tags.
Additional comments not posted (6)
.husky/pre-commit (1)

1-1: Potential execution issues due to script modification.

The removal of the shebang line and the line that sources the Husky script could potentially break the execution of this pre-commit hook. Ensure that the script is executable and functions correctly in all intended environments.

Run the following script to verify the script's functionality:

Also applies to: 7-7

tests/resolvers/UserTag/childTags.spec.ts (1)

1-1: Consider the implications of removing the ESLint non-null assertion directive.

The removal of the /* eslint-disable @typescript-eslint/no-non-null-assertion */ directive could lead to stricter TypeScript checks and potentially more robust code. However, ensure that this change does not introduce errors in parts of the codebase that rely on non-null assertions.

Run the following script to verify the impact of this change on the codebase:

Verification successful

Review the use of non-null assertions in test files.

The non-null assertions are primarily used in test files, which suggests that their removal might not significantly impact production code. However, ensure that these assertions are used safely and that tests do not make unsafe assumptions about data presence.

  • Review the following test files for safe use of non-null assertions:
    • tests/resolvers/Post/creator.spec.ts
    • tests/resolvers/Post/comments.spec.ts
    • tests/resolvers/Query/getEventAttendee.spec.ts
    • tests/resolvers/Mutation/registerForEvent.spec.ts
    • tests/resolvers/Mutation/createFundCampaignPledge.spec.ts
    • tests/resolvers/Mutation/updateUserTag.spec.ts
    • tests/resolvers/Mutation/addEventAttendee.spec.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the ESLint non-null assertion directive.

# Test: Search for non-null assertions in the TypeScript files. Expect: No errors related to non-null assertions.
rg --type ts '!'

Length of output: 117561


Script:

#!/bin/bash
# Description: Search for non-null assertions in TypeScript files.

# Test: Search for non-null assertions specifically. Expect: Instances where `!` is used for non-null assertions.
rg --type ts '\w+!\.'

Length of output: 2660

eslint.config.mjs (1)

1-135: Comprehensive and well-structured ESLint configuration.

The new eslint.config.mjs file is well-structured and appears to comprehensively address various aspects of linting and code quality, especially for TypeScript projects. Ensure that this configuration is thoroughly tested to confirm its compatibility with the existing codebase and does not introduce any unintended side effects.

package.json (3)

102-104: Dependency additions for ESLint are appropriate.

The addition of @eslint/compat, @eslint/eslintrc, and @eslint/js aligns with the PR's objective to enhance ESLint configuration and compatibility. These packages are essential for the new ESLint setup.


132-132: Update of eslint version is justified.

Upgrading eslint from ^8.56.0 to ^9.9.0 is necessary to support the new configuration format and potentially includes improvements and new features that are beneficial for the project.


137-137: Addition of globals package.

The introduction of the globals package at version ^15.9.0 is likely intended to enhance the global variables recognition by ESLint, which can be crucial for linting in complex projects. Ensure that this aligns with the project's linting requirements.

Verification successful

Globals package is used in ESLint configuration.

The globals package is imported and utilized in eslint.config.mjs to configure global variables for Node.js, aligning with the project's linting requirements. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the necessity of the `globals` package in the new ESLint configuration.

# Test: Search for the usage of `globals` in the new ESLint configuration. Expect: References to global variable configurations.
rg --type json -A 10 $'globals' ./eslint.config.js

Length of output: 108


Script:

#!/bin/bash
# Search for ESLint configuration files in the repository.
fd --type f --name ".eslintrc*" 

# Check for references to the `globals` package in any found ESLint configuration files.
rg 'globals' $(fd --type f --name ".eslintrc*")

Length of output: 5360

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 25, 2024
@Suyash878
Copy link
Contributor Author

After successful merging of this PR, I will go ahead and create a similar issue in the Talawa-Admin repository as well.

@palisadoes
Copy link
Contributor

Please fix the conflicting file so we may merge

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 31, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 31, 2024
Copy link

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3fdd754 and ef76b3e.

Files selected for processing (1)
  • package.json (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package.json

Copy link

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ef76b3e and efc6597.

Files selected for processing (1)
  • .husky/pre-commit (1 hunks)
Additional comments not posted (1)
.husky/pre-commit (1)

23-23: Clarification needed on the removal of git add .

The removal of git add . from the pre-commit hook script could lead to issues where changes made by commands earlier in the script are not staged for commit. This change might cause developers to commit incomplete or incorrect code states if they are not manually adding changes to the staging area.

It's important to understand the rationale behind this removal:

  • If the intention is to make developers manually stage files, this should be clearly communicated to avoid confusion.
  • If this is an oversight, consider adding the command back or implementing another mechanism to ensure all changes are staged.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 31, 2024
Copy link

@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: 3

Outside diff range, codebase verification and nitpick comments (1)
delete2.sh (1)

2-2: Use double quotes around the variable in the for loop.

The for loop is not using double quotes around the variable CHANGED_UNAUTH_FILES, which can cause word splitting and globbing issues.

Add double quotes around the variable:

-for file in ${CHANGED_UNAUTH_FILES}; do
+for file in "${CHANGED_UNAUTH_FILES}"; do
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between efc6597 and 8084150.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (5)
  • .husky/pre-commit (2 hunks)
  • delete.sh (1 hunks)
  • delete2.sh (1 hunks)
  • eslint.config.mjs (1 hunks)
  • package.json (2 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Files skipped from review as they are similar to previous changes (1)
  • eslint.config.mjs
Additional context used
Shellcheck
delete2.sh

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

delete.sh

[warning] 3-3: CODECOV_UNIQUE_NAME appears unused. Verify use (or export if used externally).

(SC2034)

Additional comments not posted (2)
delete.sh (1)

7-7: LGTM!

Running ESLint on changed files is a good practice to ensure code quality.

.husky/pre-commit (1)

20-20: LGTM!

The change to stage all files using git add . is approved.

However, please verify the impact of removing the line sourcing the Husky script on the execution of the pre-commit hook. The AI-generated summary indicates that this removal may disrupt the execution of subsequent commands.

Run the following script to verify the execution of the pre-commit hook:

Verification successful

Pre-commit hook executes successfully

The pre-commit hook executed without any errors, indicating that the removal of the line sourcing the Husky script did not disrupt its functionality. The configuration is working as expected.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the execution of the pre-commit hook.

# Test: Simulate a commit and check if the pre-commit hook is executed successfully.
# Expect: The pre-commit hook should be executed without any errors.
git commit --allow-empty -m "Test commit"

Length of output: 81

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 2, 2024
Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

  1. Please make the suggested changes.
  2. Make sure that coderabbit.ai approves your work.

@@ -3,9 +3,6 @@
# Disable the hooks in CI
[ -n "$CI" ] && exit 0

# Change to the current directory
. "$(dirname -- "$0")/_/husky.sh"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

@@ -132,6 +135,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-tsdoc": "^0.3.0",
"get-graphql-schema": "^2.1.2",
"globals": "^15.9.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this added?

Copy link

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8084150 and 5d42029.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (1)
  • package.json (2 hunks)
Files skipped from review due to trivial changes (1)
  • package.json

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 4, 2024
@Suyash878
Copy link
Contributor Author

I will open a new PR, since this one has a lot of unnecessary file changes and conflicts.

@Suyash878
Copy link
Contributor Author

Suyash878 commented Sep 8, 2024

I was working on a newer branch for opening a new PR regarding this issue. Now in order to migrate and properly use eslint.config.js , I need to install these following packages(mentioned in the screenshot) which then lead to conflicts in the package-lock.json file. And due to this same reason the package globals was also added.
I would like to know how I shall proceed with this then.
image

@palisadoes
Copy link
Contributor

Please use your initiative to achieve the goal

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