我是新手+打字稿+ eslint。 大多数集成工作正常,但在分解对象中的多行效果不佳。
更漂亮的1.19.1 Playground link
输入:
const {
ciq,
drawingMenuX,
drawingMenuY,
selectedDrawing,
} = store.chartStore;
输出:
const { ciq, drawingMenuX, drawingMenuY, selectedDrawing } = store.chartStore;
预期的行为:
const {
ciq,
drawingMenuX,
drawingMenuY,
selectedDrawing,
} = store.chartStore;
我想在解构对象中保留多行格式,如基本原理(https://prettier.io/docs/en/rationale.html#multi-line-objects)
在普通对象中效果很好,但在分解对象中效果不好
如何解决此问题? 我只需要修正每一行吗?
package.json
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"eslint": "^6.7.2",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^1.7.0",
"prettier": "^1.19.1",
.eslintrc.js
module.exports = {
env: {
browser: true,
es6: true,
},
extends: ['plugin:react/recommended', 'plugin:prettier/recommended', 'airbnb'],
plugins: ['react', '@typescript-eslint'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
rules: {
'react/jsx-filename-extension': [
1,
{
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'no-confusing-arrow': [0],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-unused-vars': [2, { args: 'none' }],
},
},
],
};
答案 0 :(得分:3)
我更喜欢Prettier的处理方式。
在您的.eslintrc.js
中将其添加到您的rules
。
'object-curly-newline': 'off',