Defining WebSocket as Global in ES Lint for React Native Application

I get the following eslint error:

42:21  error  'WebSocket' is not defined  no-undef

You cannot import WebSocket from react-nativebecause it is global, but when I add WebSocket as global variables to mine .eslintrc.yml, it does not change the error result:

globals:
   WebSocket: true

How to define WebSocket as global in ES Lint for a React Native application?

Can this be fixed? Currently my .eslintrc looks like this:

env:
  browser: false
  es6: true
  commonjs: true
  node: true
extends: 'airbnb'
parser: babel-eslint
globals:
    WebSocket: true
parserOptions:
  ecmaFeatures:
    experimentalObjectRestSpread: true
    jsx: true
  sourceType: module
plugins:
  - react
  - react-native
rules:
  indent:
    - error
    - tab
    - {"SwitchCase": 1}
  linebreak-style:
    - error
    - unix
  quotes:
    - error
    - double
  semi:
    - error
    - never
  no-tabs: off
  max-len: off
  no-console: off
  no-plusplus: off
  global-require: off
  import/no-unresolved: off
  import/extensions: off
  class-methods-use-this: off
  react/jsx-no-bind: off
  react/forbid-prop-types: off
  react/prefer-stateless-function: off
  react/jsx-indent: [2, 'tab']
  react/jsx-indent-props: [2, 'tab']
  react/jsx-filename-extension: [1, { extensions: ['.js', '.jsx'] }]
  react/jsx-uses-react: error
  react/jsx-uses-vars: error
  react-native/no-unused-styles: 2
  react-native/split-platform-components: 2
  react-native/no-inline-styles: off
  react-native/no-color-literals: off

I can get rid of it using the inline comment

/* globals WebSocket:true */

Also, when I do not inherit from airbnb eslint, but I cannot figure out which lint rule in Airbnb is responsible for blocking this.

+4
source share
1

, , - . globals . , , . eslint --print-config path_to_some_js_file, , , ESLint . , config globals. eslint --debug path_to_file, , ESLint. , , root: true ( ESLint ). CLI ESLint

+1

Source: https://habr.com/ru/post/1671322/


All Articles