当前位置: 代码迷 >> JavaScript >> ESLint 对象解构新行格式函数
  详细解决方案

ESLint 对象解构新行格式函数

热度:161   发布时间:2023-06-07 15:25:35.0

我希望能够像这样格式化我的代码:

const {
    header, 
    note, 
    otherStuff
} = labels;

const { thisDestructuredObject } = _.get(labels,`some.thing.here`,`some.default.value`);

Eslint 格式如下:

const {
    header, note, otherStuff
} = labels;

const { thisDestructuredObject } = _.get(labels,
    `some.thing.here`,
    `some.default.value`);

然而,我设定了两个规则:

"function-paren-newline": ["error", { "minItems": 4 }],
"object-curly-newline": [
    "error",
    {
        "ObjectExpression": { "multiline": true, "minProperties": 2 },
        "ObjectPattern": { "multiline": true, "minProperties": 2 },
        "ImportDeclaration": "never",
        "ExportDeclaration": { "multiline": true, "minProperties": 3 }
    }
]

我为React启用了预设,并为 ESLint 推荐了设置。 此外,还设置了ReactReact-hooks插件。

有没有人试过做这样的事情?

目前没有针对此的内置规则,但有一个。 包有几个规则来执行此操作,直到它被烘烤。

  相关解决方案