From d1582d181bfeb5138d9cae306b40dfa2fe87fe39 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 18:08:22 -0400 Subject: [PATCH 01/10] Update versions of pre-commit hooks --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 692c7fa2a..7d93876ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/codespell-project/codespell - rev: v2.2.4 + rev: v2.3.0 hooks: - id: codespell additional_dependencies: [tomli] @@ -8,7 +8,7 @@ repos: exclude: "test/fixtures/" - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.3 + rev: v0.6.0 hooks: - id: ruff args: ["--fix"] @@ -17,14 +17,14 @@ repos: exclude: ^git/ext/ - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.9.0.6 + rev: v0.10.0.1 hooks: - id: shellcheck args: [--color] exclude: ^test/fixtures/polyglot$|^git/ext/ - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: end-of-file-fixer exclude: test/fixtures/ @@ -33,6 +33,6 @@ repos: - id: check-merge-conflict - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.16 + rev: v0.19 hooks: - id: validate-pyproject From 016fa44a64ac244de2335b00338af67e3f8585ee Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 18:09:06 -0400 Subject: [PATCH 02/10] Have codespell ignore words that cause new false positives --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6cf4b3f5d..090972eed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,6 @@ lint.unfixable = [ [tool.codespell] -ignore-words-list="gud,doesnt" +ignore-words-list="afile,assertIn,doesnt,gud,uptodate" #count = true quiet-level = 3 From c82bb65fd263603b374b925f61483efc47c2a264 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 18:13:28 -0400 Subject: [PATCH 03/10] Fix a spelling error that codespell didn't catch --- .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 7d93876ed..90b899f8e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: hooks: - id: codespell additional_dependencies: [tomli] - # args: ["--write-changes"] # consider enabling for auto-fif + # args: ["--write-changes"] # consider enabling for auto-fix exclude: "test/fixtures/" - repo: https://github.com/astral-sh/ruff-pre-commit From 9556f63a965877db19002849d7bfeec71e84a2c7 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 18:19:03 -0400 Subject: [PATCH 04/10] Drop suggestion to auto-fix spelling (many false positives) --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90b899f8e..c47d9a2c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,6 @@ repos: hooks: - id: codespell additional_dependencies: [tomli] - # args: ["--write-changes"] # consider enabling for auto-fix exclude: "test/fixtures/" - repo: https://github.com/astral-sh/ruff-pre-commit From 7a138eea78fd922b21f6049d273aaeca5f02bfb0 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 18:55:48 -0400 Subject: [PATCH 05/10] Fix small inconsistencies in test/fixtures/ exclusions --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c47d9a2c7..f5635b2a0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: hooks: - id: codespell additional_dependencies: [tomli] - exclude: "test/fixtures/" + exclude: ^test/fixtures/ - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.6.0 @@ -26,7 +26,7 @@ repos: rev: v4.6.0 hooks: - id: end-of-file-fixer - exclude: test/fixtures/ + exclude: ^test/fixtures/ - id: check-toml - id: check-yaml - id: check-merge-conflict From 53ec790e0dbc1ec9e4451394edb5c572c807b817 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 19:01:02 -0400 Subject: [PATCH 06/10] Fix inconsistent indentation --- .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 f5635b2a0..0cbf5aa73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,4 +34,4 @@ repos: - repo: https://github.com/abravalheri/validate-pyproject rev: v0.19 hooks: - - id: validate-pyproject + - id: validate-pyproject From bdfa280f6dd412464419dd133ad02781cd27a312 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 19:02:14 -0400 Subject: [PATCH 07/10] Temporarily let end-of-file-fixer break LICENSE-BSD symlink On Windows, when `core.symlinks` is `false` or unset (since it defaults to `false` on Windows), Git checks out symbolic links as regular files whose contents are symlinks' target paths. Modifying those regular files and committing the changes alters the symlink target in the repository, and when they are checked out as actual symlinks, the targets are different. But the `end-of-file-fixer` pre-commit hook automatically adds newlines to the end of regular files that lack them. It doesn't do this on actual symlinks, but it does do it to regular files that stand in for symlinks. This causes it to carry a risk of breaking symlinks if it is run on Windows and the changes committed, and it is easy to miss that this will happen because `git diff` output shows it the same way as other additions of absent newlines. This deliberately commits the change that end-of-file-fixer makes to the `LICENSE-BSD` symlink, in order to allow a mitigation beyond just excluding that symlink (or replacing it with a regular file) to be tested. This change must be undone, of course. --- fuzzing/LICENSE-BSD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuzzing/LICENSE-BSD b/fuzzing/LICENSE-BSD index ea5b60640..4f88f81bf 120000 --- a/fuzzing/LICENSE-BSD +++ b/fuzzing/LICENSE-BSD @@ -1 +1 @@ -../LICENSE \ No newline at end of file +../LICENSE From 965ea8bebcd768f6cadbc6cae6b7fe65868f1fb6 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 20:17:24 -0400 Subject: [PATCH 08/10] Enable check-symlinks pre-commit hook Rationale: - Small but likely benefit in general, since there are no currently foreseen intentional use cases of committing of broken/dangling symlinks in this project. So such symlinks that arise are likely unintentional. - If the end-of-file-fixer hook has run on a Windows system where `core.symlinks` has *not* been set to `true`, and symlinks' paths have not been excluded, then a newline character is added to the end of the path held in the regular file Git checks out to stand in for the symlink. Because it is not actually a symlink, this will not detect the problem at that time (regardless of the order in which this and that hook run relative to each other). But when it is then run on CI on a system where symlinks are checked out, it will detect the problem. --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0cbf5aa73..3f6892687 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,6 +27,7 @@ repos: hooks: - id: end-of-file-fixer exclude: ^test/fixtures/ + - id: check-symlinks - id: check-toml - id: check-yaml - id: check-merge-conflict From e9782487b8119147aa0c456c708f61ca7e3139e1 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 20:24:36 -0400 Subject: [PATCH 09/10] Revert "Temporarily let end-of-file-fixer break LICENSE-BSD symlink" This reverts commit bdfa280f6dd412464419dd133ad02781cd27a312. --- fuzzing/LICENSE-BSD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuzzing/LICENSE-BSD b/fuzzing/LICENSE-BSD index 4f88f81bf..ea5b60640 120000 --- a/fuzzing/LICENSE-BSD +++ b/fuzzing/LICENSE-BSD @@ -1 +1 @@ -../LICENSE +../LICENSE \ No newline at end of file From cae0d8743a31fb0eda3c224a45c14de8cabd0d90 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 15 Aug 2024 20:28:46 -0400 Subject: [PATCH 10/10] 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