Skip to content

Commit 77eecb3

Browse files
committed
Add a pre-commit configuration file
Close #141
1 parent 12c2891 commit 77eecb3

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- id: gdscript-formatter
2+
name: GDScript Formatter
3+
description: Format GDScript files with gdscript-formatter
4+
entry: gdscript-formatter --safe
5+
language: unsupported
6+
files: \.gd$

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ It will print the files that need to be formatted.
7979

8080
To see other possible options, run `gdscript-formatter --help`.
8181

82+
83+
## Using editorconfig
84+
8285
You can also configure the formatter with an [EditorConfig](https://editorconfig.org/) file at the root of your project. This is a good way to share the same formatting settings with your whole team. The formatter supports the standard keys `indent_style`, `indent_size`, `max_line_length`, `insert_final_newline`, and `trim_trailing_whitespace`, plus custom keys prefixed with `gdscript_formatter_`. See the [GDScript Formatter docs](https://www.gdquest.com/library/gdscript_formatter/) for the complete list. Note that command line flags override `.editorconfig` values.
8386

8487
Use `--quote-style preserve/single/double` to automatically normalize the string quote style. You can also set the style in your `.editorconfig` file using the key `gdscript_formatter_quote_style`. The default value, `preserve`, leaves existing quotes unchanged.
@@ -92,6 +95,24 @@ gdscript_formatter_format_on_save = true
9295

9396
Use this to force everyone in your team to format their GDScript files on save.
9497

98+
99+
## Formatting automatically on commit with pre-commit
100+
101+
You can run the formatter automatically before each commit with a version control hook. If your team uses the pre-commit framework, you can add the formatter hook to your project's `.pre-commit-config.yaml` configuration file:
102+
103+
```yaml
104+
repos:
105+
- repo: https://github.com/GDQuest/GDScript-formatter
106+
rev: 0.21.0 # use the tag of the version you want to use
107+
hooks:
108+
- id: gdscript-formatter
109+
```
110+
111+
See the [formatter documentation](http://gdquest.com/library/gdscript_formatter#formatting-automatically-on-commit) for some more detailed information on this.
112+
113+
114+
## Keeping a section of code as-is
115+
95116
To keep a section of code exactly as you wrote it, wrap it between `# fmt: off` and `# fmt: on` comments. This is especially useful when you want to keep values aligned or arranged in a specific way when long data structures:
96117

97118
```gdscript

0 commit comments

Comments
 (0)