strict

要求或禁止严格模式指令

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

严格模式指令是脚本或函数体开头的 "use strict" 字面。它启用严格模式语义。

当指令出现在全局范围内时,严格模式适用于整个脚本:

"use strict";

// strict mode

function foo() {
    // strict mode
}

当指令出现在函数体的开头时,严格模式仅适用于该函数,包括所有包含的函数:

function foo() {
    "use strict";
    // strict mode
}

function foo2() {
    // not strict mode
};

(function() {
    "use strict";
    function bar() {
        // strict mode
    }
}());

EbSYInlem385jyQXmvkOsysHKXJhTyQyLDRpk2biMGCI+BfzRxuQb1wFSjiOlV22cUGMS7bUY2HncujWBO5fmyyb3egCjfo5hLp0REhs6gsaXC6H0WFDYfZXRZu7aH/SZn20LXIyxsdBJTLC4TO7XUJ7ddz/G5Hpzt+J/IbZx2g=

OCQ3iR25s6K7G20c969FWwYbfy2/aZh40Fm4DzHPFvMGQxoj66dcpgXGX5AnUIxK59yLs7N9r4wAtTTnykS5hrR2O5NGaazTraOBS6m7iSBRsotf2Nl1dpxy5B+JH9Lh

规则详情

iaDZS5R9bOIvnAMBvIu0DZWfnzk9CSTR23c5as5iVpW843pugwqo4AENv3F0mhv6

/XwrxHBE04dsIpt5qyioCHGzxYJgXSuV7IZg+oaROiXc5WAJUBL3Y5PEp+rE6cVC5totJhl1wg/yXnMZxdwK2wrDE8ftrdf79HYBs4Mi0xP/km+cMgKw0S1C4vWApUe2NxoJ5BYh16Y3JPH6WwGAuC5UyjK9mLKE//HbSDc1PUd6cRwVg6g+yeQPQn4lPo87KL+KcTG89ExsUDk09kuPv1VoNuCP7vmlj6ywpTDQF5oqjX5SLOp9k0KWOYPhuo0C

    ltfdY44Ti2AmQt0LAQhEtT28DYIOZbIiOAuy1Z5z3nl2QUaxTCtiT5vxva9ABbYGNXkoLTAsLfmXfy3Hy+lnqH1CehQNTc6YxokRKtx6KAEgg5VQhWdmkoU9Q4UJK8ZpROjlDOyB2ZMLv5Je+UEciO9N7sxHjv8bJBQfoqNhFHQnI8hL4BaR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Ug5LrVsc+dFmEqlwzNyC2Smx+fqzRlIOfv10dg9eF0c0T5InDNX9DG7RGOg3htQ8AVAwxYlGsprjdsH9pAcpu9VNA31QoGy5FhP2x52V4Wd25YBmzr0PGpOgB88IRg9Rt0Z5qGLhYL3Tdpqap01oHgTiYHoDBWG3auXVhTovpVLFmXUW3fhKsWLDo4M7pXHWSIRY6wAbMbnr88VsZPpuKoH0gnI0fHzXoSziCs9mnapo/1dBqeh5nfNxlRk3kT9jk1YWGjGP8t4dXE2q5rK3Vz+JldpSY7nW7WRRNtbPiHAqBUWUVBy3nrePedTqQ=

/DcSV3up/jsfIbxfQbZ5T6iLXo8DA3PmVP0gU8YNRil9aD54sOV9QB5+K2WOFq4NjWsOAY7T3FL+2cR+L3AGmt0p8zrUcMv/Cd6dsTlj7BhC82Wt1/K0Fu8bU3Dh/ZjpAoVL7jsgC5f1fIVjmiDX0Qx02uz7BnYq6K+j9KUfSUbFysH4eS9MyaT/+TzAXDBZSCv8k7MZAJe3X8vRL0jkCrdbnF5bsTJwZzJS7Dg2P9BY+wvbvClNM/6L8p/2Oh3INYgRofzj3ttdTTXcuPcnd/PuyJYjDX5cHfOmWEQtEZo7h1QLkmKrmr7K0zM6zjabuekNz596ayOOag8lG5usnHXBsPboACbzMOQ4r8NCMmc=

global

gzlG8jANWr4Hhb4/2Xwr93AV5aaymojmMJ3AJlmf0V5Y2+y0oZCykbs8aS+je0v/WfhYhByiOKVLSR2Y+NrAJuhzEmUqujukf1S2WYUfIxI=

/*eslint strict: ["error", "global"]*/

function foo() {
}
/*eslint strict: ["error", "global"]*/

function foo() {
    "use strict";
}
/*eslint strict: ["error", "global"]*/

"use strict";

function foo() {
    "use strict";
}

gzlG8jANWr4Hhb4/2Xwr93AV5aaymojmMJ3AJlmf0V67pyH4HiiPwDLoE2Ze/S9NASiMRyTSAiavUUXb4hvhUqOIBhZ2yr2clN6BDmnka6Y=

/*eslint strict: ["error", "global"]*/

"use strict";

function foo() {
}

function

Aoi33z8Jys++TWj/jR7PpgLXP2Z89WsO/6LUsJqbyw5YBKEJRCr+q5Xe1+jUi5cjR4OAQ5hFkLZtp1tGxA91L1VK7M8FlfdODnvkqrZAqFZ03yyp1Vi3blJUQ9tgKuAUYkNolzb2LfrduMI91445PBfmNAYwiLN8PUVuM4JvV/7rFbqHs60ZRHXEHdNf0j+lxFGWI0RIW8+OSKXBxwvLmkZk2grAz9dHB/QaH/a1OqajIUSlNFYYhinUdZ8/G3jymDf8w7Nn0W7Er70OlZW5O0u3H7r4z52vFDVT/D0Q+3IjunZy7xtMcCer5Xz2q+FqSfGc2AV1hOkrCYXC3peGEozsVagQuw9djcOJK/DMgwfJ33wUbdBr0OMGy5IwRp7FKcU81zrr1VWnKrAHr8JZrw==

gzlG8jANWr4Hhb4/2Xwr9xjD5HuwjyDjekIwcCI2MSkqNTFBjObhoLlvBMPP1eS3ecRvpvkyMGsSQTIay55+Huk4bzxLuxazPEHN78XSHTo=

/*eslint strict: ["error", "function"]*/

"use strict";

function foo() {
}
/*eslint strict: ["error", "function"]*/

function foo() {
}

(function() {
    function bar() {
        "use strict";
    }
}());
/*eslint strict: ["error", "function"]*/
/*eslint-env es6*/

// Illegal "use strict" directive in function with non-simple parameter list.
// This is a syntax error since ES2016.
function foo(a = 1) {
    "use strict";
}

// We cannot write "use strict" directive in this function.
// So we have to wrap this function with a function with "use strict" directive.
function foo(a = 1) {
}

gzlG8jANWr4Hhb4/2Xwr9xjD5HuwjyDjekIwcCI2MSkqNTFBjObhoLlvBMPP1eS3YrkH52itjuVno3g9hbeZurYZFDOv3C70CATdAvpWAhE=

/*eslint strict: ["error", "function"]*/

function foo() {
    "use strict";
}

(function() {
    "use strict";

    function bar() {
    }

    function baz(a = 1) {
    }
}());

var foo = (function() {
    "use strict";

    return function foo(a = 1) {
    };
}());

never

gzlG8jANWr4Hhb4/2Xwr99gbBBt/zgYd+m2LbPq2shzHTFvrMOHWOiytSQtiLMXa/UFIRIIbHSYcSNm7+e8qUmh0GAjf7D5//ubHqz4Nylc=

/*eslint strict: ["error", "never"]*/

"use strict";

function foo() {
}
/*eslint strict: ["error", "never"]*/

