object-curly-spacing
在大括号内强制保持一致的间距
一些该规则报告的问题可以通过 --fix 命令行选项 自动修复
虽然格式偏好是非常个人化的,但在以下情况下,许多样式指南要求或不允许大括号之间有空格:
// simple object literals
var obj = { foo: "bar" };
// nested object literals
var obj = { foo: { zoo: "bar" } };
// destructuring assignment (EcmaScript 6)
var { x, y } = y;
// import/export declarations (EcmaScript 6)
import { foo } from "bar";
export { foo };
规则详情
此规则强制在对象字面量、解构赋值和导入/导出说明符的大括号内保持一致的间距。
选项
该规则有两个选项,一个字符串选项和一个对象选项。
/NYB2S5vRacr5bCxCyQNqseEm/1VcRhXmx+t3kLxT/4=
- Yw6ycervSQCLTEfLF3p1WrRfAyzgkTyvzya/Raa1L3NYlN7MG6u1RLCeOuuIgGQU0IiPqAv+o1B7k9iibZFwA9QuzaZAQOSMITSYUiIMwdvvbG3ybP57o7sbxvHnyXzaQKTxG5V3Aj3XgNk1dy5CP+knujBcnNBjIeoX2OrqYjZPsfK+EjUmrb3XA27zkFtccESnfIAKIFFEmlEcOVdjqlOSIQiqQxJF5FQFfxEHxLA=
1P3EcEC0VbBsWI5hyRJr9w==
- d81pmxsoBfe6RHZozbdKwRhss7YqxMSlbGKSRAo06b4+MUnGS8A5h8mZ7WgH6FWHdInbmPwSi3mQpNHD0gIepoXv7RFXfn5MuGVNMaGD7GK2Lgms6OSr9GeQ0CT9B+iwjdJGn2L+EYgFzhwZ+T++D49Cm3r+vErzQLlHS2klqPzg6yqGio2GQCGASAntAggWX/t1qhQ8+cCEGfv1xXDQHbu3fXL+kkUbvEl0Ijd6+dh/5hB8vFaSY3ycnMeTFnYRb2u2tg0gg775KqIC1/ggCO4g+fG0sG+k4r4PIJlJpxLpPZxGuY9GRLlAVjZjse5HeQ2z5Oo5CI12I4r+cDw7yrWq6j87HF6b/LNwFk2sKDkjD4SFp/+w3EvFowtgAM3+oRa7Xz+h1ELYCsw2sAKbWXy2h4JA8LuVL2KiELbN1HxP1IN/cobCokSQufZ/ofMZ/kyf0+Eo7/OE2Z6zEkkxpE5XyTRD8hfe3dB1ocnn45RZT9odD4OGwcZmW9b5AKkuP5va5qhFJNW+H3Jn1nxS8ZSlbYfGryrAtis8iCNAp7Pyoe83qdsidlX1gA1Mn/wr4d1tcNCEuSOxP5gB4/ZFMbftb2uCutoxTVSgVb4cCVIvidpvHwahIpEQpkuRIItMwUsIXVbkYm3KXBwemGs7cxXUaA1kSAP6XqAAsRl2bLCWaD/O4av8yO7UoQFSS1RM2BrwZnxjARhU0UiZXPX7Ki4OB2n1FmM7HkXa8jfM3KxlDM61O7cV4+1zYR8nCgRR+WvjW/2JqUdpuy2KNJ8jo7hwFiZvISOI8sCjycgoaAEX5oR9qcUxtdrtUOd/TOYsTH53PX5zpBrdnLIvJ57WzPCiKLdgUpKAkOu+5yqpzEtPE4AzNSgM5WCIdp+CErc4mxOgIyl5aDSSYBNB0K0+aOVFr5ZG/GSIxXrkntW2185S6v6Vv0wMbu8rfaTiDk+kxGv3tFp6wL0K1VLaZ4kszA==
never
UlaHmiNRrn4r9+6kXRmVxu+/JtTvB66OuDMzKvUvCMsRKC8F48fXJd9pxC9xiK5/kpeKZXi7fWE2Hk+d5Puy5t8m7lDomiYiNPOhS1ItgsY=
/*eslint object-curly-spacing: ["error", "never"]*/
var obj = { 'foo': 'bar' };
var obj = {'foo': 'bar' };
var obj = { baz: {'foo': 'qux'}, bar};
var obj = {baz: { 'foo': 'qux'}, bar};
var {x } = y;
import { foo } from 'bar';
UlaHmiNRrn4r9+6kXRmVxu+/JtTvB66OuDMzKvUvCMsRKC8F48fXJd9pxC9xiK5/8l4Hbm5ggoZBZlSXDL9yqhvyzKdjP512Iv73zIRJiQw=
/*eslint object-curly-spacing: ["error", "never"]*/
var obj = {'foo': 'bar'};
var obj = {'foo': {'bar': 'baz'}, 'qux': 'quxx'};
var obj = {
'foo': 'bar'
};
var obj = {'foo': 'bar'
};
var obj = {
'foo':'bar'};
var obj = {};
var {x} = y;
import {foo} from 'bar';
always
nQP82WYZJTVvhOZX4UTE6IEwvurs0YzEJUu6Q6spVF9wSQudtSEk5nyoRrluei4pSwOXy5NzI8XsXLT6BMi7pW0XURP2X1D3RMJA8uwTNpg=
/*eslint object-curly-spacing: ["error", "always"]*/
var obj = {'foo': 'bar'};
var obj = {'foo': 'bar' };
var obj = { baz: {'foo': 'qux'}, bar};
var obj = {baz: { 'foo': 'qux' }, bar};
var obj = {'foo': 'bar'
};
var obj = {
'foo':'bar'};
var {x} = y;
import {foo } from 'bar';
nQP82WYZJTVvhOZX4UTE6IEwvurs0YzEJUu6Q6spVF+JUYhuvxa/DTAV79mBml/z0F99COEjj6IIv58iuvboQQtBxbwXAtXq8ohdJWVhNJI=
/*eslint object-curly-spacing: ["error", "always"]*/
var obj = {};
var obj = { 'foo': 'bar' };
var obj = { 'foo': { 'bar': 'baz' }, 'qux': 'quxx' };
var obj = {
'foo': 'bar'
};
var { x } = y;
import { foo } from 'bar';
arraysInObjects
nQP82WYZJTVvhOZX4UTE6OuCHGnW7mjyh6+e0PAySFsn3MMLNAlxUo+FhwtfM3mying7cxV6WEXLS0u/PhhRE9JWu5LhfHdrH8q9zHkeXd7ynvg30aufTy1g2hIk2RCUYRpflKSYRMmXC+Ta7OeyJw==
/*eslint object-curly-spacing: ["error", "never", { "arraysInObjects": true }]*/
var obj = {"foo": [ 1, 2 ] };
var obj = {"foo": [ "baz", "bar" ] };
nQP82WYZJTVvhOZX4UTE6LkvOQDhY6Lx0RejRnMFIcEVeU1JKH1iBaUcHq5OzwdE6DfgPz9qumpP2QHSDsIpDhQYJ8hHErt57ORz6II0YSGMT2dcBupN0mokard+8brPqSmmB17EscgiRHdXQq1W6A==
/*eslint object-curly-spacing: ["error", "always", { "arraysInObjects": false }]*/
var obj = { "foo": [ 1, 2 ]};
var obj = { "foo": [ "baz", "bar" ]};
objectsInObjects
nQP82WYZJTVvhOZX4UTE6OuCHGnW7mjyh6+e0PAySFvTjC5LjRCdUx7KjAeh9bcXzbMBYIgNCMsBubaLALyfhVe4ojBUQemNgmBh7n8lEisjarCxYQCkzgOeAE+cIcTvX0IjkFl4Lv2RHaH3OC9L/A==
/*eslint object-curly-spacing: ["error", "never", { "objectsInObjects": true }]*/
var obj = {"foo": {"baz": 1, "bar": 2} };
nQP82WYZJTVvhOZX4UTE6LkvOQDhY6Lx0RejRnMFIcGIhkZVDKgye2Do4Qh/b+rUrVk/aaxOmo22enCzbxykSZcss1cSpo2Bs4IFMFbmzPjn9u7vMsSxjDGuUmoB6FJ3Fq8hF/noJHaWNPm7cQm5PQ==
/*eslint object-curly-spacing: ["error", "always", { "objectsInObjects": false }]*/
var obj = { "foo": { "baz": 1, "bar": 2 }};
何时不使用
0/TzZaD6kBZQXK1shdMp75iBH4hrtW6i/vk0d8H593/lwl0/YXnETGbhrSLCPwdCQyz2vmm2IK3JpM11cgDRXk+1LfJ2ITGBTekr1aS1J9KT59+ABXKmw1eDV7UZ6kxp