我创建了一个 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
我不知道如何设置内联样式空间以及如何解决更漂亮的问题。
最佳答案
您可以通过 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/