padded-blocks

要求或禁止在块内填充

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

一些样式指南要求块语句以空行开头和结尾。目标是通过在视觉上分离块内容和周围代码来提高可读性。

if (a) {

    b();

}

既然拥有一致的代码风格是件好事,那么您要么总是编写填充块,要么永远不要这样做。

规则详情

此规则在块内强制执行一致的空行填充。

选项

cWpuyLzV0yUvaZA1cHmCCyxRqK0kYW4Rk3hUPHpZI3edb54wLerr8A1gDxqvcHPqHisz5hqBm7+jeKWmL+BCMXnWtkFMMn4oRt1o0iudHa96HiNlPiuWiqdB2/U8iMiAHjVVEJq8nAbvOWdMS1hndVEkIl4zLxTcnrJECQf9SPymd65QcHq65WxBtbmbhOcx

第一个选项

kHfccWZ4DfZe9lRjqakf5/3NP2axNaZhOIG4vR7xX7Q=

    d5CvDQ+WtLSkE0tJJ7ZphHM2gIvrZMneSsTNAbLO413N3nuFx5TKKweqtm6UvcNpWOQyNuitS5e/D9zv80Gm9XkZws+znQwyibohwtirF1v10hTahjRVnVs4PIGR/lITICY3MQkDNNEx5N+ZWwRVZVwHlg86jmXOk9S5bFYMEzfBLiExmuvBe3Gk1ikCy4DwqbtHUcj4kPfUOONmxXinRRacT8JmCNyHkc9i6xkNSB7DDdo20ndIX1L5HBIOUF5LUjNpiE2YdQe28QoF1WdtB2sBQVNd5C3waWgr4/ptaGoxIB9wvkOCyg7vkDV5dGpYKMwxM3HMgELgyLsWO27loL2T6QL77MFIorp4ybsVFKZtNa+EIZk9MUflytRucQY82hDeOYpFFJQ+8MMskN9ZVGQVRIpD8FPpRs25b45tlPo=

voibwsaFFftuogUNmUDZnQ==

    0OxKJ9dsxysoazY38fLkZm5uCY01SF+s6f2l2uize3moWt7J+EA34InMVmpx2VP/lfn7nUKVsJQCer3Wv0yiLWSH8Ngy2TZpFnDqpBZVB6wqxma3s2dK1BKRUnW5rTfe7oIgwSVP7xVI3zlYTQD4eYQudlH2ZtnJlcxhb+jEfv2yx88ZsH005WXNs4Bd2KbbyAPrXbSK+NPGvIEPlX8VcXs7eWvpXJ6OBRCE0SuJZqRNsGnIv5c7AeppJEmXe/b4KjaVWP6a1EpiwjExvIdZ/BHe2ZQkYwkipHStteEf8PfIG0y4HtEVqH7RLlMsmcSQRfSLbVUZhMYrNj10TzsxZQ==

第二种选择

    J52LYaJhI0afApeaqBtuskz0vImEZkMOZsGU115GCM3Sxz7WBi+3ujEBmN/Y/073CCOxXujh3IiB/2UtVGMY1ZwzEqE9DhXmAPh/0udN1L0=

always

fMxAu85BjIe6KL+vThfysfnIPyF+IzG94tk6+Y8RTh05MRzaUfrsrTUvexxWwqRMAmZEX1IWxruJILPqI0CNbJ1ak39Lt0jr4Dm55GOLcis=

/*eslint padded-blocks: ["error", "always"]*/

if (a) {
    b();
}

if (a) { b(); }

if (a)
{
    b();
}

if (a) {
    b();

}

if (a) {
    // comment
    b();

}

class C {
    static {
        a();
    }
}

fMxAu85BjIe6KL+vThfysfnIPyF+IzG94tk6+Y8RTh05MRzaUfrsrTUvexxWwqRM4DoH5hZJU7axXN6dacqLTTyChg5vQIiaaipz0Pi30Xc=

