【问题标题】:ESLint validate JSX fileESLint 验证 JSX 文件
【发布时间】:2017-12-24 08:07:49
【问题描述】:

我使用 ESLint 检查我的反应代码。但是,它无法识别反应组件标签中的变量。 ESLint 向我抛出错误“no-unused-vars”(变量“Comp”)。但是我在我的代码中使用了这个变量

export function TestHoc() {
    return function (Comp) {
        class testHocComponent extends PureComponent{
            render(){
                const props={
                    'x':1,
                    'y':2,
                    'z':3
                };

                return (
                    <Comp {...props}/>
                );
            }
        }
        return testHocComponent;
    };
}

这是我的 ESLint 的配置

"env": {
    "browser": true,
    "commonjs": true,
    "es6": true,
    "node": true
},
"parserOptions": {
    "ecmaVersion": 6,
    "ecmaFeatures": {
        "experimentalObjectRestSpread": true,
        "jsx": true,
        "arrowFunctions": true,
        "classes": true,
        "modules": true,
        "defaultParams": true
    },
    "sourceType": "module"
},
"parser": "babel-eslint",
"plugins": [
    "react"
],

【问题讨论】:

  • 首先,代替图片,尝试粘贴代码。
  • 对不起,这是我的错
  • "rules": { "react/jsx-uses-vars": 2 } 可能对你有帮助
  • 谢谢,我是 ESLint 的新手,我会尝试这种方式
  • 在此处添加完整的 lint 文件,以便可以轻松提供帮助,如果添加规则后仍有问题,请告诉我..

标签: reactjs jsx eslint


【解决方案1】:

添加{rules": { "react/jsx-uses-vars": 2 } 可以帮助您。您可以抽出时间阅读this

【讨论】:

    猜你喜欢
    • 2019-08-04
    • 2018-07-04
    • 2016-08-07
    • 2015-09-21
    • 2019-08-22
    • 2018-08-22
    • 2018-04-16
    • 2018-03-28
    相关资源
    最近更新 更多