require or disallow newline at the end of files (eol-last)

要求或禁止文件末尾保留一行空行 (eol-last)

The --fix option on the command line can automatically fix some of the problems reported by this rule.

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

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.

在非空文件中存在拖尾换行是一个常见的 UNIX 风格。它的好处同输出文件到终端一样,方便在串联和追加文件时不会打断 shell 的提示。

Rule Details

This rule enforces at least one newline (or absence thereof) at the end of non-empty files.


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.

在 v0.16.0 之前此规则还强制在文件末尾只有一行空行。如果你仍然想要这样,可以考虑开启 no-multiple-empty-lines 使用 maxEOF 和/或 no-trailing-spaces

Examples of incorrect code for this rule:

错误 代码示例:

/*eslint eol-last: ["error", "always"]*/

function doSmth() {
  var foo = 2;

Examples of correct code for this rule:

正确 代码示例:

/*eslint eol-last: ["error", "always"]*/

function doSmth() {
  var foo = 2;


This rule has a string option:


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.

弃用:"unix""windows" 选项已被弃用。 如果你需要强制一种指定的换行风格,结合 linebreak-style 规则一起使用。


This rule was introduced in ESLint 0.7.1.

该规则在 ESLint 0.7.1 被引入。