object-curly-newline

在打开大括号之后和关闭大括号之前强制执行一致的换行符

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

许多样式指南要求或不允许在对象大括号和其他标记内换行。

规则详情

此规则要求或不允许在 { 与其后标记之间以及 } 与其前一个对象字面量或解构赋值标记之间换行。

选项

此规则有一个字符串选项:

    OkFUL1XOL6DN7ZRSE5GhTIljRvfVK2x1XBtsSTIGl3OxbOPiFfF81lrXaNsdMP1Hmw2emcOe5/A8OJBgABulrkKglWz1bBQO4zu4dKhLFmB/eRyZf1sMJmYeZ8IY5rRKGadXYV27TEuSb5EaapTXS6jl4S9vMO6GfKy/UcviBKSAEl6i10OoX6vbZDkwAuqUxTgMHoX2GOexqV6Q2VXTRJrTx3+rOerPJx2mXy/Z4ARxk93ZiplvqsmbK6HqqmFT

KVqaSq8nEh78Qlztgd7r/Xb+c8w/n2URQN1l9QRIVrE=

    YN2/kihdUfsG7TJy3cSVfuQpb1Wcw9TmUXYBxYg7mWPAx/8vJ+V1co06HAnaLybU7AQ732am19EmhPeeDPx7Kh9pnyHqww0O/wUTGCf56J0qqV6XxcWLSMs/W6Rjve5rN0yIYZ0BAsqSo64DrHx2Hhhwt8ctw+ERtqP2EHnfwMSh1P1sMZg6LcB0lnx7kz6ZZtOkgMjxVn5MXdbDt8AlN4XSBp1Oe0H7wbGyjPauj4L2tCRRbFaW38mdV6VgSOfIQ3Ae8mSy/XMVmhZ29oI6Kc3ONrL+pLV8X6La6obi0KnQop8TNbSfNkh3sbrHtPvU2as18jbb5GfW/FmHSc7jpDmNkGAsgPbdmlmN3q2BXBaILkAAUjPg589PkWoMEYBR25cLhus9VKi5SZvlaFrVZVvFJbR1uXDeNDQqaV71I6Er5jm7NMt/51xrKL9dSl9JzIEp7oXWAT+JSnwlvwtvedz5a85JC34TY65i3hvO1L3SaPM7hP3Q8T9ZNejDO2Z4aIxmvnlAu1FeUi7IldA41OIMZdDvibBHdksFxLZnjdyxAifKHr5dYYUxyIIVwUu56k8/8dsNGp55UqYbzP4eujK0l2HAFrz6jgLwoyksfocpg/kwxuNT9a3xSXAdE0F0O5aeqfct1RW+L2hpOQDxNJKweC4+VIggFmOf/kdSDekBCfwgx8x5L01OEV/Jlt4ejRDCFjSmPA4Z/41kux2C3r/Z4Sb7li0p5Jw4Cfd7HjlJWg8DhRpjJaghMPI6PcQI4+GMMvFTiNlVCU9NUzGiKwHTiruSQLsazOuxlMgE5JmoJFNFjRtcnXeu47WyzxNjP1mYFm232F0BR+Q8kdeayklLGB3xilAvThpm87lIR5H1/R+MLbz3ZAwlJ2TABgx4vdKjV6sFs9J7E1+7K8L6A8ebBYVcZM+Dwp2usg50A8VxNkRPiw7l9ryx8ht/hSTg

JKiigvmASV5CTs4Il3OLIlzohXhviuVOAKVL10tho1ysbnEW2f2V/FHCe0jzNlsbunz95tNWzPQF6WexWa5FeXaHisLmMAJdlScNzXjamrzodNyUQTGW7VnfL7Q9bs2K

