Gelio / tslint-react-hooks

TSLint rule for detecting invalid uses of React Hooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shows as warning regardless of rules declaration

tylerthehaas opened this issue Β· comments

I have setup my tslint.json like this:

{
  "defaultSeverity": "error",
  "extends": ["tslint-config-airbnb", "tslint-react-hooks"],
  "jsRules": {},
  "rules": {
    "align": false,
    "import-name": false,
    "no-boolean-literal-compare": false,
    "no-this-assignment": false,
    "react-hooks-nesting": "error",
    "variable-name": false,
    "ter-indent": false,
    "ter-arrow-parens": false,
    "semicolon": false,
    "strict-boolean-expressions": false,
    "space-before-function-paren": false,
    "trailing-comma": [
      true,
      {
        "multiline": {
          "objects": "always",
          "arrays": "always"
        },
        "esSpecCompliant": true
      }
    ]
  },
  "rulesDirectory": []
}

but when I use hooks improperly it shows as a warning.

image

I would expect this to be underlined in red as an error.

That seems peculiar. I will try to replicate the issue and debug it πŸ˜„ Thanks for sharing πŸ‘

did you try "react-hooks-nesting": true?

yes I've tried all options.

@tylerthehaas I tried to replicate the issue. When using TSLint plugin for vscode the violations showed only as warnings. That is because this is the default behavior for this extension. Try to add:

"tslint.alwaysShowRuleFailuresAsWarnings": false

to workspace/user settings in VSCode. This made it so that the rule violations were shown as errors.

If that does not do it, try to lint your project using the command line and see if the violations are still warnings, not errors. Here is the output from my attempt:

Ξ» npx tslint -c tslint.json -p tsconfig.json src/**/*.tsx

ERROR: D:/Programowanie/open-source/tslint-react-hooks-test/src/App.tsx:8:5 - A hook cannot be used in a class component

Make sure the behavior is correct for other rules you use. It may be that this problem is not specific to tslint-react-hooks, but to your overall environment configuration πŸ™‚

@tylerthehaas Does the problem still appear, even after following my instructions from the post above?

I'm sorry I wasn't notified of your previous message. I will try at work tomorrow.

@tylerthehaas any progress? πŸ™‚

sorry about the delay. but yes that fixed the issue. Would you like me to submit a pr to add that to the documentation?

No worries πŸ™‚ That was not a problem with this specific rule, but with the vscode extension, so I would rather not add that information to this project as it is not closely related

Thank you for your effort πŸ‘