简体   繁体   English

React Native-Eslint错误描述不清楚

[英]React native-eslint error description is unclear

I created the react-native project and was doing some experiments with style guides and plugin, I created some mistakes to check how eslint error description work. 我创建了react-native项目,并使用样式指南和插件进行了一些实验,我创建了一些错误来检查eslint错误描述的工作方式。 Here is some code which I wrote and put an error(a comma) in app.js file. 这是我编写的一些代码,并将错误(逗号)放在app.js文件中。

app.js app.js

import React, { Component } from 'react'
import { Text, View } from 'react-native'

const App = () => (, <---------------------- this is the error(a comma)
  <View style={{ flex: 1 }}>
    <Text>hi</Text>
  </View>
)

export default App

Following is the error screenshot: 以下是错误截图: 在此处输入图片说明 As we can see that in the error description of the eslint, there are some "[39m 36m" embedded in between. 我们可以看到在eslint的错误描述中,在它们之间嵌入了一些[[39m 36m]。
What could be the reason for this unstructured error message? 此非结构化错误消息的原因可能是什么?
please help. 请帮忙。
Here is some other files attached. 这是附加的一些其他文件。

.eslintrc file .eslintrc文件

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "plugins": ["react", "flowtype", "jsx-a11y", "import"],
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "react/prefer-stateless-function": [1, { "ignorePureComponents": true }],
    "react/forbid-prop-types": [0, { "forbid": [] }],
    "import/extensions": [1, "never", { "svg": "always" }],
    "import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": true,
        "optionalDependencies": false,
        "peerDependencies": false
      }
    ],
    "semi": ["error", "never"]
  },
  "env": {
    "jest": true
  }
}

package.json package.json

{
  "name": "auth1",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "lint": "eslint src",
    "pretty":
      "prettier --semi false --print-width 100 --single-quote --trailing-comma all --write \"src/**/*.js\"",
    "precommit": "lint-staged && yarn test",
    "flow": "flow",
    "flow stop": "flow stop",
    "flow status": "flow status",
    "flow coverage": "flow coverage"
  },
  "lint-staged": {
    "*.js": ["yarn pretty", "git add"]
  },
  "dependencies": {
    "react": "16.3.0-alpha.1",
    "react-native": "0.54.0"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.2",
    "babel-jest": "22.4.1",
    "babel-preset-flow": "^6.23.0",
    "babel-preset-react-native": "4.0.0",
    "eslint": "^4.18.2",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-flowtype": "^2.46.1",
    "eslint-plugin-import": "^2.9.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    "flow-bin": "0.65.0",
    "husky": "^0.14.3",
    "jest": "22.4.2",
    "lint-staged": "^7.0.0",
    "prettier": "^1.11.1",
    "react-test-renderer": "16.3.0-alpha.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

Also, I installed eslint and Flow-bin, both can identifies the error(as you can see in screenshot above under problems tab), but do we need to use both and if not which one to prefer or if both have different purpose please help me understand. 另外,我安装了eslint和Flow-bin,两者都可以识别错误(如您在上面的屏幕快照中的“ 问题”选项卡下所示),但是我们是否需要同时使用两者,如果不是,则最好使用哪一个,或者如果两者目的不同,请帮助我明白了

Thanks in Advance. 提前致谢。

You probably need to specify the --no-color option to eslint . 您可能需要为eslint指定--no-color选项。 Those are ANSI escape sequences, which is how color is added to the console messages. 这些是ANSI转义序列,这是将颜色添加到控制台消息的方式。 If you get the same problem in your terminal, that might also need configuring to handle ANSI, or use the CLI option to disable color. 如果您在终端中遇到相同的问题,则可能还需要进行配置以处理ANSI,或使用CLI选项禁用颜色。

eslint and flowtype serve different purposes. eslintflowtype具有不同的用途。 Flow will pick up certain syntax errors, but eslint will pick up more esoteric code constructs that can cause problems (assuming configured to do so). Flow将获取某些语法错误,但是eslint将获取更多可能导致问题的深奥代码构造(假设配置为这样做)。

Flow will interpret the types you specify and warn/error when you are trying to use incompatible types (in assignment, parameters, returns etc). 当您尝试使用不兼容的类型(赋值,参数,返回等)时,Flow将解释您指定的类型并发出警告/错误。

With color: 带颜色:

> eslint . "--color"


[4m/Users/xxxx/yyyy.js[24m
  [2m7:13[22m  [31merror[39m  Parsing error: Unexpected token

[0m [90m  5 | [39m}[0m
[0m [90m  6 | [39m[0m
[0m[31m[1m>[22m[39m[90m  7 | [39m[36mfunction[39m f({[33m,[39m[0m
[0m [90m    | [39m            [31m[1m^[22m[39m[0m
[0m [90m  8 | [39m  [90m// $FlowFixMe[39m[0m
[0m [90m  9 | [39m  a [33m=[39m [35m1[39m[33m,[39m[0m
[0m [90m 10 | [39m}[33m:[39m [33mParams[39m) {[0m

[31m[1m✖ 1 problem (1 error, 0 warnings)[22m[39m
[31m[1m[22m[39m

Without color: 无颜色:

> eslint . "--no-color"


/Users/xxxx/yyyy.js
  7:13  error  Parsing error: Unexpected token

   5 | }
   6 | 
>  7 | function f({,
     |             ^
   8 |   // $FlowFixMe
   9 |   a = 1,
  10 | }: Params) {

✖ 1 problem (1 error, 0 warnings)

我认为这是vscode中的ESLINT( dbaeumer.vscode-eslint )插件的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Atom和React Native的ESLint意外解析错误 - ESLint Unexpected Parsing error with Atom & React Native 反应导航 | [eslint] 解析错误:意外令牌 = | 反应原生 - React Navigation | [eslint] Parsing error: Unexpected token = | React-Native React Native/Typescript/Eslint 错误:类型“void”不可分配给类型“CompositeAnimation” - React Native/Typescript/Eslint error: Type 'void' is not assignable to type 'CompositeAnimation' WebStorm ESLint配置react-native-community错误 - WebStorm ESLint configuration react-native-community error 不清楚在 react native 中 async 和 await 的用法 - Unclear as to the usage of async and await in react native 在双花括号、ESLint/Prettier 警告上反应原生错误 - React Native error on double curly braces, ESLint/Prettier Warnings ESLint:(64:12)解析错误:意外的令牌,React Native中应为“}” - ESLint: (64:12) Parsing error: Unexpected token, expected “}” in React Native React-native-razorpay错误代码及其描述 - React-native-razorpay error codes and its description 具有Babel,Flow,React和React Native的ESLint配置 - ESLint configuration with Babel, Flow, React and React Native 用纱线陪伴并创建本机应用程序 - eslint with yarn and create-react-native-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM