Skip to content

Commit 29de6ef

Browse files
Merge pull request #9094 from kaixin-hc/update_pre-commit
Add new documentation about the pre-commit hook
2 parents cd337a0 + 54e795a commit 29de6ef

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

contributing/development/code_style_guidelines.rst

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,38 @@ set up clang-format locally to check and automatically fix all your commits.
5353
These guidelines only cover code formatting. See :ref:`doc_cpp_usage_guidelines`
5454
for a list of language features that are permitted in pull requests.
5555

56+
5657
Using clang-format locally
5758
~~~~~~~~~~~~~~~~~~~~~~~~~~
5859

59-
First of all, you will need to install clang-format. As of now, you need to use
60-
**clang-format 13** to be compatible with Godot's format. Later versions might
60+
You need to use **clang-format 17** to be compatible with Godot's format. Later versions might
6161
be suitable, but previous versions may not support all used options, or format
6262
some things differently, leading to style issues in pull requests.
6363

64+
Pre-commit hook
65+
^^^^^^^^^^^^^^^
66+
67+
For ease of use, we provide hooks for Git with the `pre-commit <https://pre-commit.com/>`__
68+
Python framework that will run clang-format automatically on all your commits with the
69+
correct version of clang-format.
70+
To set up:
71+
72+
::
73+
74+
pip install pre-commit
75+
pre-commit install
76+
77+
78+
You can also run the hook manually with ``pre-commit run``.
79+
80+
.. note::
81+
82+
Previously, we supplied a hook in the folder ``misc/hooks``. If you copied the
83+
script manually, these hooks should still work, but symlinks will be broken.
84+
If you are using the new system, run ``rm .git/hooks/*`` to remove the old hooks
85+
that are no longer needed.
86+
87+
6488
Installation
6589
^^^^^^^^^^^^
6690

@@ -74,7 +98,7 @@ Here's how to install clang-format:
7498
- macOS and Windows: You can download precompiled binaries from the
7599
`LLVM website <https://releases.llvm.org/download.html>`__. You may need to add
76100
the path to the binary's folder to your system's ``PATH`` environment
77-
variable to be able to call ``clang-format`` out of the box.
101+
variable to be able to call clang-format out of the box.
78102

79103
You then have different possibilities to apply clang-format to your changes:
80104

@@ -95,20 +119,6 @@ command:
95119
you don't run clang-format on compiled objects (.o and .a files) that are
96120
in Godot's tree. So better use ``core/*.{cpp,h}`` than ``core/*``.
97121

98-
Pre-commit hook
99-
^^^^^^^^^^^^^^^
100-
101-
For ease of use, we provide a pre-commit hook for Git that will run
102-
clang-format automatically on all your commits to check them, and let you apply
103-
its changes in the final commit.
104-
105-
This "hook" is a script that can be found in ``misc/hooks``, refer to that
106-
folder's README.md for installation instructions.
107-
108-
If your clang-format is not in the ``PATH``, you may have to edit the
109-
``pre-commit-clang-format`` to point to the correct binary for it to work.
110-
The hook was tested on Linux and macOS, but should also work in the Git Shell
111-
on Windows.
112122

113123
IDE plugin
114124
^^^^^^^^^^
@@ -292,15 +302,29 @@ command:
292302
- The path can point to several files, either one after the other or using
293303
wildcards like in a typical Unix shell.
294304

305+
295306
Pre-commit hook
296-
^^^^^^^^^^^^^^^
307+
~~~~~~~~~~~~~~~
308+
309+
For ease of use, we provide hooks for Git with the `pre-commit <https://pre-commit.com/>`__
310+
Python framework that will run ``black`` automatically on all your commits with the
311+
correct version of ``black``.
312+
To set up:
313+
314+
::
315+
316+
pip install pre-commit
317+
pre-commit install
318+
319+
320+
You can also run the hook manually with ``pre-commit run``.
297321

298-
For ease of use, we provide a pre-commit hook for Git that will run
299-
black automatically on all your commits to check them, and let you apply
300-
its changes in the final commit.
322+
.. note::
301323

302-
This "hook" is a script which can be found in ``misc/hooks``. Refer to that
303-
folder's ``README.md`` for installation instructions.
324+
Previously, we supplied a hook in the folder ``misc/hooks``. If you copied the
325+
script manually, these hooks should still work, but symlinks will be broken.
326+
If you are using the new system, run ``rm .git/hooks/*`` to remove the old hooks
327+
that are no longer needed.
304328

305329

306330
Editor integration

0 commit comments

Comments
 (0)