junk-file
A file an editor, the operating system, or a language's tools left behind.
- Group
- Code
- Runs
- On by default
- Level
- warning
- Reads
- Every file
- Fix
- None: deleting a file is left to the person who knows they do not need it
Why
Editors, operating systems, and build tools leave files beside the code that nobody means to keep: Vim's swap and undo files and Emacs's backups, auto-saves, and locks; macOS's .DS_Store, ._ resource forks, and volume metadata, Windows's Thumbs.db and desktop.ini, and KDE's .directory; merge and patch leftovers (.orig, .rej) and backups (.bak, .tmp, rustfmt's .rs.bk); Python's __pycache__, .pyc, and the caches of pytest, mypy, ruff, Hypothesis, tox, and Jupyter; compiled Java classes and object files; and the crash logs of npm, Yarn, pnpm, and the JVM. Each one is reported by its name, and a directory of them once. The rule runs by default, over hidden files too; a file .gitignore ignores is not read, so ignoring the pattern keeps it from coming back. A project that keeps such a file on purpose, such as a fixture, leaves it out with exclude in [lint.junk-file].
The fix, as Ur suggests it: delete it and ignore its pattern in .gitignore, or leave it out with exclude in [lint.junk-file] if the project keeps it on purpose.
For agents
Never add an editor's swap or backup file, an operating system's folder metadata, a compiled or cached file, or a crash log to the project; delete it, and ignore its pattern in .gitignore.
Example
src/main.rsfn main() {
println!("{}", shop::total(&[250, 1999]));
}
src/.main.rs.swpb0VIM 9.1
src/main.rs~fn main() {
println!("{}", shop::total(&[250, 1999]));
}
.DS_StoreBud1
tools/__pycache__/gen.cpython-312.pycbytecode
$ ur lint --rule junk-file
warning[junk-file]: `.DS_Store` is Finder's folder settings, which macOS writes
--> .DS_Store:1:1 this file
= hint: delete it and ignore its pattern in .gitignore, or leave it out with `exclude` in `[lint.junk-file]` if the project keeps it on purpose
warning[junk-file]: `src/.main.rs.swp` is a Vim swap file
--> src/.main.rs.swp:1:1 this file
= hint: delete it and ignore its pattern in .gitignore, or leave it out with `exclude` in `[lint.junk-file]` if the project keeps it on purpose
warning[junk-file]: `src/main.rs~` is an editor's backup copy, as Emacs and Vim write
--> src/main.rs~:1:1 this file
= hint: delete it and ignore its pattern in .gitignore, or leave it out with `exclude` in `[lint.junk-file]` if the project keeps it on purpose
warning[junk-file]: `tools/__pycache__` is Python's bytecode cache
--> tools/__pycache__:1:1 this file
= hint: delete it and ignore its pattern in .gitignore, or leave it out with `exclude` in `[lint.junk-file]` if the project keeps it on purpose
0 clone classes and 4 `junk-file` findings in 5 files