Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MD047 - Files Should End with a Single Newline Character

Severity: Warning
Category: Whitespace
Auto-fix: ✓ Available

Rule Description

This rule ensures files end with exactly one newline character. This is a POSIX standard and helps with version control systems.

Why This Rule Exists

Files ending with a newline are important because:

  • POSIX standard requires text files to end with a newline
  • Git and other VCS show "No newline at end of file" warnings
  • Prevents issues when concatenating files
  • Ensures consistent file formatting
  • Some tools expect the trailing newline

Examples

❌ Incorrect (violates rule)

# Document

Last line without newline```

Or with multiple newlines:

```markdown
# Document

Last line with multiple newlines


✅ Correct

# Document

Last line with single newline

Configuration

This rule has no configuration options.

Automatic Fix

This rule supports automatic fixing with --fix. The fix will:

  • Add a newline if the file doesn't end with one
  • Remove extra newlines if there are multiple
  • Ensure exactly one newline at the end of the file

Apply Fix

# Fix file endings
mdbook-lint lint --fix docs/

# Preview what would be fixed
mdbook-lint lint --fix --dry-run docs/

When to Disable

Consider disabling this rule if:

  • You're working with files that intentionally lack final newlines
  • Your toolchain doesn't support files with trailing newlines
  • You're dealing with generated content that doesn't include newlines

Disable in Config

# .mdbook-lint.toml
disabled_rules = ["MD047"]

Disable for Specific Files

Since this is a file-level rule, you can exclude specific files:

# .mdbook-lint.toml
[[overrides]]
path = "no-newline.md"
disabled_rules = ["MD047"]
  • MD009 - No trailing spaces
  • MD010 - Hard tabs
  • MD012 - Multiple consecutive blank lines

References