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

bug(linter): false positve "react-hooks/RulesOfHooks" with default export #7555

Closed
melxy1997 opened this issue Nov 30, 2024 · 0 comments · Fixed by #7570
Closed

bug(linter): false positve "react-hooks/RulesOfHooks" with default export #7555

melxy1997 opened this issue Nov 30, 2024 · 0 comments · Fixed by #7570
Assignees
Labels
A-linter Area - Linter C-bug Category - Bug

Comments

@melxy1997
Copy link

What version of Oxlint are you using?

0.13.2

What command did you run?

yarn oxlint

What does your .oxlint.json config file look like?

{
    "$schema": "../../node_modules/oxlint/configuration_schema.json",
    "plugins": [
        "oxc",
        "react",
        "typescript",
        "eslint-plugin-import",
        "eslint-plugin-jest",
        "eslint-plugin-react-hooks"
    ],
    "env": {
        "browser": true,
        "amd": true,
        "es6": true
    },
    "globals": {
        "If": "readonly",
        "Choose": "readonly",
        "When": "readonly",
        "Otherwise": "readonly",
    },
    "rules": {
        "react-hooks/rules-of-hooks": "error",
        "react-hooks/exhaustive-deps": "warn",
        "no-unused-vars": ["error", { "args": "none", "caughtErrors": "none" }],
        "no-console": ["error", { "allow": ["warn", "error", "info"] }],
        "import/order": 0,
        "import/no-self-import": 0,
        "import/no-cycle": 0,
        "import/no-duplicates": 0,
        "import/no-useless-path-segments": 0,
        "import/named": 0,
        "import/no-named-as-default": 0,
        "import/export": 0,
        "no-duplicate-imports": 1,
        "jest/no-identical-title": "warn",
        "jest/valid-expect": "warn",
        "jest/no-mocks-import": "off",
        "jest/no-commented-out-tests": "off"
    }}

What happened?

  • In the official implementation of react-hooks/RulesOfHooks, it seems that hooks are not disallowed within functions that are default exports, whereas in our Rust version of the implementation, such behavior is restricted. Of course, I also don't think this is an incorrect implementation approach.
  • It's just that in the project I'm working on, there's a requirement to "throw errors for files that violate RulesOfHooks," so using oxlint results in a large number of errors being thrown. (However, using ESLint does not result in these errors.)
  • I would like to propose an expectation that we can align with the official implementation, which would be great;
  • Alternatively, adding an Advanced Configuration to bypass this restriction on default exports, similar to:
{
    "react-hooks/rules-of-hooks": ["error", {
      "allowHooksInDefaultExport": true
    }]
}

References:

@melxy1997 melxy1997 added A-linter Area - Linter C-bug Category - Bug labels Nov 30, 2024
@camc314 camc314 changed the title linter: An action of "react-hooks/RulesOfHooks" bug(linter): An action of "react-hooks/RulesOfHooks" Dec 1, 2024
@camc314 camc314 self-assigned this Dec 1, 2024
@camc314 camc314 changed the title bug(linter): An action of "react-hooks/RulesOfHooks" bug(linter): false positve "react-hooks/RulesOfHooks" with default export Dec 1, 2024
@camc314 camc314 closed this as completed Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants