Skip to content

require-eol-last

🎨 Stylistic 🔧 Fixable ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

Require or disallow a newline at the end of files.

Rule Details ​

This rule requires or disallows a final newline in non-empty Markdown files. Empty files are always valid.

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.

Examples ​

❌ Incorrect ​

Examples of incorrect code for this rule:

Default ​

md
<!-- eslint md/require-eol-last: 'error' -->

Tex
t

With 'never' Option ​

The following example ends with a newline after Text.

md
<!-- eslint md/require-eol-last: ['error', 'never'] -->

Text

✅ Correct ​

Examples of correct code for this rule:

Default ​

The following example ends with a newline after Text.

md
<!-- eslint md/require-eol-last: 'error' -->

Text

With 'never' Option ​

md
<!-- eslint md/require-eol-last: ['error', 'never'] -->

Text

Options ​

js
'md/require-eol-last': ['error',
  // First Option
  'always',
  // Second Option
  {
    newline: 'LF',
  }
]

First Option ​

'always' | 'never' ​

Type: 'always' | 'never' / Default: 'always'

'always' requires at least one newline at the end of non-empty files. 'never' disallows newlines at the end of files.

To limit consecutive blank lines, use no-consecutive-blank-line alongside this rule.

Second Option ​

newline ​

Type: 'CR' | 'LF' | 'CRLF' / Default: 'LF'

This option selects the newline inserted by autofix in 'always' mode. That mode accepts existing CR (\r), LF (\n), and CRLF (\r\n) endings regardless of this setting.

Fix ​

In 'always' mode, this rule adds a missing final newline. In 'never' mode, it removes all consecutive newlines at the end of the file.

Prior Art ​