'How to set inline style rule with eslint?
I create a React Native project the version is 0.62.2
I change eslintrc.js
as below
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
}],
},
};
I hope my style code like this {{ flex: 1, marginTop: 5 }}
not {{flex:1,marginTop:5}}
But my warrning shows info:
(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
I have no idea how to set inline styles space and how to fix the prettier problem.
Solution 1:[1]
It looks like your configuration is missing prettier in the plugins' array. Make sure to correctly use eslint to run prettier by reading prettier's documentation.
Prettier has a rule for object literals spacing called bracket spacing, but note that it is set to true by default.
Solution 2:[2]
You can use disable rule functionality by ESLint
// eslint-disable-line react-native/no-inline-styles
For more info visit https://eslint.org/docs/user-guide/configuring.html#configuring-rules
Solution 3:[3]
the value should be 0, to set it to false. So your rules array should look like this:
rules: {
... my other rules
"react-native/no-inline-styles": 0,
"prettier/prettier": ["error", {
"no-inline-styles": false
}],
}
Solution 4:[4]
make change to file: .eslintrc.js
module.exports = {
root: true,
extends: '@react-native-community',
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'react-native/no-inline-styles': 0,
'prettier/prettier': 0,
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-shadow': ['error'],
'no-shadow': 'off',
'no-undef': 'off',
},
},
],
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sal |
Solution 2 | Rajan |
Solution 3 | Aman Singh |
Solution 4 | jancarlos ramirez |