Skip to content

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

@melxy1997

Description

@melxy1997

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:

Metadata

Metadata

Assignees

Labels

A-linterArea - LinterC-bugCategory - Bug

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions