代码之家  ›  专栏  ›  技术社区  ›  N. Labrahmi

eslint atom和react native的意外分析错误

  •  1
  • N. Labrahmi  · 技术社区  · 6 年前

    在玩一个简单的react原生设置时,我突然发现了一些(也许不是这样)奇怪的eslint东西。

    这是我的javascript文件:

    import React from 'react';
    import { Text, View } from 'react-native';
    
    const Header = () => {
      const { textStyle } = styles;
      return (
        <View>
          <Text style={textStyle}>App Header!</Text>
        <View/>
      );
    };
    const styles = {
      textStyle: {
        fontSize: 20
      }
    };
    export default Header;
    

    出现此问题的原因是 textStyle: { 线:

    Parsing error: Unexpected token, expected "}" (Fatal)
    

    我已经安装了最新的 linter (V2.2.0)和 linter-eslint (V8.4.1)包 Atom .

    我正在使用来自 npm 包裹 rally-coding 我在项目中安装了DEV依赖项,这是我的 .eslintrc 文件:

    {
      "extends": "rallycoding",
      "parser": "babel-eslint",
      "ecmaFeatures": {
        "jsx": true
      }
    }
    

    你知道这是从哪里来的吗?到目前为止,(许多)github问题线程中建议的解决方法都没有帮助。

    1 回复  |  直到 6 年前
        1
  •  2
  •   bennygenel    6 年前

    语法错误是由未关闭 View 标签。

    <View/> 应该是 </View>

    边注: 对于这些错误,linter并不总是很准确。一个小建议是,如果你有一个 expected "}" 错误并已检查所有 }