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

Migrating to eslint.config.js #2522

Merged
merged 15 commits into from
Oct 12, 2024
Merged

Conversation

Suyash878
Copy link
Contributor

@Suyash878 Suyash878 commented Sep 10, 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. Now this PR is in reference to an earlier PR which was closed due to some dependency issues.

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

  • New Features

    • Added a "Videos" section to the table of contents in the CONTRIBUTING.md file for improved navigation.
    • Introduced a comprehensive ESLint configuration for TypeScript and GraphQL projects to enhance code quality.
  • Bug Fixes

    • Minor formatting adjustments made in the README.md for better visual alignment of the features list.
  • Chores

    • Added new development dependencies and updated existing ones to improve linting and code quality tools in the project.

Copy link

coderabbitai bot commented Sep 10, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing the documentation and updating the ESLint configuration for improved code quality. A new "Videos" section is added to the CONTRIBUTING.md file, while minor formatting adjustments are made in the README.md. The eslint.config.mjs file is created to replace the deprecated eslintrc.json, incorporating new ESLint rules and plugins tailored for TypeScript and GraphQL projects. Additionally, new development dependencies are added to package.json to support the updated linting configuration, along with updates to existing dependencies.

Changes

File Change Summary
CONTRIBUTING.md Added a link to "Videos" in the table of contents.
README.md Adjusted indentation for the "Videos" entry in the core features list.
eslint.config.mjs Introduced new ESLint configuration for TypeScript and GraphQL, replacing eslintrc.json.
package.json Added new development dependencies for ESLint compatibility and configuration management; updated existing dependencies.

Assessment against linked issues

