组件上的传播运算符禁用eslint-config-airbnb上的react / prop-types规则

时间:2018-09-26 15:16:45

标签: reactjs react-proptypes eslint-config-airbnb

我面临的问题是,当我在组件中添加散布属性时,react / prop-types规则停止工作:

import React from 'react';
import PropTypes from 'prop-types';

import Button from './Button';

const LoginFacebook = ({
      label, ...props
    }) => (
      <Button
        {...props} // if I remove this line then eslint shows me the react/proptypes error
      >
        {label}
      </Button>
    );

.eslintrc:

{
  "extends": "airbnb",
  "parser": "babel-eslint",
  "rules": {
    "max-len": ["error", { "code": 80, "ignoreUrls": true }],
    "no-console": [2]
  },
  "env": {
    "browser": true
  }
}

.package.json

"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.1",

这就是我在登录容器中使用此组件的方式:

...    
render() {
       return (
        <Grid>
          <GridCell span="6" phone="4" tablet="8">
            <LoginFacebook
              onLoginSuccess={this.onLoginSuccess}
              onLoginFailure={this.onLoginFailure}
            />
          </GridCell>
        </Grid>
       )
    }

0 个答案:

没有答案