Index

eol-last

要求或禁止在文件末尾换行

🔧 Fixable

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

Important

This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.

Learn more

非空文件末尾的换行符是常见的 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 之前,该规则也会强制文件末尾只有一行。如果你仍然希望这种行为,可以考虑启用 no-multiple-empty-lines 并使用 maxEOF 和/或 no-trailing-spaces

🌐 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)结尾
  • "never" 强制文件末尾不以换行符结尾
  • "unix"(已弃用)与“always”完全相同
  • "windows"(已弃用)与“always”相同,但在自动修复时会使用 CRLF 字符

**已弃用:**选项 "unix""windows" 已弃用。如果你需要强制使用特定的换行样式,请将此规则与 linebreak-style 配合使用。

版本

此规则是在 ESLint v0.7.1 中引入。

资源