From cbc3848c327645c8d856695656e93efff4f0b904 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Fri, 23 Aug 2024 11:11:54 -0400 Subject: [PATCH 1/3] Update pre-commit hooks --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9ad06e4..75856e2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: reuse - repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update - rev: v0.3.3post1 + rev: v0.4.0post1 hooks: - id: pre-commit-update @@ -75,7 +75,7 @@ repos: exclude: *default_excludes - repo: https://github.com/Jayman2000/jasons-pre-commit-hooks - rev: v0.1.0 + rev: v0.2.0 hooks: - id: detect-bad-unicode @@ -145,7 +145,7 @@ repos: - --strict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.7 + rev: v0.6.2 hooks: - id: ruff From 609700dd8ac9af94706d8bab26bb1a4f7b283bc8 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Fri, 23 Aug 2024 11:19:02 -0400 Subject: [PATCH 2/3] Make repo-style-checker enforce use of nixfmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment, I’m working on a private Git repo that uses repo-style-checker. I want to add a Nix file to that private repo, and I want to make sure that I use good formatting when I create that Nix file. By having repo-style-checker enforce the use of nixfmt, I’m helping guarantee that .nix files will be properly formatted. --- jasons_pre_commit_hooks/repo_style_checker.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jasons_pre_commit_hooks/repo_style_checker.py b/jasons_pre_commit_hooks/repo_style_checker.py index 2f743df..98ecf2b 100644 --- a/jasons_pre_commit_hooks/repo_style_checker.py +++ b/jasons_pre_commit_hooks/repo_style_checker.py @@ -197,6 +197,14 @@ class PreCommitRepoInfo(NamedTuple): url='https://github.com/Jayman2000/jasons-pre-commit-hooks', hook_ids=('unreleased-commit-checker',) ) +PCR_NIXFMT: Final = PreCommitRepoInfo( + # Normally, I would use the upstream repo’s URL, but I can’t because + # this pull request [1] hasn’t been merged yet. + # + # [1]: + url='https://github.com/Jayman2000/nixfmt-pr', + hook_ids=('nixfmt',) +) PRE_COMMIT_REPOS_BY_PATH: Final = ( (('**',), PCR_REUSE), (('.pre-commit-hooks.yaml',), PCR_PRE_COMMIT_UPDATE), @@ -214,6 +222,7 @@ class PreCommitRepoInfo(NamedTuple): (PYTHON_GLOBS, PCR_RUFF), (('.pre-commit-hooks.yaml',), PCR_PRE_COMMIT_ITSELF), (('VERSIONING.md',), PCR_UNRELEASED_COMMIT_CHECKER), + (('**.nix',), PCR_NIXFMT), ) From ea6195b18c580783a06a47b4e41807e8cf5e0e03 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Fri, 23 Aug 2024 11:43:29 -0400 Subject: [PATCH 3/3] Use two spaces for indentation in Nix files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I created this commit because 609700d (Make repo-style-checker enforce use of nixfmt, 2024-08-23) unintentionally created an impossible situation. Specifically, that commit made repo-style-checker give you an error if you had a Nix file in your repo, but didn’t have the nixfmt pre-commit hook enabled. Once you enabled the nixfmt pre-commit hook, this would happen: 1. You run “pre-commit run --all”. 2. nixfmt gives an error because you used four spaces for indentation instead of two spaces for indentation. 3. You switch to using two spaces for indentation. 4. You run “pre-commit run --all” again. 5. editorconfig-checker gives an error because you used two spaces for indentation instead of four spaces for indentation. 6. You switch to using four spaces for indentation. 7. You run “pre-commit run --all” again. 8. nixfmt gives an error because you used four spaces for indentation instead of two spaces for indentation. 9. You switch to using four spaces for indentation. 10… In order to fix that infinite loop, this commit updates the standard EditorConfig file so that it uses two spaces for indentation in Nix files. There are two alternatives that I considered before ultimately deciding on changing the EditorConfig file to use two spaces for indentation in Nix files. First, I considered figuring out how to make nixfmt use four spaces for indentation instead of two spaces for indentation. I decided that it would be better to follow the same style guide that the Nix ecosystem project uses. Second, I considered using two spaces for indentation everywhere instead of sometimes using two spaces and sometimes using four spaces. Unfortunately, that wouldn’t work for Markdown files. In certain situations, the CommonMark spec requires that you use four or more spaces for indentation [1]. I could have used two spaces for indentation everywhere else and made an exception for Markdown files, but that seemed more disruptive than simply making an exception for Nix files. Plus, I might have also had to make an exception for Python files since Python’s style guide says to use four spaces for indentation [2]. [1]: [2]: --- jasons_pre_commit_hooks/editor_config.ini | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jasons_pre_commit_hooks/editor_config.ini b/jasons_pre_commit_hooks/editor_config.ini index 9c65baa..6b85e9a 100644 --- a/jasons_pre_commit_hooks/editor_config.ini +++ b/jasons_pre_commit_hooks/editor_config.ini @@ -222,3 +222,12 @@ insert_final_newline = true # [4]: # editorconfig-checker-enable max_line_length = 72 + +[**.nix] +# I’m only using 2 for Nix files because the Nix ecosystem project +# itself uses 2 spaces for indentation [1]. +# +# editorconfig-checker-disable +# [1]: +# editorconfig-checker-enable +indent_size = 2