eol-last
要求或禁止在文件末尾换行
此规则报告的一些问题可通过 --fix
命令行选项自动修复
此规则在 ESLint v8.53.0 中已弃用。请在 @stylistic/eslint-plugin-js
中使用 相应的规则。
¥This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js
.
非空文件中的尾随换行符是一种常见的 UNIX 习惯用法。尾随换行符的好处包括能够连接或附加到文件以及将文件输出到终端,而不会干扰 shell 提示。
¥Trailing newlines in non-empty files are a common UNIX idiom. Benefits of trailing newlines include the ability to concatenate or append to files as well as output files to the terminal without interfering with shell prompts.
规则详情
¥Rule Details
此规则在非空文件的末尾强制执行至少一个换行符(或没有换行符)。
¥This rule enforces at least one newline (or absence thereof) at the end of non-empty files.
在 v0.16.0 之前,此规则还强制文件末尾只有一行。如果你仍然需要此行为,请考虑使用 maxEOF
和/或 no-trailing-spaces 启用 no-multiple-empty-lines。
¥Prior to v0.16.0 this rule also enforced that there was only a single line at
the end of the file. If you still want this behavior, consider enabling
no-multiple-empty-lines with maxEOF
and/or
no-trailing-spaces.
此规则的错误代码示例:
¥Examples of incorrect code for this rule:
/*eslint eol-last: ["error", "always"]*/
function doSomething() {
var foo = 2;
}
此规则的正确代码示例:
¥Examples of correct code for this rule:
/*eslint eol-last: ["error", "always"]*/
function doSomething() {
var foo = 2;
}
选项
¥Options
此规则有一个字符串选项:
¥This rule has a string option:
-
"always"
(默认)强制文件以换行符 (LF) 结尾¥
"always"
(default) enforces that files end with a newline (LF) -
"never"
强制文件不以换行符结尾¥
"never"
enforces that files do not end with a newline -
"unix"
(已弃用)与 “always” 相同¥
"unix"
(deprecated) is identical to “always” -
"windows"
(已弃用)与 “always” 相同,但在自动修复时将使用 CRLF 字符¥
"windows"
(deprecated) is identical to “always”, but will use a CRLF character when autofixing
已弃用:选项 "unix"
和 "windows"
已弃用。如果你需要强制执行特定的换行样式,请将此规则与 linebreak-style
结合使用。
¥Deprecated: The options "unix"
and "windows"
are deprecated. If you need to enforce a specific linebreak style, use this rule in conjunction with linebreak-style
.
版本
此规则是在 ESLint v0.7.1 中引入。