/*eslint padded-blocks: ["error", "always"]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    // comment
    b();

}

class C {

    static {

        a();

    }

}

never

yOPmeunUbyT4mmCnPBjZ7ajv5kDd1zkaFstzkR/+QddoUz6Y2X5db/sMb1TIrB6kPauvKrqShoFcBIZmySk5B0iz1L3KX2sjNSZEMsDZ6m0=

/*eslint padded-blocks: ["error", "never"]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    b();
}

if (a) {
    b();

}

class C {

    static {

        a();

    }

}

yOPmeunUbyT4mmCnPBjZ7ajv5kDd1zkaFstzkR/+QddEhj49R7+jHfoyytT+L+OI/7oJfBCxR++SyXirJCwnEYrxnfqzYkmj5yGyLHLBwtI=

/*eslint padded-blocks: ["error", "never"]*/

if (a) {
    b();
}

if (a)
{
    b();
}

class C {
    static {
        a();
    }
}

blocks

yOPmeunUbyT4mmCnPBjZ7b7fuBf+Vt/csIUGO+SXOxCC7akbjqhMDPW1LMGIKP2vvlesl8e/9pfqPbfTWib2NJjgF+VLFT7XT5R+XiZyAftka4u8ofHzK7FYrEIpvMoh

/*eslint padded-blocks: ["error", { "blocks": "always" }]*/

if (a) {
    b();
}

if (a) { b(); }

if (a)
{
    b();
}

if (a) {

    b();
}

if (a) {
    b();

}

if (a) {
    // comment
    b();

}

class C {

    static {
        a();
    }

}

yOPmeunUbyT4mmCnPBjZ7b7fuBf+Vt/csIUGO+SXOxCC7akbjqhMDPW1LMGIKP2vzqbtHYcbkELVEI3n/X0e4zHcZWUar+C141RRDmgnusdvBiCN83OPepU6xfUEp7ks

/*eslint padded-blocks: ["error", { "blocks": "always" }]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    // comment
    b();

}

class C {

    static {

        a();

    }

}

class D {
    static {

        a();

    }

}

yOPmeunUbyT4mmCnPBjZ7b7fuBf+Vt/csIUGO+SXOxDWUd1rqgQs9siaONlZlkO0e06cJ39LtegzhdcmhpvodIaswNsLFwkflrxgqVwkSNRcs6r1mFL+9SLEkJKg2ImY

/*eslint padded-blocks: ["error", { "blocks": "never" }]*/

if (a) {

    b();

}

if (a)
{

    b();

}

if (a) {

    b();
}

if (a) {
    b();

}

class C {
    static {

        a();

    }
}

yOPmeunUbyT4mmCnPBjZ7b7fuBf+Vt/csIUGO+SXOxDWUd1rqgQs9siaONlZlkO0McXKubpDOnbGLHm4c4qj5QU20zSMTe2haENGRsy+kkB7KNMt5o6D59WKZMBcpgoR

/*eslint padded-blocks: ["error", { "blocks": "never" }]*/

if (a) {
    b();
}

if (a)
{
    b();
}

class C {
    static {
        a();
    }
}

class D {

    static {
        a();
    }

}

classes

yOPmeunUbyT4mmCnPBjZ7QMGvgMCNIb1YyQ4C/fOkMFbfMPbXt5XN42NaaBgl9qswQJpQQMADPpeMovY/rPCsH6TpeKmalwQtlmb82wvr5wAnU1p6K3ahDquq9sSnyD7

/*eslint padded-blocks: ["error", { "classes": "always" }]*/

class  A {
    constructor(){
    }
}

yOPmeunUbyT4mmCnPBjZ7QMGvgMCNIb1YyQ4C/fOkMFbfMPbXt5XN42NaaBgl9qsR5UTDlA4FULMQ65hB4Z+ionWuuv7OOX0YkCX8W1VvzNvS8+9wcwkx+bC98Dwefr3

/*eslint padded-blocks: ["error", { "classes": "always" }]*/

class  A {

    constructor(){
    }

}

