Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add must-have eslint rules #7261

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft

Conversation

reactoholic
Copy link
Contributor

@reactoholic reactoholic commented Nov 28, 2024

This PR is entirely for test purposes. One should pull this branch locally and check how many issues the client has from TS disabling and missing dependency array variables which is absolutely not good. Dependency array variables can change entire behavour and extremely dangerous avoiding them when they must be present in the array.

Summary by CodeRabbit

  • New Features

    • Updated linting rules to enhance code quality, including new rules for React hooks.
    • Added recommendation for the React Hooks extension in Visual Studio Code.
  • Bug Fixes

    • Updated ECMAScript version to 2022 for improved compatibility.
  • Chores

    • Incremented package version to 0.77.0.
    • Updated ESLint dependency and added new ESLint plugins for React and React Hooks.

Signed-off-by: reactoholic <[email protected]>
Signed-off-by: reactoholic <[email protected]>
Copy link

coderabbitai bot commented Nov 28, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request includes updates to the .eslintrc.js configuration file, enhancing linting rules and updating the ECMAScript version to 2022. It modifies the rules for React and TypeScript, including disabling prop-types enforcement and adjusting warnings for React hooks. The .vscode/extensions.json file is updated to recommend a new extension for React hooks. Additionally, the package.json file reflects a version increment and updates to the eslint dependency, along with the addition of eslint-plugin-react and eslint-plugin-react-hooks for improved linting capabilities.

Changes

File Change Summary
.eslintrc.js - Updated ecmaVersion from 2016 to 2022
- Added rules: 'react/prop-types': 'off', '@typescript-eslint/ban-ts-comment': 'warn', 'react-hooks/rules-of-hooks': 'error'
- Updated rule: 'react-hooks/exhaustive-deps': 'warn' from off
- Modified unused variables rule based on environment function.
.vscode/extensions.json - Added extension: "ms-vscode.vscode-react-hooks"
package.json - Updated dependency: "eslint": "^8.57.0" to "eslint": "^8.57.1"
- Added dependencies: "eslint-plugin-react": "^7.37.2", "eslint-plugin-react-hooks": "^5.0.0"

Possibly related PRs

  • Release 0.71 #6881: This PR updates the version number in package.json, which is related to the main PR's updates in the same file, indicating a connection through version management.
  • new release version 0.75.0 #7058: Similar to Release 0.71 #6881, this PR also updates the version number in package.json, showing a direct relationship through versioning changes.
  • Master to develop 0.76 #7153: This PR involves a version downgrade in package.json, maintaining the connection to the main PR's updates in the same file.
  • Coderabbit config update #7260: Although primarily focused on configuration updates, it includes changes relevant to JavaScript and React, which may indirectly relate to the linting improvements in the main PR.

Suggested reviewers

  • bobbykolev
  • ccanos
  • hero101

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.

@reactoholic reactoholic self-assigned this Nov 28, 2024
@reactoholic
Copy link
Contributor Author

@coderabbitai help

Copy link

coderabbitai bot commented Nov 28, 2024

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.

@reactoholic
Copy link
Contributor Author

@coderabbitai full review

Copy link

coderabbitai bot commented Nov 28, 2024

✅ Actions performed

Full review triggered.

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)
.vscode/extensions.json (1)

6-7: LGTM! Good addition of the React hooks extension.

The addition of ms-vscode.vscode-react-hooks is a valuable improvement that will provide better IDE support for React hooks development, complementing the ESLint rules being added in this PR.

This extension will help developers by:

  • Providing IntelliSense for React hooks
  • Offering quick fixes for common hooks-related issues
  • Supporting the enforcement of hooks rules at the IDE level
.eslintrc.js (1)

43-43: Excellent addition of React Hooks rules!

These rules are crucial for preventing bugs in React applications:

  • rules-of-hooks: Enforces Rules of Hooks, preventing runtime errors
  • exhaustive-deps: Warns about missing dependency array variables, which directly addresses the PR objectives about preventing dangerous behavioral changes

The warning level for exhaustive-deps is a good choice as it highlights potential issues while allowing for justified exceptions.

Consider documenting common patterns for handling dependencies in React hooks, especially for cases where certain dependencies need to be intentionally omitted.

Also applies to: 45-45

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 23fac77 and b5997d7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .eslintrc.js (3 hunks)
  • .vscode/extensions.json (1 hunks)
  • package.json (1 hunks)
🔇 Additional comments (3)
.eslintrc.js (2)

41-42: LGTM! Good TypeScript-first configuration

  • Disabling react/prop-types is correct as TypeScript handles type checking
  • Warning on @ts- comments helps prevent unnecessary type assertions

Line range hint 15-16: Verify ESLint plugin dependencies

The configuration uses React-specific rules. Let's ensure all necessary plugins are properly configured.

✅ Verification successful

ESLint plugin dependencies are properly configured

The required ESLint plugins for React (eslint-plugin-react and eslint-plugin-react-hooks) are correctly listed in the package dependencies, ensuring proper functionality of the React-specific rules in the ESLint configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if required ESLint plugins are listed in package.json
cat package.json | jq '.dependencies + .devDependencies | keys' | grep -E 'eslint-plugin-(react|react-hooks)'

Length of output: 167

package.json (1)

191-191: LGTM! The ESLint dependencies update aligns with the PR objectives.

The changes appropriately add the necessary ESLint plugins for enforcing React and React Hooks rules, which will help catch issues with missing dependency array variables. The version ranges are appropriate for dev dependencies.

Let's verify the compatibility of these versions:

Also applies to: 194-195

✅ Verification successful

ESLint dependencies are compatible with each other

The peer dependency checks confirm that:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility between eslint and its plugins

# Check the peer dependencies of eslint-plugin-react and eslint-plugin-react-hooks
npm info [email protected] peerDependencies --json
npm info [email protected] peerDependencies --json

# Check for any known compatibility issues or breaking changes
npm view [email protected] changelog
npm view [email protected] changelog
npm view [email protected] changelog

Length of output: 410

.eslintrc.js Show resolved Hide resolved
@reactoholic reactoholic added production Something that is happening in the production environment poc and removed production Something that is happening in the production environment labels Nov 28, 2024
@bobbykolev
Copy link
Contributor

As I'd like to have less dusty PRs, let's quickly discuss the suggested changes and agree on an approach.

As far as I understand, we had some of these configurations in the past. Although nice to have, I don't think we have time to fix either all dependency arrays or the TS ignore comments.

I'd suggest updating only the ESLINT as suggested (if it doesn't require many changes). Let's collect the other suggestions in a technical ticket and keep the PRs fresh.

@ccanos , @reactoholic , let me know your thoughts.

@reactoholic
Copy link
Contributor Author

As I'd like to have less dusty PRs, let's quickly discuss the suggested changes and agree on an approach.

As far as I understand, we had some of these configurations in the past. Although nice to have, I don't think we have time to fix either all dependency arrays or the TS ignore comments.

I'd suggest updating only the ESLINT as suggested (if it doesn't require many changes). Let's collect the other suggestions in a technical ticket and keep the PRs fresh.

@ccanos , @reactoholic , let me know your thoughts.

The TS ignores are only in 3 places, these are fast to fix, but I agree not fixing all dep arrays as this hides insanely big chance of messing up the app. I agree on adding the rules as a starter, possibly fixing the 3 TS ignores.

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

Successfully merging this pull request may close these issues.

2 participants