【问题标题】:Eslint react/no-typos rule throw an error when declare a property as style将属性声明为样式时,Eslint react/no-typos 规则会引发错误
【发布时间】:2018-11-28 23:14:57
【问题描述】:

我在 react native 应用程序中遇到了 eslint 的问题。我正在为我的组件声明样式属性。它看起来像:

Component.propTypes = {
   styles: ViewPropTypes.style,
   textStyle: Text.propTypes.style,
}
Component.defaultProps = {
   styles: null,
   textStyle: null,
}

我收到以下 eslint 错误:

295:25  error  Typo in declared prop type: style         react/no-typos
296:20  error  Typo in declared prop type: propTypes     react/no-typos
296:30  error  Typo in prop type chain qualifier: style  react/no-typos

我注意到我使用 es6 语法来获取它们。当我使用 es7 时,一切都很好。 你能告诉我我做错了什么吗?

我的库版本是:

"prop-types": "15.6.1",
"react": "16.0.0",
"react-native": "0.50.0",

"eslint": "^4.11.0",
"eslint-import-resolver-babel-module": "^4.0.0",
"eslint-plugin-flowtype": "^2.41.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "7.9.1",
"eslint-plugin-react-native": "^3.1.0",

感谢和抱歉我的英语水平。

【问题讨论】:

  • 你可以尝试使用 eslint-plugin-react@7.10.0 吗?我认为他们修复了一些与no-typos 规则相关的错误。
  • 谢谢,它有效。您可以写下您的评论作为答案,我会接受。

标签: react-native ecmascript-6 eslint react-proptypes


【解决方案1】:

你可以尝试使用 eslint-plugin-react@7.10.0 吗?我认为他们修复了一些与无错别字规则相关的错误。

【讨论】:

    【解决方案2】:

    使用camelCase 表示法,例如.propTypes不是 .PropTypes

    【讨论】:

      猜你喜欢
      • 2020-10-01
      • 2017-12-14
      • 2021-02-23
      • 2014-02-01
      • 2021-03-13
      • 1970-01-01
      • 2022-01-13
      • 2017-02-22
      • 2020-08-13
      相关资源
      最近更新 更多