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 from eslintrc.json to eslint.config.js #2660

Open
wants to merge 7 commits into
base: develop-postgres
Choose a base branch
from

Conversation

Suyash878
Copy link

@Suyash878 Suyash878 commented Dec 14, 2024

What kind of change does this PR introduce?

Feature

Issue Number:

Fixes #2645

Did you add tests for your changes?

Not required.

Snapshots/Videos:

None.

If relevant, did you update the documentation?

Not required.

Summary

Successfully migrating from the deprecated .eslintrc.json to the newly supported eslint.config.js configuration.

Does this PR introduce a breaking change?

No.

Other information

None.

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Introduced new GraphQL queries for retrieving fund and campaign data.
    • Enhanced error handling in the Organization Dashboard with user notifications.
  • Bug Fixes

    • Corrected a typo in the USER_FUND_CAMPAIGNS query.
  • Chores

    • Updated ESLint configuration and dependencies to improve linting capabilities.
    • Removed outdated ESLint configuration files.

Copy link

coderabbitai bot commented Dec 14, 2024

Walkthrough

This pull request focuses on migrating the ESLint configuration from the traditional .eslintrc.json format to the new eslint.config.mjs approach. The changes involve removing the old configuration files (.eslintignore and .eslintrc.json), adding a new eslint.config.mjs configuration file, and updating the package.json with new ESLint-related dependencies. Additionally, the PR includes several GraphQL query definitions for funds and campaigns, as well as minor updates to the OrganizationDashboard component for improved error handling and display logic.

Changes

File Change Summary
.eslintignore Deleted file that previously specified linting exclusions
.eslintrc.json Deleted traditional ESLint configuration file
eslint.config.mjs New ESLint configuration file using the latest flat config approach
package.json Updated ESLint-related dependencies and versions
src/GraphQl/Queries/fundQueries.ts Added new GraphQL queries for funds, campaigns, and pledges
src/screens/OrganizationDashboard/OrganizationDashboard.tsx Minor updates to error handling and post display logic

Assessment against linked issues

Objective Addressed Explanation
Migrate from .eslintrc.json to eslint.config.mjs
Maintain existing linting rules

Possibly related PRs

Suggested Labels

ignore-sensitive-files-pr

Suggested Reviewers

  • palisadoes
  • pranshugupta54
  • AVtheking
  • GlenDsza

Poem

🐰 Linting rabbits hop with glee,
Configs dancing, now ESLint-free!
From .json to .mjs we leap,
Clean code promises we shall keep!
Hop, hop, hooray for code so bright! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

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

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

7-9: Simplify plugin import by removing 'fixupPluginRules'.

The use of fixupPluginRules from @eslint/compat may not be necessary in the Flat Configuration. You can import eslint-plugin-import directly and reference it in the plugins section without wrapping it.

Apply this diff to simplify the import:

- import _import from "eslint-plugin-import";
- import { fixupPluginRules } from "@eslint/compat";
+ import importPlugin from "eslint-plugin-import";

  ...

  plugins: {
      react,
      "@typescript-eslint": typescriptEslint,
      jest,
-     import: fixupPluginRules(_import),
+     import: importPlugin,
      tsdoc,
      prettier,
  },

61-62: Update 'ecmaVersion' to the latest version.

The ecmaVersion is set to 2018. Consider updating it to the latest version (e.g., 2023) to support the newest ECMAScript features.

Apply this diff to update the ecmaVersion:

  parser: tsParser,
- ecmaVersion: 2018,
+ ecmaVersion: "latest",
  sourceType: "module",
package.json (1)

Line range hint 97-101: Remove the redundant 'eslintConfig' field from 'package.json'.

Since the ESLint configuration has moved to eslint.config.mjs, the eslintConfig field in package.json is no longer needed and can be removed to prevent confusion.

Apply this diff to remove the redundant configuration:

  },