{
    "object-curly-newline": ["error", {
        "ObjectExpression": "always",
        "ObjectPattern": { "multiline": true },
        "ImportDeclaration": "never",
        "ExportDeclaration": { "multiline": true, "minProperties": 3 }
    }]
}
    /MhiwQukWb5UtzAEu4kwNcnG0ZsDBS3h+bmIQmY+ZFuUb//EVhKA/NLVtlAkWZtTPVv+gFq9f9nCzj2n2u38OSrCfmwwVSh1tFyjVbLUfbn5dRctvU7GEo+Ev/NjkxsL/cBMQYXW6NOObIQMGaVMN1iIx19I12Yy7eCJvsnEA6VPkzIhaRd67tawvO6lkjut+2OeorIVCdHjLFIwMLyrWphjZGKhQHSCPMQbzgVKfB9LsNttafmUTzPdSTOW8StBh/708zIdW+G3mtUJ3IAQVvnwfIET/PUmbywTyu5I82KXlyZT2RBOuI8ZXu8lACfrhy2W1PI8g/9X1KkeA1/OZ3Nk3Uu9GbCWMyE+BWGVBAI=

always

nQP82WYZJTVvhOZX4UTE6IEwvurs0YzEJUu6Q6spVF9wSQudtSEk5nyoRrluei4pSwOXy5NzI8XsXLT6BMi7pW0XURP2X1D3RMJA8uwTNpg=

/*eslint object-curly-newline: ["error", "always"]*/
/*eslint-env es6*/

let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {foo() {
    dosomething();
}};

let {} = obj;
let {f} = obj;
let {g, h} = obj;
let {i,
    j} = obj;
let {k = function() {
    dosomething();
}} = obj;

nQP82WYZJTVvhOZX4UTE6IEwvurs0YzEJUu6Q6spVF+JUYhuvxa/DTAV79mBml/z0F99COEjj6IIv58iuvboQQtBxbwXAtXq8ohdJWVhNJI=

/*eslint object-curly-newline: ["error", "always"]*/
/*eslint-env es6*/

let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

let {
} = obj;
let {
    f
} = obj;
let {
    g, h
} = obj;
let {
    i,
    j
} = obj;
let {
    k = function() {
        dosomething();
    }
} = obj;

never

nQP82WYZJTVvhOZX4UTE6E+CdxiNzTu7o6T6mOD/GjrlRbdiMmNGpTGF7jf6PDecmimnZUW8Ueq/JPRBe9vmC96U7eEe4wGZUMRSihGX7SQ=

/*eslint object-curly-newline: ["error", "never"]*/
/*eslint-env es6*/

let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

let {
} = obj;
let {
    f
} = obj;
let {
    g, h
} = obj;
let {
    i,
    j
} = obj;
let {
    k = function() {
        dosomething();
    }
} = obj;

nQP82WYZJTVvhOZX4UTE6E+CdxiNzTu7o6T6mOD/Gjr3KLd0XlVm271nyfP4jKz4rZUK0QKEwlbOpUIvLmoD0d+TCkpccuhbKB2+aNyFH6E=

/*eslint object-curly-newline: ["error", "never"]*/
/*eslint-env es6*/

let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};

let {} = obj;
let {f} = obj;
let {g, h} = obj;
let {i,
    j} = obj;
let {k = function() {
    dosomething();
}} = obj;

multiline

nQP82WYZJTVvhOZX4UTE6DhxWMUcruFjqeXlZXiw62VXMYwVysRUcsL5yE0FWvj4SEJpdJw42cRQbwKFoWxtsc68iibwdipZvXqBy8Eh3LbDd2TMW6Tq0rYncgtBzNk+

/*eslint object-curly-newline: ["error", { "multiline": true }]*/
/*eslint-env es6*/

let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};

let {
} = obj;
let {
    f
} = obj;
let {
    g, h
} = obj;
let {i,
    j} = obj;
let {k = function() {
    dosomething();
}} = obj;

nQP82WYZJTVvhOZX4UTE6DhxWMUcruFjqeXlZXiw62VXMYwVysRUcsL5yE0FWvj4qjB0msRXS6xgN01I10mQPoCQNQACKg2a37ngbtOzCob8J5Qt0dgAOjr1+Ngy7l4l

/*eslint object-curly-newline: ["error", { "multiline": true }]*/
/*eslint-env es6*/

