Trailing Whitespace
debt(d3/e1/b1/t5)
Closest to 'default linter catches the common case' (d3), because detection_hints lists php-cs-fixer, phpcs, editorconfig, and git — all commonly available and default-configured tools that flag trailing whitespace automatically, with no specialist setup required.
Closest to 'one-line patch or single-call swap' (e1), because the quick_fix describes a single editor setting (auto-strip on save) and one .editorconfig line (trim_trailing_whitespace = true) — no refactor needed.
Closest to 'minimal commitment' (b1), because trailing whitespace is a file-level formatting property with no architectural reach; fixing it is a one-time cleanup with no ongoing structural tax on maintainers.
Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5), because the misconception field explicitly states developers assume trailing whitespace is purely cosmetic — yet it can break heredoc syntax in PHP and cause noisy diffs. This is a well-known but non-obvious gotcha, matching t5.
Also Known As
TL;DR
Explanation
Trailing whitespace adds noise to git diffs (lines appear changed when only whitespace changed), can interfere with "headers already sent" errors in PHP if a file ends with whitespace after the closing ?> tag, and makes grep results harder to read. Most editors have a "trim trailing whitespace on save" setting. The PSR-12 standard explicitly prohibits trailing whitespace.
Common Misconception
Why It Matters
Common Mistakes
- Not configuring editors to trim trailing whitespace on save.
- Not adding trailing_whitespace = true to .editorconfig.
- Mixed files where some lines have trailing whitespace and others don't — inconsistent.
- Trailing whitespace in heredoc strings that alters the string content.
Code Examples
function greet(string $name): string {
return 'Hello ' . $name;
// ^^^ trailing spaces — invisible but in git diff
}
// .editorconfig fix:
[*]
trim_trailing_whitespace = true
// Trailing whitespace causes noise in diffs and can break heredoc/string comparisons
// .editorconfig
[*.php]
trim_trailing_whitespace = true
// Auto-fix with phpcbf:
$ vendor/bin/phpcbf --standard=PSR12 src/
// Git pre-commit hook to block commits with trailing whitespace:
$ git config core.whitespace trailing-space
// PhpStorm: Settings → Editor → General → Strip trailing spaces on save
// VS Code: "files.trimTrailingWhitespace": true (in settings.json)