1

How do I correctly add React to the allowed list of unused variables?

Problem highlight in editor tab

VSCODE problems tab showing one ESLINT problem with React unusing imported variable

Problem highlighting in yaml config file

VSCODE problems tab showing one ESLINT problem with React unusing imported variable

.eslintrc.yml

env:
  browser: true
  commonjs: true
  es6: true
  node: true
extends: 'eslint:recommended'
parserOptions:
  ecmaFeatures:
    experimentalObjectRestSpread: true
    jsx: true
  sourceType: module
plugins:
  - react
rules:
  indent:
    - error
    - tab
  linebreak-style:
    - error
    - unix
  quotes:
    - error
    - single
  semi:
    - error
    - never
globals:
    React: true

In fact, the React imported as a variable is used by the JSX as an environment. You can see this if you do not import React.

Terminal verbose error on React absent in App scope

north.inhale
  • 483
  • 2
  • 9
  • 20
  • 1
    Have you tried adding `"eslint:recommended"` and `"plugin:react/recommended"` to `extends` in `.eslintrc.yml`? – Tholle Aug 04 '18 at 12:18
  • No it's not actualy duplicated, because in my case, using YAML – north.inhale Aug 04 '18 at 12:23
  • Yes it help https://s.mail.ru/KX6d/9LrmgS7gT - YAML and https://s.mail.ru/ooHw/24FtJT7gX - Problems tab – north.inhale Aug 04 '18 at 12:27
  • 1
    But... "The react/recommended set of rules adds many other rules you may not want." They also found the solution for that problem, but not for YAML. Anyway let it be, i'll try to work this this simple (first) solution. Thank you. – north.inhale Aug 04 '18 at 12:32

0 Answers0