let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

let {} = obj;
let {f} = obj;
let {g, h} = obj;
let {
    i,
    j
} = obj;
let {
    k = function() {
        dosomething();
    }
} = obj;

minProperties

nQP82WYZJTVvhOZX4UTE6DZIMfc3B6t5noRD3mzMooBXJg3aO6ClT1DiEUC5bEm7JSK3OiV4bVlC+oaFu61E7BOYSnczRfInsxQqU32VFqO99dRTxyVa0r+4fwbnS4Kq

/*eslint object-curly-newline: ["error", { "minProperties": 2 }]*/
/*eslint-env es6*/

let a = {
};
let b = {
    foo: 1
};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {
    foo: function() {
        dosomething();
    }
};

let {
} = obj;
let {
    f
} = obj;
let {g, h} = obj;
let {i,
    j} = obj;
let {
    k = function() {
        dosomething();
    }
} = obj;

nQP82WYZJTVvhOZX4UTE6DZIMfc3B6t5noRD3mzMooBXJg3aO6ClT1DiEUC5bEm7M5ZJ1UJlLmi4/J2Cpmm5BIiWs4vUk/Ofvmh8b+sGs9Zee0dsKvwvz6SrbWgu20P7

/*eslint object-curly-newline: ["error", { "minProperties": 2 }]*/
/*eslint-env es6*/

let a = {};
let b = {foo: 1};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {foo: function() {
    dosomething();
}};

let {} = obj;
let {f} = obj;
let {
    g, h
} = obj;
let {
    i,
    j
} = obj;
let {k = function() {
    dosomething();
}} = obj;

consistent

UlaHmiNRrn4r9+6kXRmVxvidGsgd2wpYflsGj+5soSBLNKw8gJojICHRiS4BChTOM6cFpIAcPulrEiangDWerkFUHTqKAfMtF8+fPzHmm0qs8qf95FFTgUUsfSSxLy9D

/*eslint object-curly-newline: ["error", { "consistent": true }]*/
/*eslint-env es6*/

let a = {foo: 1
};
let b = {
    foo: 1};
let c = {foo: 1, bar: 2
};
let d = {
    foo: 1, bar: 2};
let e = {foo: function() {
    dosomething();
    }
};
let f = {
    foo: function() {
    dosomething();}};

let {g
} = obj;
let {
    h} = obj;
let {i, j
} = obj;
let {k, l
} = obj;
let {
    m, n} = obj;
let {
    o, p} = obj;
let {q = function() {
    dosomething();
    }
} = obj;
let {
    r = function() {
        dosomething();
    }} = obj;

UlaHmiNRrn4r9+6kXRmVxvidGsgd2wpYflsGj+5soSBLNKw8gJojICHRiS4BChTOM6cFpIAcPulrEiangDWerjexqzIa3QMMqwbSWZNMJVw8qveT3vMo+rAxJll+E4+Z

/*eslint object-curly-newline: ["error", { "consistent": true }]*/
/*eslint-env es6*/

let empty1 = {};
let empty2 = {
};
let a = {foo: 1};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {foo: function() {dosomething();}};
let f = {
    foo: function() {
        dosomething();
    }
};

let {} = obj;
let {
} = obj;
let {g} = obj;
let {
    h
} = obj;
let {i, j} = obj;
let {
    k, l
} = obj;
let {m,
    n} = obj;
let {
    o,
    p
} = obj;
let {q = function() {dosomething();}} = obj;
let {
    r = function() {
        dosomething();
    }
} = obj;

ObjectExpression 和 ObjectPattern

nQP82WYZJTVvhOZX4UTE6KDx08Lku1+esTav/Kz0qTm+UB1wfSkzFQjr54ygkND+kdpDS1IIM1ECUf+oHK6DEboxm1Qx9tHnn1chrsRocPK3vqvJ6kTsvvuXKG60KeisSh4nZafdeFMdrtGlcLSsWFo6TgdP+dbEDz31VFZ26kM=

