Skip to content

Commit

Permalink
Add new documentation about the pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kaixin-hc committed Mar 13, 2024
1 parent f47a505 commit 31680e2
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions contributing/development/code_style_guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,39 @@ set up clang-format locally to check and automatically fix all your commits.
These guidelines only cover code formatting. See :ref:`doc_cpp_usage_guidelines`
for a list of language features that are permitted in pull requests.


Using clang-format locally
~~~~~~~~~~~~~~~~~~~~~~~~~~

First of all, you will need to install clang-format. As of now, you need to use
**clang-format 13** to be compatible with Godot's format. Later versions might
You need to use **clang-format 13** to be compatible with Godot's format (the
precommit hook downloads the correct dependency). Later versions might
be suitable, but previous versions may not support all used options, or format
some things differently, leading to style issues in pull requests.

Pre-commit hook
^^^^^^^^^^^^^^^

For ease of use, we provide hooks for Git with the `pre-commit <https://pre-commit.com/>`__
Python framework that will run clang-format automatically on all your commits with the
correct version of clang-format.
To set up:

::

pip install pre-commit
pre-commit install


You can also run the hook manually with ``pre-commit run``.

.. NOTE::

Previously, we supplied a hook in the folder ``misc/hooks``. If you copied the
script manually, these hooks should still work, but symlinks will be broken.
If you are using the new system, run ``rm .git/hooks/*`` to remove the old hooks
that are no longer needed.


Installation
^^^^^^^^^^^^

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

Pre-commit hook
^^^^^^^^^^^^^^^

For ease of use, we provide a pre-commit hook for Git that will run
clang-format automatically on all your commits to check them, and let you apply
its changes in the final commit.

This "hook" is a script that can be found in ``misc/hooks``, refer to that
folder's README.md for installation instructions.

If your clang-format is not in the ``PATH``, you may have to edit the
``pre-commit-clang-format`` to point to the correct binary for it to work.
The hook was tested on Linux and macOS, but should also work in the Git Shell
on Windows.

IDE plugin
^^^^^^^^^^
Expand Down Expand Up @@ -292,15 +303,29 @@ command:
- The path can point to several files, either one after the other or using
wildcards like in a typical Unix shell.


Pre-commit hook
^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~

For ease of use, we provide hooks for Git with the `pre-commit <https://pre-commit.com/>`__
Python framework that will run black automatically on all your commits with the
correct version of black.
To set up:

::

pip install pre-commit
pre-commit install


You can also run the hook manually with ``pre-commit run``.

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

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


Editor integration
Expand Down

0 comments on commit 31680e2

Please sign in to comment.