включение eslint-response-hooks отключает все правила eslint - PullRequest
0 голосов
/ 29 апреля 2020

Я пытаюсь получить react-hooks правила для eslint, но, похоже, он не работает с моей настройкой (VSCode, CRA, airbnb, tslint, prettier).

Вот мой .eslintr c. json до его разрыва:

{
  "env": {
    "browser": true,
    "es6": true,
    "jest": true
  },
  "extends": ["plugin:react/recommended", "airbnb", "prettier"],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint"],
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".jsx", ".tsx"] }]
  }
}

Вот мой devDependencies:

  "devDependencies": {
    "@testing-library/jest-dom": "^5.5.0",
    "@testing-library/react": "^10.0.3",
    "@testing-library/user-event": "^10.1.0",
    "@types/jest": "^25.2.1",
    "@types/node": "^13.13.4",
    "@types/react": "^16.9.34",
    "@types/react-dom": "^16.9.7",
    "@typescript-eslint/eslint-plugin": "^2.30.0",
    "@typescript-eslint/parser": "^2.30.0",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.1.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^3.0.0",
    "prettier": "^2.0.5",
    "typescript": "~3.8.3"
  },

Затем я попытался добавить следующее к extends in .eslintrc:

"extends": ["plugin:react/recommended", "plugin:react-hooks/recommended", "airbnb", "prettier"],

Я также попытался поместить "plugin:react-hooks/recommended" в другое место в массиве. Независимо от того, что я делаю, он нарушит все остальные правила, в том числе и свои.

Я также попытался добавить следующее к plugins и rules:

"plugins": ["react", "react-hooks", "@typescript-eslint"],
"rules": {
  // ...
  "react-hooks/rules-of-hooks": "error",
  "react-hooks/exhaustive-deps": "warn"
}

И, конечно, тестовый код для проверки правил пуха:

  const [a, b] = React.useState("Hey");

  React.useEffect(() => {
    React.useMemo(() => {}, []);
    if (a) b("Yeppp");
    if (props.what) console.log(props.what);
    exampleMethod();
  }, []);

  const exampleMethod = () => {};

РЕДАКТИРОВАТЬ: забыл упомянуть, я также пытался использовать airbnb/hooks в extends, а также:

"extends": ["plugin:react/recommended", "airbnb", "airbnb/hooks", "prettier"],

1 Ответ

0 голосов
/ 30 апреля 2020

Я нашел решение, поэтому отвечаю на свой вопрос.

В документах eslint-plugin-реагировать-hooks указано, что при использовании Create React App необходимо NOT добавить модуль непосредственно в package.json. * 1008. * Следовательно, решение состоит в том, чтобы удалить eslint-plugin-react-hooks из devDependencies.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...