Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ gdscript-formatter --check path/to/file.gd

To see other possible options, run `gdscript-formatter` without any arguments.

## Git pre-commit hook

You can run the `gdscript-formatter` automatically on staged `.gd` prior to each commit. This repository includes a pre-commit hook you can copy into your project.

From the root of your project, run:

```sh
cp path/to/GDScript-formatter/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
```

This copies the hook into `.git/hooks/`, where Git looks for hooks to run automatically. Git will now run the formatter on your staged `.gd` files before every commit.

## Linting GDScript files

The formatter also includes a linter that checks for style and convention issues according to the official GDScript style guide.
Expand Down
5 changes: 5 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
staged=$(git diff --cached --name-only --diff-filter=ACM | grep '\.gd$')
[ -z "$staged" ] && exit 0
echo "$staged" | xargs gdscript-formatter
git add $staged