- "eslintConfig": {
-     "extends": [
-         "react-app",
-         "react-app/jest"
-     ]
- },
  "browserslist": {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4aafd7 and b29d1a4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .eslintignore (0 hunks)
  • .eslintrc.json (0 hunks)
  • eslint.config.mjs (1 hunks)
  • package.json (2 hunks)
  • src/GraphQl/Queries/fundQueries.ts (0 hunks)
  • src/screens/OrganizationDashboard/OrganizationDashboard.tsx (0 hunks)
💤 Files with no reviewable changes (4)
  • .eslintignore
  • .eslintrc.json
  • src/screens/OrganizationDashboard/OrganizationDashboard.tsx
  • src/GraphQl/Queries/fundQueries.ts
🔇 Additional comments (2)
eslint.config.mjs (1)

24-33: Verify that all necessary files are properly ignored.

With the migration from .eslintignore to the ignores array, ensure that all files and patterns that should be excluded from linting are included. This includes any files previously specified in .eslintignore.

Review the ignores array to confirm it reflects all the necessary ignore patterns from your previous configuration.

package.json (1)

119-121: Re-evaluate the necessity of '@eslint/compat' and '@eslint/eslintrc'.

The packages @eslint/compat and @eslint/eslintrc are typically used for compatibility purposes when migrating configurations. Since you're adopting the new Flat Configuration format, these may not be required.

Consider removing these dependencies if they are not essential to your setup.

eslint.config.mjs Outdated Show resolved Hide resolved
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: 1

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

51-68: Consider updating ECMAScript version.

The current configuration uses ECMAScript 2018. Consider updating to a more recent version (e.g., 2022) to take advantage of newer language features.

-        ecmaVersion: 2018,
+        ecmaVersion: 2022,

112-116: Consider relaxing interface naming conventions.

The current configuration requires all interfaces to have either "Interface" or "TestInterface" prefix, which might lead to verbose and less readable code. Consider removing the prefix requirement while keeping the PascalCase format.

         "@typescript-eslint/naming-convention": ["error", {
             selector: "interface",
             format: ["PascalCase"],
-            prefix: ["Interface", "TestInterface"],
         }, {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b29d1a4 and d56b259.

📒 Files selected for processing (1)
  • eslint.config.mjs (1 hunks)
🔇 Additional comments (6)
eslint.config.mjs (6)

1-14: LGTM: Import statements are well-organized and complete.

All necessary ESLint plugins and utilities are properly imported.


15-21: LGTM: Configuration setup follows ESLint flat config best practices.

Proper initialization of FlatCompat with correct base directory and ESM compatibility.


34-41: Remove redundant Prettier configuration.

Having both 'plugin:prettier/recommended' and 'prettier' in the extends array is redundant.


42-49: LGTM: Plugin configurations are properly set up.

All plugins are correctly registered and the use of fixupPluginRules for the import plugin is appropriate.


70-74: LGTM: React settings are properly configured.

Using "detect" for React version is the recommended approach.


23-33: Verify the necessity of ignoring specific files.

While the general ignore patterns for CSS/SCSS/JSON files are standard, let's verify if ignoring specific files like src/components/CheckIn/tagTemplate.ts is still necessary.

✅ Verification successful

Let me gather more information about the tagTemplate.ts file to understand why it might need to be ignored.


Based on the results, I can now generate the final response:

The specific file ignores are still necessary and valid

The specifically ignored file src/components/CheckIn/tagTemplate.ts exists and contains a PDF template definition used for tag generation. The file contains base64-encoded PDF data and specific layout configurations, which should be excluded from linting to avoid unnecessary processing of generated/binary content.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the specific ignored files exist and their content
echo "Checking for existence of specifically ignored files..."
for file in "src/components/CheckIn/tagTemplate.ts" "tsconfig.json"
do
  if [ -f "$file" ]; then
    echo "Found $file:"
    head -n 5 "$file"
  else
    echo "$file not found"
  fi
done

Length of output: 798


Script:

#!/bin/bash
# Check the content and usage of tagTemplate.ts
echo "Content of tagTemplate.ts:"
cat src/components/CheckIn/tagTemplate.ts

echo -e "\nChecking for references to tagTemplate:"
rg "tagTemplate" --type ts -C 2

Length of output: 65728

Comment on lines 90 to 98
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/no-unsafe-function-type": "error",
"@typescript-eslint/no-wrapper-object-types": "error",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Strict TypeScript rules need adjustments before enabling

The codebase shows multiple violations of the proposed strict TypeScript rules:

  • Found 31 instances of any type usage across multiple files
  • Found one @ts-ignore comment in src/utils/recurrenceUtils/recurrenceUtilityFunctions.ts

Key files requiring attention:

  • src/utils/useLocalstorage.ts: Multiple any type usages in API
  • src/state/action-creators/index.ts: Multiple any type usages in action creators
  • src/state/reducers/pluginReducer.ts: any type used for state
  • src/utils/StaticMockLink.ts: Multiple any type usages in request handling
  • src/components/AddOn/support/services/Plugin.helper.ts: any type used in plugin handling

The strict TypeScript rules should be enabled gradually after proper type definitions are added to replace the any types. Consider:

  1. First fixing the type definitions
  2. Then enabling these rules one at a time
  3. Or enabling them with warnings first ("warn" instead of "error")
🔗 Analysis chain

Verify the impact of strict TypeScript rules.

The configuration includes several strict TypeScript rules. Let's verify if the codebase is ready for these strict rules to avoid excessive errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential violations of strict TypeScript rules
echo "Checking for potential 'any' types..."
rg ":\s*any\b" --type=typescript

echo "Checking for non-null assertions..."
rg "[!]\." --type=typescript

echo "Checking for @ts-ignore or @ts-nocheck..."
rg "@ts-(ignore|nocheck)" --type=typescript

Length of output: 481


Script:

#!/bin/bash
# Check for potential violations of strict TypeScript rules in .ts and .tsx files
echo "Checking for potential 'any' types..."
rg ":\s*any\b" -g "*.{ts,tsx}"

echo "Checking for non-null assertions..."
rg "[!]\." -g "*.{ts,tsx}"

echo "Checking for @ts-ignore or @ts-nocheck..."
rg "@ts-(ignore|nocheck)" -g "*.{ts,tsx}"

# Also check for TypeScript files in the project
echo "Listing TypeScript files..."
fd "\.(ts|tsx)$"

Length of output: 29944

@Suyash878 Suyash878 changed the title Issue#2645 Migrating from eslintrc.json to eslint.config.js Dec 14, 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: 2

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

1-14: LGTM! Consider organizing imports for better maintainability.

The imports are comprehensive and include all necessary plugins. Consider organizing them into groups:

  • Node.js built-ins
  • ESLint core/compat
  • ESLint plugins
  • Parsers and utilities
+ // Node.js built-ins
 import path from 'node:path';
 import { fileURLToPath } from 'node:url';
+
+ // ESLint core/compat
 import js from '@eslint/js';
 import { FlatCompat } from '@eslint/eslintrc';
 import { fixupPluginRules } from '@eslint/compat';
 import globals from 'globals';
+
+ // ESLint plugins
 import react from 'eslint-plugin-react';
 import typescriptEslint from '@typescript-eslint/eslint-plugin';
 import jest from 'eslint-plugin-jest';
 import _import from 'eslint-plugin-import';
 import tsdoc from 'eslint-plugin-tsdoc';
 import prettier from 'eslint-plugin-prettier';
+
+ // Parsers and utilities
 import tsParser from '@typescript-eslint/parser';

25-34: Consider adding common build and test directories to ignores.

The ignore patterns cover most file types but could be enhanced with common build and test output directories.

 ignores: [
   '**/*.css',
   '**/*.scss',
   '**/*.less',
   '**/*.json',
   'src/components/CheckIn/tagTemplate.ts',
   '**/package.json',
   '**/package-lock.json',
   '**/tsconfig.json',
+  'build/**',
+  'dist/**',
+  'coverage/**',
+  'node_modules/**',
 ],

167-191: Consider adjusting React rule severity levels.

Some React rules might be too restrictive or inconsistent in their severity levels:

  • jsx-equals-spacing is set to "warn" while most other rules are "error"
  • function-component-definition is effectively disabled (0) but includes configuration
- 'react/jsx-equals-spacing': ['warn', 'never'],
+ 'react/jsx-equals-spacing': ['error', 'never'],

- 'react/function-component-definition': [
-   0,
-   {
-     namedComponents: 'function-declaration',
-   },
- ],
+ 'react/function-component-definition': ['error', {
+   namedComponents: ['function-declaration', 'arrow-function'],
+   unnamedComponents: 'arrow-function'
+ }],
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cf1714d and d089b64.

📒 Files selected for processing (1)
  • eslint.config.mjs (1 hunks)
🔇 Additional comments (2)
eslint.config.mjs (2)

36-43: Remove 'prettier' from the extends array to prevent conflicts.

Using both 'plugin:prettier/recommended' and 'prettier' in the extends array is redundant as 'plugin:prettier/recommended' already includes prettier's recommended configuration.

 ...compat.extends(
   'plugin:react/recommended',
   'eslint:recommended',
   'plugin:jest/recommended',
   'plugin:prettier/recommended',
   'plugin:@typescript-eslint/recommended',
-  'prettier',
 ),

81-113: Strict TypeScript rules need adjustments before enabling

The enabled TypeScript rules are quite strict and may cause numerous errors in the existing codebase. Consider a gradual approach to enabling these rules.

#!/bin/bash
# Verify impact of strict TypeScript rules
echo "Checking TypeScript files for potential violations..."

# Check for explicit any usage
echo "Files with 'any' type usage:"
rg ":\s*any\b" --type=typescript

# Check for non-null assertions
echo "Files with non-null assertions:"
rg "[!]\." --type=typescript

# Check for type assertions
echo "Files with type assertions:"
rg "as\s+\w+" --type=typescript

Comment on lines +124 to +130
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'interface',
format: ['PascalCase'],
prefix: ['Interface', 'TestInterface'],
},
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider restrictive interface naming convention.

The current configuration requires interfaces to be prefixed with either 'Interface' or 'TestInterface', which deviates from common TypeScript practices and may make the code more verbose.

 {
   selector: 'interface',
   format: ['PascalCase'],
-  prefix: ['Interface', 'TestInterface'],
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'interface',
format: ['PascalCase'],
prefix: ['Interface', 'TestInterface'],
},
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'interface',
format: ['PascalCase'],
},

Comment on lines +62 to +64
parser: tsParser,
ecmaVersion: 2018,
sourceType: 'module',
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update ECMAVersion to support modern JavaScript features.

The current ECMAVersion (2018) is outdated. Consider updating to a more recent version to support modern JavaScript features.

 parser: tsParser,
- ecmaVersion: 2018,
+ ecmaVersion: 2022,
 sourceType: 'module',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
parser: tsParser,
ecmaVersion: 2018,
sourceType: 'module',
parser: tsParser,
ecmaVersion: 2022,
sourceType: 'module',

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