Skip to content

Commit 476396a

Browse files
committed
add catch-dotenv hook to README and improve test clarity
1 parent 3e8b0c9 commit 476396a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Require literal syntax when initializing empty or zero Python builtin types.
4242
- Ignore this requirement for specific builtin types with `--ignore=type1,type2,…`.
4343
- Forbid `dict` keyword syntax with `--no-allow-dict-kwargs`.
4444

45+
#### `catch-dotenv`
46+
Prevents committing `.env` files to version control and optionally generates `.env.example` files.
47+
- Use `--create-example` to generate a `.env.example` file with variable names but no values.
48+
- Automatically adds `.env` to `.gitignore` if not already present.
49+
- Helps prevent accidental exposure of secrets and sensitive configuration.
50+
4551
#### `check-case-conflict`
4652
Check for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT.
4753

pre_commit_hooks/catch_dotenv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _read_gitignore(gitignore_file: str) -> tuple[str, list[str]]:
5757
file=sys.stderr,
5858
)
5959
raise
60-
return original_text if lines else '', lines
60+
return original_text, lines
6161

6262

6363
def _normalize_gitignore_lines(

tests/catch_dotenv_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_gitignore_with_existing_content_preserved(
9595
g = tmp_path / DEFAULT_GITIGNORE_FILE
9696
g.write_text(
9797
'node_modules/\n# comment line\n',
98-
) # no trailing newline section markers
98+
) # existing content with trailing newline
9999
run_hook(tmp_path, [DEFAULT_ENV_FILE])
100100
lines = g.read_text().splitlines()
101101
# original content should still be at top
@@ -372,7 +372,7 @@ def test_subdirectory_invocation(
372372
os.chdir(sub)
373373
try:
374374
ret = main(
375-
['../' + DEFAULT_ENV_FILE],
375+
[str(Path('..') / DEFAULT_ENV_FILE)],
376376
) # staged path relative to subdir
377377
gi = (sub / DEFAULT_GITIGNORE_FILE).read_text().splitlines()
378378
finally:

0 commit comments

Comments
 (0)