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

Eslint upgrade to v9 #9344

Conversation

amjithtitus09
Copy link
Contributor

@amjithtitus09 amjithtitus09 commented Dec 9, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Introduced a new ESLint configuration file to enhance linting for JavaScript and TypeScript projects.
    • Added support for internationalization and MDX linting.
    • Added a new context for resetting history state in the application.
  • Bug Fixes

    • Removed outdated ESLint configuration to streamline the linting process.
    • Improved error handling in locale file management.
  • Chores

    • Updated and added various dependencies related to ESLint and TypeScript for improved code quality and consistency.
    • Enhanced the robustness and clarity of several components, including AssetCreate, ExcelFileDragAndDrop, and Sidebar.
    • Improved notification handling in the service worker.

@amjithtitus09 amjithtitus09 requested a review from a team as a code owner December 9, 2024 18:48
Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Caution

Review failed

The head commit changed during the review from 5ceeaba to 0291d9c.

Walkthrough

The changes in this pull request involve the removal of the .eslintrc.json file and the addition of a new ESLint configuration file, eslint.config.mjs. The new configuration consolidates and updates the linting setup for JavaScript and TypeScript projects, incorporating various plugins and rules. Additionally, the package.json file has been modified to include new dependencies and update existing ones, particularly those related to ESLint and its plugins, ensuring compatibility with the latest version.

Changes

File Change Summary
.eslintrc.json Deleted; contained previous ESLint configuration settings.
eslint.config.mjs Added; new ESLint configuration with comprehensive rules for JavaScript, TypeScript, React, and MDX.
package.json Updated dependencies and devDependencies; added new packages and updated versions of existing ones.

Assessment against linked issues

Objective Addressed Explanation
Upgrade eslint to v9 (9050)
Ensure plugins are compatible with eslint v9 (9050)
Update the eslint config to newest version (9050)

Possibly related PRs

  • Update dependencies #9049: Involves updates to ESLint dependencies, which are relevant to the modifications made in this PR regarding ESLint configuration.

🐰 In the code we hop and play,
New ESLint rules lead the way.
With packages fresh and bright,
Our code will shine, oh what a sight!
Let's lint and code, all day long,
In harmony, we all belong! 🐇✨


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 0291d9c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67692d7ce3c65700083ac126
😎 Deploy Preview https://deploy-preview-9344--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link
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: 3

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

15-26: Consider adding common directories to the ignore list

The current ignores list excludes several directories and file types. To further optimize linting performance, consider adding node_modules, .cache, and coverage directories to the ignore list.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0f58adc and 9e6a401.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .eslintrc.json (0 hunks)
  • eslint.config.mjs (1 hunks)
  • package.json (4 hunks)
💤 Files with no reviewable changes (1)
  • .eslintrc.json
🔇 Additional comments (4)
eslint.config.mjs (2)

66-67: Verify the parserOptions.project path

Ensure that the project path in parserOptions ("./tsconfig.json") correctly references your TypeScript configuration file. An incorrect path can lead to linting errors or reduced performance.


139-139: ⚠️ Potential issue

Verify the spread operator usage in MDX configuration

Using the spread operator with mdxPlugin.configs.recommended may not work as expected. Confirm that this syntax is supported in the ESLint flat config. If issues arise, consider importing and extending the recommended configuration.

package.json (2)

63-63: Addition of @radix-ui/react-icons is appropriate

The new dependency @radix-ui/react-icons has been added. Ensure it's used in the project to justify its inclusion.


108-110: ESLint and related packages updated successfully

The updates to ESLint and its plugins align with the upgrade to ESLint v9. The inclusion of new packages like @eslint/compat, @eslint/eslintrc, and globals supports the new configuration.

Also applies to: 128-129, 136-136, 138-138, 142-142, 144-144

eslint.config.mjs Outdated Show resolved Hide resolved
eslint.config.mjs Outdated Show resolved Hide resolved
package.json Outdated
@@ -81,6 +81,7 @@
"dayjs": "^1.11.13",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2",
"eslint-plugin-markdown": "^5.1.0",
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 9, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Move eslint-plugin-markdown to devDependencies

eslint-plugin-markdown is a development tool and should be listed under devDependencies to prevent it from being included in the production build.

