简体   繁体   English

Eslint:如何强制多行对象文字和数组具有相同的缩进?

[英]Eslint: how to force multiline object literals and arrays to have the same indent?

Eg these should be allowed: 例如,应允许这些:

{ a: 1, b: 2, c: 3 };

{
  a: 1,
  b: 2,
  c: 3,
};

{
  a: 1, b: 2, c: 3,
};

[
  1,
  2,
  3,
];

These should not be allowed: 这些不应该被允许:

{ a: 1,
  b: 2,
  c: 3,
};

{
  a: 1, b: 2,
  c: 3,
};

I added "object-property-newline": [2, { allowAllPropertiesOnSameLine: true }], , but it's still allowing the 2 examples. 我添加了"object-property-newline": [2, { allowAllPropertiesOnSameLine: true }], ,,但仍然允许这两个示例。 I also tried several key-spacing options but it doesn't do what I want. 我也尝试了几种key-spacing选项,但它并不能满足我的要求。 How do I disallow the last 2 examples? 我如何不允许最后两个示例?

The first example is covered by another rule object-curly-newline : 第一个示例由另一个规则object-curly-newline覆盖:

/* eslint object-curly-newline: 2 */

let foo = { a: 1,
  b: 2,
  c: 3,
};

// Unexpected line break before this closing brace. (object-curly-newline)

The second example works on my computer. 第二个示例在我的计算机上工作。

You can check it in this demo . 您可以在此演示中进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM