lines-around-directive
此规则在 ESLint v4.0.0 中已弃用,并被 padding-line-between-statements 规则取代。
指令在 JavaScript 中用于向执行环境指示脚本希望选择加入诸如 "strict mode"
之类的功能。指令在文件或功能块顶部的 指示序言 中组合在一起,并应用于它们发生的范围。
// Strict mode is invoked for the entire script
"use strict";
var foo;
function bar() {
var baz;
}
var foo;
function bar() {
// Strict mode is only invoked within this function
"use strict";
var baz;
}
规则详情
此规则要求或禁止指令序言周围的空白换行符。此规则不强制执行有关各个指令之间的空白换行符的任何约定。此外,它不需要在指令序言之前使用空白换行符,除非它们前面有注释。如果这是您想要强制执行的样式,请使用 padded-blocks 规则。
选项
该规则有一个选项。它可以是字符串或对象:
"always"
(默认)在指令周围强制使用空白换行符。"never"
不允许在指令周围出现空白换行符。
n1WFN/RrllrZChIOyS4pUQ==
{
"before": "always" or "never"
"after": "always" or "never",
}
always
HoAi8bJkccJ1g/xNNEnDWOcRbRFjHXJYQvnP6N2Axyo=
5nEv4RCYCaBiSjFxJ4F/mKpeHlEIrnzbcqjXOckHJ1AJ0xAHd//XhiviWDbH1IuAqaAyJgfXNGoYxXmr3KHkzg8n3n6+Byg3bZng9pMLAqY=
/* eslint lines-around-directive: ["error", "always"] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
5nEv4RCYCaBiSjFxJ4F/mKpeHlEIrnzbcqjXOckHJ1BfWqE5nzuNHhp5glzX4UAfCadSKulj2RmmZJMOk1cyb5bLx+vIqzR6ie39IF3MWi8=
/* eslint lines-around-directive: ["error", "always"] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
never
5nEv4RCYCaBiSjFxJ4F/mCwtS62WYVf8Z3bTN0V8XnhtvTkeQjr06WS/jwr4MFgTlY/4wZUvk/MeZS6zp4z3JTWT0aSYW+CzBIMGIVe5Dm4=
/* eslint lines-around-directive: ["error", "never"] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
5nEv4RCYCaBiSjFxJ4F/mCwtS62WYVf8Z3bTN0V8Xng2VcIX0zXLVJuKLwV+9IjYF/o37BrrvFCp16+0aw4kI1UXI6hM+nKNGuj36GsSlgM=
/* eslint lines-around-directive: ["error", "never"] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
before & after
5nEv4RCYCaBiSjFxJ4F/mE/QUTr/0IAOUkRSGusG2i5Q2/9bBofavrR8n+Ou0WF+rVQ8x4vjJD3Fl72YB8Dh8gVoffg4Nn4zlReC06BuGhQPvCTKB4CIiqdaM115aQ7ulAdPKQR50J26xFggyrn5kg==
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
5nEv4RCYCaBiSjFxJ4F/mE/QUTr/0IAOUkRSGusG2i5Q2/9bBofavrR8n+Ou0WF+rVQ8x4vjJD3Fl72YB8Dh8gOoeKAjwUXBYLSapr1BI3fDHOsvLFFjvqdWjDNaf4FpfrUQAcLyctfYGxgCyZJsbg==
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
5nEv4RCYCaBiSjFxJ4F/mE/QUTr/0IAOUkRSGusG2i7/O5WLEMg4sbXWupU4bWbQQmDtLusikgP4nse6cv2b0WTRXOLsj1+TBGTt8Mvw/k016S3EsU14yP9lNwKzazsWafI1uEVdVSD7zOYa5jq68A==
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
5nEv4RCYCaBiSjFxJ4F/mE/QUTr/0IAOUkRSGusG2i7/O5WLEMg4sbXWupU4bWbQQmDtLusikgP4nse6cv2b0eQiy4xsD5WlW8lRV1qvcrVthriw2iU6GhyjmzmoFLYrdmM/fDTeoBYa4gOPWeWoSg==
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
/* Top of file */
"use strict";
var foo;
/* Top of file */
// comment
"use strict";
"use asm";
var foo;
function foo() {
"use strict";
"use asm";
var bar;
}
function foo() {
// comment
"use strict";
var bar;
}
何时不使用
6fBUtIGWUllxPkk644JetlaDHyH8m7DJ8I5SnIsG36X9BA0M0moegDcZcfN1LzDWH/9HidZyJwiLWsjtA6m+HT3GZrziKkKuG7pOcfxsTdplnxq6MIX/CXYnQKwTSmYMUfgXfSVIW2R0XA8Ir/pFw2Kjr6SdN2gW6iB9Aw47H4WIC0MP37ZxTsVgu4bRrN2EtgPnDBsLd5JOF91prTvCpw==
兼容性
- 0M72PUUCp+mfNi3LHcXFE4RhiZ0MGpLUS2lahSOQzj5Gw1w6t64Bdhf05WPjUKZRdwOyj4yhfUEGyke7Of5DtRAO91JkV991INBuE1amfCvpIPciMmYfuMymISx9vKCQdI3IBlkyrA4EfzewjH+if2VT6dNm5j/Ubb6aXCe1ucG+2RlwBh8uB8IGCn/OWD1LRYi6r62I/vJzd63dp59z0HPuRjZpUkkt059m1NsfzVjEA4YYIAeB38Dpv8c44pv6UbdcvIN9TgCRvr+qLmt4yUhjMlO2KI1xS1SZtzYTQ7c1UzLBynfbkv5Ayun8dRFfvK6iBaRcG7PWkGuz24bo9Q==