Apply this diff to fix the issue:

  "dependencies": {
-   "eslint-plugin-markdown": "^5.1.0",
  },
  "devDependencies": {
+   "eslint-plugin-markdown": "^5.1.0",

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member

Choose a reason for hiding this comment

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

@amjithtitus09 this package is not required

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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

26-50: Consider adding TypeScript-specific compiler options

While the global settings are well-configured, consider adding TypeScript compiler options for better type checking:

 languageOptions: {
   ecmaVersion: 12,
   sourceType: "module",
+  parserOptions: {
+    project: "./tsconfig.json",
+    tsconfigRootDir: ".",
+  },
   globals: {
     ...globals.browser,
     ...globals.node,
   },
   parserOptions: {
     ecmaFeatures: {
       jsx: true,
     },
   },
 },

116-117: Simplify Prettier configuration

The Prettier plugin automatically sets up both the plugin and config when using eslint-plugin-prettier/recommended.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 489e7df and 00663e2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • eslint.config.mjs (1 hunks)
  • package.json (4 hunks)
  • src/components/Facility/AssetCreate.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🪛 eslint
eslint.config.mjs

[error] 10-11: Delete

(prettier/prettier)


[error] 118-118: Insert

(prettier/prettier)

🔇 Additional comments (5)
eslint.config.mjs (2)

1-24: LGTM! Base configuration follows ESLint v9 best practices

The imports and base configuration are well-structured, following the new flat config format introduced in ESLint v9.

🧰 Tools
🪛 eslint

[error] 10-11: Delete

(prettier/prettier)


65-66: Avoid spreading recommended rules directly

Spreading tseslint.configs.recommended.rules and plugin rules can cause conflicts or unexpected behavior.

Also applies to: 86-87

src/components/Facility/AssetCreate.tsx (3)

163-169: LGTM! Improved readability of section visibility logic

The refactored implementation using direct conditional statements is clearer and maintains the same functionality.


196-207: LGTM! Enhanced null safety in asset data handling

The addition of null checks before setting state values improves type safety and prevents potential runtime errors.


499-499: LGTM! Improved className handling

The use of template literals for dynamic class assignments improves code readability and maintainability.

@amjithtitus09
Copy link
Contributor Author

Hey @sainak, I've made the requested changes

package.json Outdated
@@ -81,6 +81,7 @@
"dayjs": "^1.11.13",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2",
"eslint-plugin-markdown": "^5.1.0",
Copy link
Member

Choose a reason for hiding this comment

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

@amjithtitus09 this package is not required

src/components/Facility/AssetCreate.tsx Outdated Show resolved Hide resolved
@sainak sainak requested a review from rithviknishad December 13, 2024 08:06
@nihal467
Copy link
Member

@amjithtitus09 lint is failing in your PR, do check it

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
eslint.config.mjs (2)

54-78: 🛠️ Refactor suggestion

Refactor TypeScript configuration to use extends

The TypeScript configuration should use extends instead of spreading rules to avoid potential conflicts.

Apply this diff to improve the configuration:

{
  files: ["**/*.{ts,tsx}"],
  plugins: {
    "@typescript-eslint": tseslint,
  },
  languageOptions: {
    parser: tsParser,
    parserOptions: {
      project: "./tsconfig.json",
    },
  },
+ extends: [
+   "@typescript-eslint/recommended"
+ ],
  rules: {
-   ...tseslint.configs.recommended.rules,
    "@typescript-eslint/no-unused-vars": [
      "error",
      {
        argsIgnorePattern: "^_",
        varsIgnorePattern: "^_",
        caughtErrorsIgnorePattern: "^_",
      },
    ],
    "@typescript-eslint/no-explicit-any": "warn",
    "no-undef": "off",
  },
}

80-92: 🛠️ Refactor suggestion

Refactor React configuration to use extends

The React configuration should use extends instead of spreading rules to avoid maintenance challenges.

Apply this diff to improve the configuration:

{
  files: ["**/*.{jsx,tsx}"],
  plugins: {
    react: reactPlugin,
    "react-hooks": reactHooksPlugin,
  },
+ extends: [
+   "plugin:react/recommended",
+   "plugin:react-hooks/recommended"
+ ],
  rules: {
-   ...reactPlugin.configs.recommended.rules,
-   ...reactHooksPlugin.configs.recommended.rules,
    "react/prop-types": "off",
  },
}
🧹 Nitpick comments (2)
src/Locale/update_locale.js (1)

63-66: Enhance error handling with more context

The current error handling discards the original error information which could be useful for debugging.

Apply this diff to improve error handling:

    try {
      files[file] = JSON.parse(readFile(`./${folderName}/${file}`));
-   } catch {
-     throw new Error(`Cannot parse ${file} file!`);
+   } catch (error) {
+     throw new Error(`Cannot parse ${file} file: ${error.message}`);
    }
src/components/Common/ExcelFIleDragAndDrop.tsx (1)

Line range hint 119-127: Consider enhancing file validation

While the current file type validation works, consider these improvements:

  1. Add file size limits to prevent large uploads
  2. Use MIME type checking in addition to file extension validation
  3. Internationalize error messages for consistency with other translations

Example implementation:

 const fileTypes = [
   "vnd.ms-excel",
   "text/csv",
   "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
 ];
+const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB

 if (!fileTypes.includes(droppedFile?.type)) {
-  dragProps.setFileDropError("Please drop a Excel / CSV file to upload!");
+  dragProps.setFileDropError(t("errors.invalid_file_type"));
   setSelectedFile(null);
   return;
 }
+
+if (droppedFile.size > MAX_FILE_SIZE) {
+  dragProps.setFileDropError(t("errors.file_too_large"));
+  setSelectedFile(null);
+  return;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb5728a and ffa6d1a.

📒 Files selected for processing (9)
  • eslint.config.mjs (1 hunks)
  • src/CAREUI/interactive/SlideOver.tsx (1 hunks)
  • src/Locale/update_locale.js (1 hunks)
  • src/PluginEngine.tsx (0 hunks)
  • src/Providers/HistoryAPIProvider.tsx (1 hunks)
  • src/components/Common/ExcelFIleDragAndDrop.tsx (4 hunks)
  • src/components/Common/Sidebar/Sidebar.tsx (1 hunks)
  • src/components/Resource/ResourceBoard.tsx (1 hunks)
  • src/service-worker.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • src/PluginEngine.tsx
  • src/service-worker.ts
🧰 Additional context used
🪛 eslint
eslint.config.mjs

[error] 10-11: Delete

(prettier/prettier)


[error] 120-120: Insert

(prettier/prettier)

🔇 Additional comments (9)
eslint.config.mjs (2)

1-24: LGTM: Base configuration follows ESLint v9 flat config format

The base configuration and imports are well-structured. The ignore patterns are comprehensive and cover common build/output directories.

🧰 Tools
🪛 eslint

[error] 10-11: Delete

(prettier/prettier)


94-116: 🛠️ Refactor suggestion

Refactor i18next configuration to use extends

Follow the same pattern as other plugins by using extends instead of spreading rules.

Apply this diff to improve the configuration:

{
  files: ["**/*.{js,jsx,ts,tsx}"],
  plugins: {
    i18next: i18nextPlugin,
  },
+ extends: [
+   "plugin:i18next/recommended"
+ ],
  rules: {
-   ...i18nextPlugin.configs.recommended.rules,
    "i18next/no-literal-string": [
      "warn",
      {
        mode: "jsx-only",
        "jsx-attributes": {
          include: ["label", "placeholder", "error", "title"],
          exclude: [".*"],
        },
        callees: {
          exclude: [".*"],
        },
      },
    ],
  },
}

Likely invalid or redundant comment.

src/Providers/HistoryAPIProvider.tsx (1)

Line range hint 1-40: LGTM: Component follows React best practices

The implementation is clean and follows React patterns. The new ResetHistoryContext is properly integrated.

src/CAREUI/interactive/SlideOver.tsx (1)

119-119: LGTM: Clean optional chaining implementation

The change from explicit null check to optional chaining operator improves code conciseness while maintaining the same functionality and type safety.

src/components/Resource/ResourceBoard.tsx (1)

44-44: Whitespace change

This is a minor formatting change with no functional impact.

src/components/Common/Sidebar/Sidebar.tsx (1)

209-209: LGTM: Clean context definition

The removal of unnecessary whitespace and comments improves code cleanliness while maintaining the same functionality.

src/components/Common/ExcelFIleDragAndDrop.tsx (3)

50-50: LGTM: Proper handling of optional callbacks

The addition of optional chaining operators for onClose and setIsValid callbacks aligns with their optional status in the Props interface and ensures type-safe function calls.

Also applies to: 101-101


202-204: LGTM: Consistent handling of optional callback

The optional chaining for setIsValid is correctly applied in the cancel handler, maintaining consistency with other usages and ensuring type safety.


232-232: LGTM: Enhanced security for external link

The addition of rel="noreferrer" is a security best practice that prevents the opened page from accessing the window.opener property, protecting against potential reverse tabnabbing attacks.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 17, 2024
Copy link

👋 Hi, @amjithtitus09,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@amjithtitus09
Copy link
Contributor Author

@nihal467 Just to confirm, what approach should I take here. Am I supposed to make the code changes to fix wherever there are lint fails? Or should I override the lint rules to bypass any of these?

cc: @sainak

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 18, 2024
@sainak
Copy link
Member

sainak commented Dec 20, 2024

@amjithtitus09 you can try to fix the easily fixable errors, and change the rest to warnings instead of errors temporarily along with creating issues to fix the errors and revert the rule change

@sainak sainak removed needs-triage question Further information is requested merge conflict pull requests with merge conflict labels Dec 20, 2024
Copy link

👋 Hi, @amjithtitus09,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 22, 2024
@amjithtitus09 amjithtitus09 force-pushed the issues/9050/eslint-upgrade-v9 branch from 5ceeaba to 0291d9c Compare December 23, 2024 09:29
@sainak
Copy link
Member

sainak commented Dec 23, 2024

@amjithtitus09 why was this pr closed?

@amjithtitus09
Copy link
Contributor Author

@sainak I discarded the commits by mistake and the PR got closed. Opening another one with existing commits

@amjithtitus09
Copy link
Contributor Author

Changes moved to #9538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge conflict pull requests with merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade eslint to v9
3 participants