programing

파일에서 ESLint react/prop-type 규칙을 비활성화하려면 어떻게 해야 합니까?

iphone6s 2023. 3. 28. 21:20
반응형

파일에서 ESLint react/prop-type 규칙을 비활성화하려면 어떻게 해야 합니까?

사용하고 있다React그리고.ESLint와 함께eslint-plugin-react.

하고싶어disableprop-types규칙을 1개의 파일로 만듭니다.

var React = require('react'); 
var Model = require('./ComponentModel');

var Component = React.createClass({
/* eslint-disable react/prop-types */
    propTypes: Model.propTypes,
/* eslint-enable react/prop-types */
    render: function () {
        return (
            <div className="component">
                {this.props.title}
            </div>
        );
    }
});

하나의 파일만 있는 경우 prop-type 검증을 비활성화하려면 다음을 사용할 수 있습니다.

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

여러 개의 파일이 있는 경우 에 추가할 수 있습니다..eslintrc루트 디렉토리에 있는 파일: 프로펠러 유형 검증을 사용하지 않도록 설정하는 규칙:

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

자세한 규칙에 대해서는, 이 링크를 체크해 주세요.또, 불편함을 위해서, eslint-disable-disable의 github 메뉴얼을 참조해 주세요.

이 파일을 파일 위에 올려놓기만 하면 됩니다.

/* eslint-disable react/prop-types */

나는 해야만 했다:

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

한테는 안 통했어

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

.eslintrc 파일(이전 버전 v6.0 이하)에서 글로벌하게 비활성화하려면:

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

.eslintrc 파일(v6.0보다 새로운 버전)에서 글로벌하게 비활성화하려면:

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

eslint 무시 댓글로 컴포넌트 전체를 포장해야 했습니다.

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 */

메이저 컴포넌트와 같은 파일에 작은 컴포넌트가 있는 경우가 있습니다.PropTypes는 과잉 살상인 것 같습니다.그러면 저는 이런 걸 많이 해요.

// 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>);

저는 이렇게 해야 했어요..eslintrcconfig 파일을 사용하여 프로펠러 유형 검증 오류를 해제합니다.

"rules": {
  "react/prop-types": "off"
}

경고로 변경할 수 있습니다. 안에 넣으십시오.eslint규칙:

'react/prop-types': ['warn'],

언급URL : https://stackoverflow.com/questions/30948970/how-to-disable-eslint-react-prop-types-rule-in-a-file

반응형