function foo() {
    "use strict";
}

gzlG8jANWr4Hhb4/2Xwr99gbBBt/zgYd+m2LbPq2shyZdwfAqDk8uTXhhtqGVwZlAPG1lBRo9fKx66Cs9hQbQdE2eBYRtyQb5nrNlHWyQzM=

/*eslint strict: ["error", "never"]*/

function foo() {
}

earlier default(已移除)

rFX3Ryydmd70FWsIaE4Hrq/jQDXmeniJeblsmzRx+e4trfrGwRphAZM4Q2mAsP91WGl0dpT9UCu3WOvNpEUldWHEPDJlQAxyrq1U6o+th9p1VRD/W+pUugmXoGd7wZBK/7WCFa0ncymXf6iN+MiYTWjk1UqPHfFNoWGnIfXDEYN5cqMPHjbaH7qeYvHITurlA+Qgjgh0NWXdKLIezmpwbPKfRQgm369js2VmH61G/0Y=

Aoi33z8Jys++TWj/jR7Ppt+MoFldpGmSMl0MJZqYE2/xlpDylBT9i+8IQnTWkFjtrFJe8/KZlJd40qxBUakTknsgXyTeA6Bgq/0okCWEnHCC34+8pRvkSco/mawSmggMrD4p722f4O0UTNdAzre4Ff8fZxfPELOQAtwEKt1KOCS4ntXOBn33wbgpWli7l9NYTnfYpJFu21BYTlgX3K+DiMXnjizuPFePbsgu4ZmyyG0AVCoM6T3Y+0oJiSeAQUaNhRw+tbn/w+i5w04AUqKaehZJ4laoBD4WX3iUiI2eE1Uvp+yrFacHBSPaC1ZWooHM9v0rB9GzFbOb6CfPGtYRj08xyHC/JfZOjyI/x9kXtgT6NOpNshRa4Wcm21xT425o

jvkUkhkS7HSb+ijdsHFfDj+eTHChwZIJiUsC/sTetlI7aK5nMSSUQTIPviLalKVshf5vWdVW10tD6y3+f2IyITRi2ggP7DO5TcoI1lvnUrw=

// "strict": "error"

function foo() {
}
// "strict": "error"

(function() {
    function bar() {
        "use strict";
    }
}());

3vRURIMaWDsQZ7e/enlM+JC2/SIKv9fsDPfP++8HBO4+3QwQGPsy6Kl41symDbUnQmO4yZD28bw0pHMUI7XdkRxBuUR4f5Tzr1/rqz/9ukU=

// "strict": "error"

"use strict";

function foo() {
}
// "strict": "error"

function foo() {
    "use strict";
}
// "strict": "error"

(function() {
    "use strict";
    function bar() {
        "use strict";
    }
}());

何时不使用

zRK/6Y6g5Fa4hnV7bUs01QgWfizZIJPj5S+WCPrfTGU7J89GWELvFBnu9vEJmzcLgDtIz5Uk1A/gbGeSixZmwOFZO65aHRTWBmNV5/0mnEcjuHs8dosb69eU0nGJnhbUONk5+JutL5ObBa11EGF9A/9DYUJBVZcFCQYcLvsbzzzGMYkSKnbjuxY5n822s0DCp5vQdqzIvDQciQhHxlMorzBm0IkG42syjIpvTlBbS/zv2fOUsw4w+totU4z6DHgq/joh80Q9ONlffvp68kpxvbiXeHHx2uWIilnolkyxWK5lvvSjyFrS2Tr5gfYpbAzWaxwpMwKfKzyqdmWW/09gmFy4RjcMA7iafSsW18vG4ftb/s18wwMabuQX/WZoWNxwq+ApKQ6oLxvGcIgYO3Nn+9zubEDaZTfOYDwUCIln6ess8IRw7YXEHsY6r5ot0EK2+hNmS2sj9M73SRtUjcyDN+UgZdzFl4mojX4BZ9pME+8=