react-native - 如何使用 eslint 设置内联样式规则?

标签 react-native eslint eslintrc

我创建了一个 React Native 项目,版本是 0.62.2
我换eslintrc.js如下

module.exports = {
  parser:'babel-eslint',
  env: {
    browser: true,
    es6: true,
  },
  extends: '@react-native-community',
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
  },
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 2018,
    sourceType: 'module',
  },
  plugins: [
    'react',
  ],
  rules: {
    ... my other rules
    "react-native/no-inline-styles": 1,
    "prettier/prettier": ["error", {
      "no-inline-styles": false
    }],
  },
};

我希望我的风格代码是这样的 {{ flex: 1, marginTop: 5 }}不是 {{flex:1,marginTop:5}}
但我的警告显示信息:
(property) FlexStyle.marginTop?: React.ReactText
Inline style: { flex: 1, marginTop: 5 }eslint(react-native/no-inline-styles)
Replace `·flex:1,·marginTop:5·` with `flex:·1,·marginTop:·5`eslintprettier/prettier

enter image description here

我不知道如何设置内联样式空间以及如何解决更漂亮的问题。

最佳答案

您可以通过 ESLint 使用禁用规则功能

// eslint-disable-line react-native/no-inline-styles

更多信息请访问https://eslint.org/docs/user-guide/configuring.html#configuring-rules

关于react-native - 如何使用 eslint 设置内联样式规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61133779/

相关文章:

android - react 原生 : How to make fullscreen youtube embed video in webview with expo (without react-native link)

javascript - 如何允许用户更改应用程序中的背景图片?

javascript - React Native 通过 `props` 构建的导航容器传递 `createStackNavigator`

javascript - ESLint 不会破坏 Github Actions 的构建

javascript - 为什么开发人员偶尔会在 "SharedArrayBuffer" "Atomics"属性中添加 ".eslintrc.json"和 "globals"?

ios - react native 全局状态

javascript - 将 'node' 环境添加到我的 .eslintrc 出现意外行为

javascript - 强制 eslint 在某些文件上导入时使用默认导出模块的原始名称

javascript - 如果 div 为空,Eslint airbnb 会强制执行自关闭 div 标签。如何禁用此规则?

javascript - eslint-config-google 没有检测到全局安装的 eslint