/*eslint object-curly-newline: ["error", { "ObjectExpression": "always", "ObjectPattern": "never" }]*/
/*eslint-env es6*/

let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};

let {
} = obj;
let {
    f
} = obj;
let {
    g, h
} = obj;
let {
    i,
    j
} = obj;
let {
    k = function() {
        dosomething();
    }
} = obj;

nQP82WYZJTVvhOZX4UTE6KDx08Lku1+esTav/Kz0qTm+UB1wfSkzFQjr54ygkND+kdpDS1IIM1ECUf+oHK6DEboxm1Qx9tHnn1chrsRocPK3vqvJ6kTsvvuXKG60KeisWrd5pJeBh+fAjrKwvxPO8TdXyhNZyX8pCl1UWlh2MSY=

/*eslint object-curly-newline: ["error", { "ObjectExpression": "always", "ObjectPattern": "never" }]*/
/*eslint-env es6*/

let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

let {} = obj;
let {f} = obj;
let {g, h} = obj;
let {i,
    j} = obj;
let {k = function() {
    dosomething();
}} = obj;

ImportDeclaration 和 ExportDeclaration

nQP82WYZJTVvhOZX4UTE6HttshIyZ+SbuY90nKwLX8KX9dHwFPFTTqTVAdnM4Bzfeuj9DWvO7L9K/GtnPAqPG+1c1GhLZDmPKAoVVnqPe1akM6XQUxh+rbj5PqjjDCBJJBaApbQmtTCYO+2DUWBlU26M7kbY+CgudrPM5hwE8g8=

/*eslint object-curly-newline: ["error", { "ImportDeclaration": "always", "ExportDeclaration": "never" }]*/
/*eslint-env es6*/

import {foo, bar} from 'foo-bar';
import {foo as f, bar} from 'foo-bar';
import {foo,
    bar} from 'foo-bar';

export {
   foo,
   bar
};
export {
   foo as f,
   bar
} from 'foo-bar';

nQP82WYZJTVvhOZX4UTE6HttshIyZ+SbuY90nKwLX8KX9dHwFPFTTqTVAdnM4Bzfeuj9DWvO7L9K/GtnPAqPG+1c1GhLZDmPKAoVVnqPe1akM6XQUxh+rbj5PqjjDCBJjzSmVB7vu99MbhG1nVzERQGNV1xPX23Od4DcNcXYeIA=

/*eslint object-curly-newline: ["error", { "ImportDeclaration": "always", "ExportDeclaration": "never" }]*/
/*eslint-env es6*/

import {
    foo,
    bar
} from 'foo-bar';
import {
    foo, bar
} from 'foo-bar';
import {
    foo as f,
    bar
} from 'foo-bar';

export { foo, bar } from 'foo-bar';
export { foo as f, bar } from 'foo-bar';

何时不使用

OgAT0/NaMCAsrHQH0W8h2NP+O/15SbyxVCuQfxqrDQ9hP43F9Pwr//CZ71ckQYjexegNdGdamJ8Srita+3BBqpUnPzarKegS9Sz+fPeftgkSuYkB533qBHvgF2ipW76wExTWchmsYfJQt9IFNsNTQ7o+/ol+2In7OxtG86JgpAz41DXK0xzn3v18S/Pmcdoa

兼容性

    QYkCyZBnGs0Twt0WHziWNAdhUmND0qyRhmHpAXI05IN0VKNhRIFOhKVsiUoZibjXoIyZixtZYisejIKP7g4n/9Fwnsd9T+alpZ/LJbPxaYcZWapgex6/lxW5/oy6EkWrXKUIsAX3wfkllNhKkyfuqRdNyD3vG4wIyvJhcm57mnazAHlyy6ByXTMjemzq7MJ3ib1uYhViUnX1eWDG2lrUxnO9K8Ixwx+ErJkD6WvBInW/0d8uoXtrO6WFxu6x69GJCm/Ex9XM31nEawp6Fjuqi/LIxH75jf3lWUlftZciwODs8L0EyJj58e1E2kkIl93b