V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
iugo
V2EX  ›  JavaScript

求助 eslintrc 配置问题: 使用 React Native 自带的 .eslintrc 遇到 import 就报错

  •  
  •   iugo · 2016-03-07 11:13:44 +08:00 · 6281 次点击
    这是一个创建于 2977 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用的 ESLint 配置文件为 React Native 官方仓库中的: https://github.com/facebook/react-native/blob/master/.eslintrc

    错误提示: AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context

    有个类似错误, 不过人家说是自己配置的问题: https://github.com/eslint/eslint/issues/4344 我按照他的做法修改配置文件在 "ecmaFeatures" 中增加了 "modules": true 还是报错.

    请问该如何修改配置文件解决这个问题?


    还有一个问题, 就是官方是在每个文件中都增加严格模式, 但是 ESLint 提示我这样在模块中添加标题是没必要的...

    3 条回复    2016-03-08 10:39:17 +08:00
    iugo
        1
    iugo  
    OP
       2016-03-07 14:44:16 +08:00
    magicdawn
        2
    magicdawn  
       2016-03-07 16:26:26 +08:00   ❤️ 1
    {
    "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
    }
    }

    如果你是在用 ESLint v2.x 的话
    iugo
        3
    iugo  
    OP
       2016-03-08 10:39:17 +08:00
    感谢 @magicdawn , 问题已被解决.

    是该看看 http://eslint.org/docs/user-guide/migrating-to-2.0.0 了.

    - ecmaFeatures 应该被包裹在顶级的 parserOptions 内.
    - ecmaFeatures.modules 被 sourceType 替代. 用法也变了, 不再是布尔值而是字符串.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2339 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 07:12 · PVG 15:12 · LAX 00:12 · JFK 03:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.