Mah*_*oni 6 javascript websocket eslint react-native
我得到以下的eslint错误:
42:21 error 'WebSocket' is not defined no-undef
Run Code Online (Sandbox Code Playgroud)
你无法导入WebSocket react-native因为它是全局的,但是当我将WebSocket作为全局变量添加到我的.eslintrc.yml时候它不会改变错误的结果:
globals:
WebSocket: true
Run Code Online (Sandbox Code Playgroud)
如何在React Native应用程序的ES Lint中将WebSocket定义为全局?
这可以修复吗?目前我的.eslintrc看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
我可以使用内联注释摆脱它
/* globals WebSocket:true */
Run Code Online (Sandbox Code Playgroud)
此外,当我不从airbnb eslint继承,但我无法弄清楚Airbnb中的哪个lint规则是否有责任阻止它.
根据您提供的信息,您的配置文件似乎由于某种原因没有被拾取。配置globals看起来正确并且应该可以工作。为了弄清楚发生了什么,您应该做两件事。首先,您可以运行eslint --print-config path_to_some_js_file查看 ESLint 解决所有依赖项和级联后的配置。该配置很可能不会被globals声明。之后,您可以运行eslint --debug path_to_file查看 ESLint 正在使用的所有配置文件。如果您的文件未包含在内,请检查所有其他配置文件并验证它们是否不包含root: true在其中(这将阻止 ESLint 合并父目录中的配置)。有关 CLI 标志的更多信息,您可以查看ESLint 文档
| 归档时间: |
|
| 查看次数: |
877 次 |
| 最近记录: |