From f6651d58d0a8a241045c91100de1f325c61dc530 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 3 Apr 2022 13:49:06 +0200
Subject: [PATCH] Move style guide to repo
---
doc/dev/style-guide.rst | 75 +++++++++++++++++++++++++++++++++++++++++
doc/index.rst | 1 +
2 files changed, 76 insertions(+)
create mode 100644 doc/dev/style-guide.rst
diff --git a/doc/dev/style-guide.rst b/doc/dev/style-guide.rst
new file mode 100644
index 00000000..817b7410
--- /dev/null
+++ b/doc/dev/style-guide.rst
@@ -0,0 +1,75 @@
+Style Guide
+===========
+
+There is a ``.editorconfig`` and a ``.clang-format`` file in the project root
+that defines some basic guidelines, mainly relating to indentation.
+
+Code Formatting
+---------------
+
+We use ``clang-format`` for code formatting, the style rules are defined in
+``.clang-format``, before submitting a PR, make sure to run the following command
+on all the C++ files you changed:
+
+.. code-block:: bash
+
+ clang-format -style=file -i
+
+**Note:** Depending on which file you change, this may produce a lot of changes
+because we have not run ``clang-format`` on all files in the project. This is
+fine.
+
+Indentation
+~~~~~~~~~~~
+
+Files use 2 spaces for indentation.
+
+Line Width
+~~~~~~~~~~
+
+Lines should not be longer than 120 characters, ``clang-format`` will enforce
+this when run. However, try to keep lines under 80 characters if it seems
+reasonable in the current situation.
+
+In some cases it makes sense to have lines longer than 80 characters for
+readability. But long lines can just the same be unreadable, for example if you
+have long if-conditions or use complex expressions as function parameters. Make
+sure you only use longer lines if keeping it under 80 would be less readable.
+
+Comments
+--------
+
+Use Doxygen ``/** */`` comments in front of functions, methods, types, members and
+classes:
+
+.. code-block:: cpp
+
+ /**
+ * @brief Generates a config object from a config file
+ *
+ * For modularity the parsing and storing of the config is separated
+ */
+ class config_parser {
+ ...
+ /**
+ * @brief Is used to resolve ${root...} references
+ */
+ string m_barname;
+ ...
+ }
+
+For all other comments use ``//`` for single-line and ``/* */`` for multi-line comments.
+
+Your comments should describe the intent and purpose of your code, not necessarily what it does.
+
+Header Files
+------------
+
+Header files should end in ``.hpp``.
+
+We use pragmas instead of include guards to guarantee header files are included
+only once:
+
+.. code-block:: cpp
+
+ #pragma once
diff --git a/doc/index.rst b/doc/index.rst
index b7ca5773..08502f18 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -33,6 +33,7 @@ Welcome to the official polybar documentation.
:maxdepth: 1
:caption: Developer Documentation:
+ dev/style-guide
dev/release-workflow
Getting Help