yOPmeunUbyT4mmCnPBjZ7QMGvgMCNIb1YyQ4C/fOkMEnqMO3pEWmZeDzuoFmUKHuJjA7Abc+PWtcFisaHkQHc0JMJmIk0bm9dN55J5aQUHNa4BCYISEG5z9U3bjO5Vou

/*eslint padded-blocks: ["error", { "classes": "never" }]*/

class  A {

    constructor(){
    }

}

yOPmeunUbyT4mmCnPBjZ7QMGvgMCNIb1YyQ4C/fOkMEnqMO3pEWmZeDzuoFmUKHuW2DZWgFA0J3ZxKr5K/WlAVU3taewKPFU6kdFuWQMB5ymnbG+9xv7uEKvQUSR9hD9

/*eslint padded-blocks: ["error", { "classes": "never" }]*/

class  A {
    constructor(){
    }
}

switches

yOPmeunUbyT4mmCnPBjZ7QnodZdvxzpnHT3xrCMHwVDockHeJbUvCg7Vg3YMYzDId+ztlEJR8I0/mHIvXiLUH5JrSy3B0FVkKIzIh7WEjxn5megzi3TRXpKl20xPTrvt

/*eslint padded-blocks: ["error", { "switches": "always" }]*/

switch (a) {
    case 0: foo();
}

yOPmeunUbyT4mmCnPBjZ7QnodZdvxzpnHT3xrCMHwVDockHeJbUvCg7Vg3YMYzDIS8iOEDWa0uhBXeC2mxb9TD9/nyl6BWKsnf/33zmRGY49W+p/jmdyoq0/tTZhRlue

/*eslint padded-blocks: ["error", { "switches": "always" }]*/

switch (a) {

    case 0: foo();

}

if (a) {
    b();
}

yOPmeunUbyT4mmCnPBjZ7QnodZdvxzpnHT3xrCMHwVCxx8siO02eoj5aKxWmJhKzqp9MXn6dK6OmQ+Q6EiusOG14jh6WPT34HaLtGIWoz2faSfw9zkUfdEjcvt7B1Ex8

/*eslint padded-blocks: ["error", { "switches": "never" }]*/

switch (a) {

    case 0: foo();

}

yOPmeunUbyT4mmCnPBjZ7QnodZdvxzpnHT3xrCMHwVCxx8siO02eoj5aKxWmJhKzccrmo9NbTQh0lIiGaWNAQ8rTexnmRsYvcQE5p0cdw45nkKbg9jCELle+q6vkVZiZ

/*eslint padded-blocks: ["error", { "switches": "never" }]*/

switch (a) {
    case 0: foo();
}

if (a) {

    b();

}

always + allowSingleLineBlocks

yOPmeunUbyT4mmCnPBjZ7VSR7skh6f8YuHTlkwt0VlZplkYRNq+o0tWmKaDAFxMcmM1hpyZ3TxkqlizePKi/94Mq8K1EUG/XZQB443yq2Gau01XBAz8WFs/r8ZKNG1asPERBOeM5Ulaysy83O1QHaw==

/*eslint padded-blocks: ["error", "always", { allowSingleLineBlocks: true }]*/

if (a) {
    b();
}

if (a) {

    b();
}

if (a) {
    b();

}

yOPmeunUbyT4mmCnPBjZ7VSR7skh6f8YuHTlkwt0VlZplkYRNq+o0tWmKaDAFxMcmM1hpyZ3TxkqlizePKi/94Mq8K1EUG/XZQB443yq2GZp90xZmwron1j2IRn9Ndd8IJA+WXxyJRSZRlcIJJN49w==

/*eslint padded-blocks: ["error", "always", { allowSingleLineBlocks: true }]*/

if (a) { b(); }

if (a) {

    b();

}

何时不使用

tnLdDa9aUeBTQq5Y34jBMDmOWexP1nFRI/R9s1tsWF3bG4KqCDLNHERDqpzAS2AlO+4BcIcKbSSiLQvO4VllCA4yPtrOi0DFHJgOzJCwNNE=