From cae0d8743a31fb0eda3c224a45c14de8cabd0d90 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 20:28:46 -0400 Subject: [PATCH] Don't fix end-of-file in files named like licenses The unanchored `LICENSE` and `COPYING` alternatives match the pattern anywhere, and therefore exclude the currently used path `fuzzing/LICENSE-BSD`. License files are more likely than other files in this project to be introduced as symlinks, and less likely to be noticed immediately if they break. Symlinks can be checked out as regular files when `core.symlinks` is set to `false`, which is rare outside of Windows but is the default behavior when unset on Windows. This exclusion fixes the current problem that end-of-file-fixer breaks those links by adding a newline character to the end (the symlinks are checked out broken if that is committed). It also guards against most future cases involving licenses, though possibly not all, and not other unrelated cases where symlinks may be used for other purposes. Although the pre-commit-hooks repository also provides a destroyed-symlinks hook that detects the situation of a symlink that has been replaced by a regular file, this does not add that hook, because this situation is not inherently a problem. The code here does not require symlinks to be checked out to work, and adding that would break significant uses of the repository on Windows. Note that this leaves the situation where a license file may be a symlink to another license file and may thus be checked out as a regular file containing that file's path. However, it is easy to understand that situation and manually follow the path. That differs from the scenario where a symlink is created but broken, because attempting to open it gives an error, and the error message is often non-obvious, reporting that a file is not found but giving the name of the symlink rather than its target. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f6892687..424cc5f37 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: rev: v4.6.0 hooks: - id: end-of-file-fixer - exclude: ^test/fixtures/ + exclude: ^test/fixtures/|COPYING|LICENSE - id: check-symlinks - id: check-toml - id: check-yaml