Debian Codegraph @

doc/style.rst

raw
1 .. Copyright (c) 2016-2026 The Regents of the University of Michigan
2 .. Part of GSD, released under the BSD 2-Clause License.
3
4 Code style
5 ==========
6
7 All code in GSD must follow a consistent style to ensure readability. We provide configuration files
8 for linters (specified below) so that developers can automatically validate and format files.
9
10 These tools are configured for use with `prek`_ and checks will run on pull requests.
11 Run checks manually with::
12
13 prek run --all-files
14
15 .. _prek: https://prek.j178.dev/
16
17 Python
18 ------
19
20 Python code in GSD should follow `PEP8`_ with the formatting performed by `yapf`_ (configuration in
21 ``setup.cfg``). Code should pass all **flake8** tests and formatted by **yapf**.
22
23 .. _PEP8: https://www.python.org/dev/peps/pep-0008
24 .. _yapf: https://github.com/google/yapf
25
26 Tools
27 ^^^^^
28
29 * Linter: `flake8 <http://flake8.pycqa.org/en/latest/>`_
30
31 * With these plugins:
32
33 * `pep8-naming <https://github.com/PyCQA/pep8-naming>`_
34 * `flake8-docstrings <https://gitlab.com/pycqa/flake8-docstrings>`_
35 * `flake8-rst-docstrings <https://github.com/peterjc/flake8-rst-docstrings>`_
36
37 * Configure flake8 in your editor to see violations on save.
38
39 * Autoformatter: `yapf <https://github.com/google/yapf>`_
40
41 Documentation
42 ^^^^^^^^^^^^^
43
44 Python code should be documented with docstrings and added to the Sphinx documentation index in
45 ``doc/``. Docstrings should follow `Google style`_ formatting for use in `Napoleon`_.
46
47 .. _Google Style: https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html#example-google
48 .. _Napoleon: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
49
50 C
51 ---
52
53 * Style is set by clang-format
54
55 * Whitesmith's indentation style.
56 * 100 character line width.
57 * Indent only with spaces.
58 * 4 spaces per indent level.
59 * See :file:`.clang-format` for the full **clang-format** configuration.
60
61 * Naming conventions:
62
63 * Functions: lowercase with words separated by underscores
64 ``function_name``.
65 * Structures: lowercase with words separated by underscores
66 ``struct_name``.
67 * Constants: all upper-case with words separated by underscores
68 ``SOME_CONSTANT``.
69
70 Tools
71 ^^^^^
72
73 * Autoformatter: `clang-format <https://clang.llvm.org/docs/ClangFormat.html>`_.
74
75 * Linter: `clang-tidy <https://clang.llvm.org/extra/clang-tidy/>`_
76
77 * Compile **GSD** with **CMake** to see **clang-tidy** output.
78
79 Documentation
80 ^^^^^^^^^^^^^
81
82 Documentation comments should be in Javadoc format and precede the item they document for
83 compatibility with Doxygen and most source code editors. Multi-line documentation comment blocks
84 start with ``/**`` and single line ones start with ``///``.
85
86 See :file:`gsd.h` for an example.
87
88 Restructured Text/Markdown files
89 --------------------------------
90
91 * 80 character line width.
92 * Use spaces to indent.
93 * Indentation levels are set by the respective formats.
94
95 Other file types
96 ----------------
97
98 Use your best judgment and follow existing patterns when styling CMake and other files types. The
99 following general guidelines apply:
100
101 * 100 character line width.
102 * 4 spaces per indent level.
103 * 4 space indent.
104
105 Editor configuration
106 --------------------
107
108 `Visual Studio Code <https://code.visualstudio.com/>`_ users: Open the provided workspace file
109 (``gsd.code-workspace``) which provides configuration settings for these style guidelines.