gpt4 book ai didi

reactjs - 如何在文件中禁用 ESLint React/prop-types 规则?

转载 作者:行者123 更新时间:2023-12-03 12:54:42 24 4
gpt4 key购买 nike

我正在使用 ReactESLint 以及 eslint-plugin-react

我想在一个文件中禁用 prop-types 规则。

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 文件中添加一条规则来禁用 prop-type 验证:

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

有关更多规则,您可以查看 this link这解决了我的问题,如果给您带来不便,您还可以阅读 eslint-plugin-react有关如何使用各种选项禁用或启用它的 github 文档。

关于reactjs - 如何在文件中禁用 ESLint React/prop-types 规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30948970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com