How to disable ESLint react/prop-types rule in a file?

后端 未结 5 814
无人及你
无人及你 2020-12-13 11:37

I\'m using React and ESLint with eslint-plugin-react.

I want to disable the prop-types rule in one f

相关标签:
5条回答
  • 2020-12-13 12:12

    Sometimes I have small components in the same file as the major one. There propTypes seems overkill. Then I do something like this

    // eslint-disable-next-line react/prop-types
    const RightArrow = ({ onPress, to }) => (<TouchableOpacity onPress={() => onPress(to)} style={styles.rightArrow}><Chevrons.chevronRight size={25} color="grey" /></TouchableOpacity>);
    
    0 讨论(0)
  • 2020-12-13 12:25

    I had to wrap the whole component with the eslint ignore comments.

    var React = require('react'); 
    var Model = require('./ComponentModel');
    
    /* eslint-disable react/prop-types */
    var Component = React.createClass({
    
        propTypes: Model.propTypes,
    
        render: function () {
            return (
                <div className="component">
                    {this.props.title}
                </div>
            );
        }
    });
    /* eslint-enable react/prop-types */
    
    0 讨论(0)
  • 2020-12-13 12:28

    if you have only one file you want to disable prop-type validation you can use:

    /* eslint react/prop-types: 0 */
    

    in cases where you have multiple files you can add to your .eslintrc file in your root directory a rule to disable prop-type validation:

    {
     "plugins": [
         "react"
      ],
      "rules": {
        "react/prop-types": 0
      }
    }
    

    for further rules you can checkout this link that solved my issue and for inconvenience you can also read up from eslint-plugin-react's github documentation about how to disable or enable it with various options.

    0 讨论(0)
  • 2020-12-13 12:32

    Just put this on top of your file:

    /* eslint react/prop-types: 0 */
    
    0 讨论(0)
  • 2020-12-13 12:35

    I had to do:

    /* eslint react/forbid-prop-types: 0 */
    

    this did not work for me:

    /* eslint react/prop-types: 0 */
    

    To disable globally in your .eslintrc file (old version v6.0 or below):

    {
        "rules": {
            "react/forbid-prop-types": 0
        }
    }
    

    To disable globally in your .eslintrc file (new version above v6.0):

    {
        "rules": {
            "react/prop-types": 0
        }
    }
    
    0 讨论(0)
提交回复
热议问题