1

native 并且在配置 eslint 时遇到问题。这是我的 .eslintrc.js。

module.exports = {
    "extends": "airbnb",
    "parser": "babel-eslint",
    "env": {
        "jest": true,
    },
    "plugins": [
        "react",
        "node"
    ],
    "rules": {
        "no-use-before-define": "off",
        "react/jsx-filename-extension": "off",
        "node/no-unsupported-features/es-syntax": ["error", {
            "version": ">=6.0.0",
            "ignores": ["modules", "destructuring"]
        }],
        "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
        "react/prop-types": "off",  
    }
};

在 App.js 中,

const { navigation } = this.props;

我得到了 eslint 错误。

[eslint] Destructuring are not supported yet on Node 4.0.0. (node/no-unsupported-features) 
[eslint] 'navigation' is missing in props validation (react/prop-types)

而且在 App.js 中,

<View style={styles.container}>
    <UpArrow title="cancel" />
    <SecondsSpinner seconds={this.state.imageTime} changeImageTime={this.changeImageTime} />
    <DownArrow title="save" />
</View>

我有错误

[eslint] JSX not allowed in files with extension '.js' (react/jsx-filename-extension)

所以我

  • 关闭“反应/道具类型”,
  • 设置 "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
  • 设置“忽略”:[“解构”]。

但它们不起作用。我不知道为什么以及如何解决这个问题。还有其他文件可以配置 eslint 吗?提前致谢。

EDIT1) "ignores": ["modules"] 有效。太奇怪了。

EDIT2)我正在使用 vscode 并且在编辑器上出现错误,所以我认为是因为 .eslintrc 文件。但现在我认为这是vscode的问题。我设置

"eslint.options": { "configFile": "/Users/com/vscode/AwesomeProject/.eslintrc.js" } 

在工作区设置中然后它可以工作

4

1 回答 1

0

尝试:

module.exports = {
    "extends": "airbnb",
    "parser": "babel-eslint",
    "env": {
        "jest": true,
    },
    "plugins": [
        "react",
        "node"
    ],
    "rules": {
        "no-use-before-define": 0,
        "react/jsx-filename-extension": 0,
        "node/no-unsupported-features/es-syntax": ["error", {
            "version": ">=6.0.0",
            "ignores": ["modules", "destructuring"]
        }],
        "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
        "react/prop-types": 0,  
    }
};
于 2018-08-07T08:28:29.273 回答