react-native - .eslintrc.js 不适用于规则 "off"

标签 react-native eslint eslintrc

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/prop-types”,
  • 设置“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" } 

在 Workspace Settings 中就可以了

最佳答案

尝试:

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,  
    }
};

关于react-native - .eslintrc.js 不适用于规则 "off",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51719879/

相关文章:

import - 如何在 Svelte 中使用 Vite 和 ESlint 解析绝对路径?

angular - eslint parseroptions.project 是做什么的?

reactjs - react native : optimizing flatlist render item with useCallback

javascript - 功能组件的辅助功能放在哪里?什么对性能最好?

react-native - 如何在 React Native 中为 TextInput 设置行高样式?

javascript - 格式化第三方导入和其他导入之间的空行

android - Haste 模块映射中不存在模块 `DatePickerIOS`

reactjs - Redux Toolkit linting 悖论

javascript - TSLint。最大语句规则 - 可用吗?

javascript - 找不到配置中指定的以下规则的实现