Objective Addressed Explanation
Switch from eslintrc.json to eslint.config.js (#[2472])
Update ESLint configuration to address deprecations (#[2496]) No mention of addressing other deprecations in the configuration.

Possibly related PRs

Suggested reviewers

  • palisadoes

Poem

🐇 In the garden, I hop with glee,
New links and rules, oh joy for me!
With videos bright, our guide is clear,
Linting with care, we have no fear.
Code flows like carrots, crisp and neat,
Together we code, oh what a treat! 🥕✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 84e9a3a and 3bd7668.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

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>, 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 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

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 10, 2024
@pranshugupta54
Copy link
Member

Please fix conflicts

@Suyash878
Copy link
Contributor Author

The conflicts occur due to some newly added packages which are necessary for the migration to happen, As I even mentioned in my previously closed PR #2483.

@palisadoes
Copy link
Contributor

We have a policy of unassigning contributors who close PRs without getting validation from our reviewer team. This is because:

  1. We start looking for people to review PRs when you submit them.
  2. We often contact them and link to the PR. If the PR is closed the whole effort is wasted.
  3. The historical thread of reviewer comments is broken when the work is spread across multiple PRs. The quality of our code is affected negatively.

Please be considerate of our volunteers' limited time and our desire to improve our code base.

This policy is stated as a pinned post in all our Talawa repositories. Our YouTube videos explain why this practice is not acceptable to our Community.

Unfortunately, if this continues we will have to close the offending PR and unassign you from the issue.

image

@palisadoes
Copy link
Contributor

Please fix the conflicting files

@Suyash878
Copy link
Contributor Author

Thank you for bringing this to my attention. I understand the importance of following the established process for PR validation and the impact it has on both the review team and the quality of our codebase. I apologize for closing the PR prematurely without proper review.

I assure you that I will adhere to the policy moving forward and ensure that all PRs remain open until they have been thoroughly reviewed by the team. I appreciate the time and effort the reviewers put into their work, and I will make sure to respect that process in the future.

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 11, 2024
@palisadoes
Copy link
Contributor

  1. Please fix the conflicting files.
  2. We have been merging other PRs that would have caused this.
  3. The PR looks good, so once you have made the changes we can merge

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

Now the only conflict that arises is due to the globals package, But since it is a required dependency for this migration to take place I cannot remove it.

@palisadoes
Copy link
Contributor

Please fix the conflicting files

@Suyash878
Copy link
Contributor Author

I would like to know how I should continue with this, because resolving the conflicts would require me to remove the globals package entirely, but it is a required dependency for the migration.
Any insights or recommendations are much appreciated.

@palisadoes
Copy link
Contributor

Did you get any feedback from the #talawa-api slack channel?

@Suyash878
Copy link
Contributor Author

Okay, I will surely try to seek assistance from there.

@Suyash878
Copy link
Contributor Author

Suyash878 commented Oct 3, 2024

I got a suggestion on the slack channel to add the globals dependency package, So should I raise an issue for it? because in that way only the package.json file in develop would match the package.json in my custom branch leading to the conflicts being resolved.

@palisadoes
Copy link
Contributor

Make the changes to this PR. It is in scope of what needs to be done to do the migration.

…lint.config.js file to handle the global variables
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between da726aa and 8999d55.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • eslint.config.mjs (1 hunks)
  • package.json (2 hunks)
🧰 Additional context used
🔇 Additional comments (4)
package.json (4)

102-104: LGTM: New ESLint packages added to support migration.

The addition of @eslint/compat, @eslint/eslintrc, and @eslint/js packages is appropriate for the migration from .eslintrc.json to eslint.config.js. These packages provide the necessary tools and APIs to work with the new ESLint configuration format.


Line range hint 102-139: Summary: Package updates align with PR objectives and best practices.

The changes in package.json effectively support the migration to eslint.config.js by adding necessary ESLint-related packages. The updates to graphql-markdown, husky, and lint-staged follow best practices for keeping dependencies current. These changes align well with the PR objectives and contribute to maintaining a robust development environment.


138-139: LGTM: Development tools husky and lint-staged updated.

The updates to husky (^9.1.5) and lint-staged (^15.2.10) are patch version increments, which typically include bug fixes and minor improvements. These updates help maintain a robust development environment.

It's a good practice to review the changelogs for these updates. You can use the following commands to check for any notable fixes or improvements:

#!/bin/bash
# Description: Fetch the changelogs for husky and lint-staged updates
echo "Husky changelog:"
npm view husky@9.1.5 changelog

echo "\nLint-staged changelog:"
npm view lint-staged@15.2.10 changelog

137-137: LGTM: graphql-markdown updated to latest minor version.

The update of graphql-markdown from ^7.0.0 to ^7.1.0 is a good practice to keep dependencies current. This minor version update should include backwards-compatible changes or bug fixes.

Please verify the changelog for graphql-markdown v7.1.0 to ensure there are no breaking changes or significant updates that might affect the project. You can use the following command to check:

eslint.config.mjs Outdated Show resolved Hide resolved
eslint.config.mjs Outdated Show resolved Hide resolved
eslint.config.mjs Show resolved Hide resolved
Suyash878 and others added 4 commits October 6, 2024 11:40
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8999d55 and 15000f3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • eslint.config.mjs (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🔇 Additional comments (5)
eslint.config.mjs (5)

36-58: LGTM: Language options and general rules are well-configured

The language options and general rules are appropriately set for a Node.js TypeScript project. The rules focus on code quality and TypeScript best practices, which will help maintain a consistent and robust codebase.


59-111: LGTM: Comprehensive TypeScript-specific configuration

The TypeScript-specific configuration is well-structured and comprehensive. It includes appropriate parser options and a detailed set of rules, particularly the naming conventions. This will ensure consistency and best practices across the TypeScript codebase.


112-125: LGTM: GraphQL configuration is properly set up

The configuration for GraphQL files is well-structured, using the appropriate processor and parser from @graphql-eslint. This setup will ensure proper linting of GraphQL schema files in the project.


126-138: LGTM: File-specific configurations are appropriate

The special configurations for test files and specific source files are reasonable. Disabling certain rules for these files can be necessary to accommodate their unique requirements.

However, it's important to be cautious when disabling rules for specific files to avoid introducing inconsistencies in the codebase. Regularly review these exceptions to ensure they remain necessary. Consider adding comments explaining why these rules are disabled for these specific files.


19-35: ⚠️ Potential issue

Quote the 'import' property name to avoid syntax errors

The 'import' property in the plugins configuration should be quoted to avoid potential syntax errors, as it's a reserved keyword in JavaScript.

Apply this change:

-        "import": fixupPluginRules(_import),
+        "import": fixupPluginRules(_import),

The rest of the global configuration, including ignored directories and extended configs, looks appropriate and follows good practices.

Likely invalid or redundant comment.

eslint.config.mjs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (b677650) to head (3bd7668).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2522   +/-   ##
========================================
  Coverage    98.57%   98.57%           
========================================
  Files          355      355           
  Lines        17996    17996           
  Branches      2400     2400           
========================================
  Hits         17740    17740           
  Misses         253      253           
  Partials         3        3           

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

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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

🧹 Outside diff range and nitpick comments (5)
eslint.config.mjs (5)

20-43: LGTM: Base configuration is well-structured

The base configuration is comprehensive and well-structured. It correctly sets up ignores, extends recommended configs, and configures plugins and language options appropriately for a TypeScript project in a Node.js environment.

Consider adjusting the indentation of the env and parser properties within languageOptions for better readability:

 languageOptions: {
-    env: {
-        node: true,  
-    },
-    parser: tsParser,  
-}
+   env: {
+     node: true,
+   },
+   parser: tsParser,
+ },

45-60: LGTM with suggestion: Global rules are comprehensive

The global rules are well-defined and appropriate for maintaining code quality in a TypeScript project. However, the no-restricted-imports rule might be too strict.

Consider modifying the no-restricted-imports rule to allow local imports:

-        "no-restricted-imports": ["error", {
-            patterns: ["**/src/**"],
-        }],
+        "no-restricted-imports": ["error", {
+            patterns: [{
+                group: ["**/src/**"],
+                message: "Please use relative imports for local files."
+            }],
+        }],

This change will still discourage absolute imports from src, but with a more informative message, and won't break legitimate local imports.


61-113: LGTM with suggestion: TypeScript-specific configuration is robust

The TypeScript-specific configuration is comprehensive and follows best practices. The naming conventions are well-defined and should promote consistency across the codebase.

Consider relaxing the @typescript-eslint/explicit-function-return-type rule to allow inference in some cases:

-        "@typescript-eslint/explicit-function-return-type": "error",
+        "@typescript-eslint/explicit-function-return-type": ["error", {
+            allowExpressions: true,
+            allowTypedFunctionExpressions: true,
+        }],

This change will still enforce explicit return types in most cases but allow inference for simple expressions and typed function expressions, which can improve code readability in some situations.


114-126: LGTM with suggestion: GraphQL configuration is set up correctly

The configuration for GraphQL files is correctly set up with the appropriate processor and plugin.

Consider adding some GraphQL-specific rules to enhance the linting of GraphQL files. For example:

 languageOptions: {
     parser: parser,
 },
+rules: {
+    "@graphql-eslint/no-anonymous-operations": "error",
+    "@graphql-eslint/naming-convention": [
+        "error",
+        {
+            OperationDefinition: {
+                style: "PascalCase",
+                forbiddenPrefixes: ["Query", "Mutation", "Subscription"],
+                forbiddenSuffixes: ["Query", "Mutation", "Subscription"],
+            },
+        },
+    ],
+},

These rules will enforce naming conventions and prevent anonymous operations in your GraphQL schemas.


127-132: LGTM with suggestion: Test file configuration could be expanded

The configuration correctly disables the no-restricted-imports rule for test files, allowing necessary flexibility.

Consider adding more test-specific configurations to enhance the linting of test files. For example:

 files: ["tests/**/*"],

 rules: {
     "no-restricted-imports": "off",
+    "@typescript-eslint/no-explicit-any": "off",
+    "@typescript-eslint/no-non-null-assertion": "off",
+    "jest/valid-expect": "error",
+    "jest/no-disabled-tests": "warn",
 },

These additional rules will provide more flexibility for test files while still maintaining good practices. Remember to install and configure the eslint-plugin-jest if you decide to use Jest-specific rules.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 15000f3 and 84e9a3a.

📒 Files selected for processing (1)
  • eslint.config.mjs (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
eslint.config.mjs (3)

1-18: LGTM: Imports and initial setup are correct

The imports and initial setup look good. All necessary plugins and utilities are imported, and the FlatCompat instance is correctly set up for backwards compatibility with older ESLint configs.


1-139: Overall: Excellent ESLint configuration with minor suggestions for improvement

This ESLint configuration is well-structured and comprehensive, covering TypeScript, GraphQL, and test files effectively. It sets up a robust set of rules that should maintain high code quality standards across the project.

Key strengths:

  1. Comprehensive ignore patterns
  2. Well-defined TypeScript-specific rules and naming conventions
  3. Proper setup for GraphQL linting
  4. Flexibility for test files

Suggestions for improvement:

  1. Consider relaxing the no-restricted-imports rule slightly
  2. Add more GraphQL-specific rules
  3. Expand test-specific configurations
  4. Clarify the need for specific file overrides

Overall, this configuration provides a solid foundation for maintaining code quality in your project. Implementing the suggested improvements will further enhance its effectiveness and flexibility.


133-139: Please clarify: Specific file overrides

The configuration includes rule overrides for specific files. While this may be necessary, it's important to understand and document the reasons for these exceptions.

Could you please provide more context on why these specific files need these rules turned off? This will help ensure that the exceptions are justified and maintain code quality across the project.

To help verify the necessity of these overrides, you can run the following script:

This script will help identify if these files contain functions that might trigger the disabled rules, justifying the overrides.

✅ Verification successful

Rule Overrides May Be Unnecessary

The verification script did not find any functions with implicit return types or empty functions in src/index.ts and src/utilities/copyToClipboard.ts. Therefore, the ESLint rule overrides for these files may not be needed and can potentially be removed to maintain consistent code quality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of implicit return types and empty functions in specified files

echo "Checking src/index.ts:"
ast-grep --lang typescript --pattern 'function $FUNC_NAME($_) { $$$ }' src/index.ts

echo "\nChecking src/utilities/copyToClipboard.ts:"
ast-grep --lang typescript --pattern 'function $FUNC_NAME($_) { $$$ }' src/utilities/copyToClipboard.ts

Length of output: 345

@Suyash878
Copy link
Contributor Author

Suyash878 commented Oct 6, 2024

I have performed the migration, Kindly review

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.

3 participants