aboutsummaryrefslogtreecommitdiff
path: root/docs/contributing.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/contributing.md')
-rw-r--r--docs/contributing.md58
1 files changed, 3 insertions, 55 deletions
diff --git a/docs/contributing.md b/docs/contributing.md
index 7d1a9691c..761bc9959 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -54,62 +54,10 @@ Never made an open source contribution before? Wondering how contributions work
54 54
55# Coding Conventions 55# Coding Conventions
56 56
57Most of our style is pretty easy to pick up on, but right now it's not entirely consistent. You should match the style of the code surrounding your change, but if that code is inconsistent or unclear use the following guidelines: 57Most of our style is pretty easy to pick up on. If you are familiar with either C or Python you should not have too much trouble with our local styles.
58
59* We indent using four (4) spaces (soft tabs)
60* We use a modified One True Brace Style
61 * Opening Brace: At the end of the same line as the statement that opens the block
62 * Closing Brace: Lined up with the first character of the statement that opens the block
63 * Else If: Place the closing brace at the beginning of the line and the next opening brace at the end of the same line.
64 * Optional Braces: Always include optional braces.
65 * Good: if (condition) { return false; }
66 * Bad: if (condition) return false;
67* We encourage use of C style comments: `/* */`
68 * Think of them as a story describing the feature
69 * Use them liberally to explain why particular decisions were made.
70 * Do not write obvious comments
71 * If you not sure if a comment is obvious, go ahead and include it.
72* In general we don't wrap lines, they can be as long as needed. If you do choose to wrap lines please do not wrap any wider than 76 columns.
73* We use `#pragma once` at the start of header files rather than old-style include guards (`#ifndef THIS_FILE_H`, `#define THIS_FILE_H`, ..., `#endif`)
74* We accept both forms of preprocessor if's: `#ifdef DEFINED` and `#if defined(DEFINED)`
75 * If you are not sure which to prefer use the `#if defined(DEFINED)` form.
76 * Do not change existing code from one style to the other, except when moving to a multiple condition `#if`.
77 * Do not put whitespace between `#` and `if`.
78 * When deciding how (or if) to indent directives keep these points in mind:
79 * Readability is more important than consistency.
80 * Follow the file's existing style. If the file is mixed follow the style that makes sense for the section you are modifying.
81 * When choosing to indent you can follow the indention level of the surrounding C code, or preprocessor directives can have their own indent level. Choose the style that best communicates the intent of your code.
82
83Here is an example for easy reference:
84 58
85```c 59* [Coding Conventions - C](coding_conventions_c.md)
86/* Enums for foo */ 60* [Coding Conventions - Python](coding_conventions_python.md)
87enum foo_state {
88 FOO_BAR,
89 FOO_BAZ,
90};
91
92/* Returns a value */
93int foo(void) {
94 if (some_condition) {
95 return FOO_BAR;
96 } else {
97 return -1;
98 }
99}
100```
101
102# Auto-formatting with clang-format
103
104[Clang-format](https://clang.llvm.org/docs/ClangFormat.html) is part of LLVM and can automatically format your code for you, because ain't nobody got time to do it manually. We supply a configuration file for it that applies most of the coding conventions listed above. It will only change whitespace and newlines, so you will still have to remember to include optional braces yourself.
105
106Use the [full LLVM installer](http://llvm.org/builds/) to get clang-format on Windows, or use `sudo apt install clang-format` on Ubuntu.
107
108If you run it from the command-line, pass `-style=file` as an option and it will automatically find the .clang-format configuration file in the QMK root directory.
109
110If you use VSCode, the standard C/C++ plugin supports clang-format, alternatively there is a [separate extension](https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.ClangFormat) for it.
111
112Some things (like LAYOUT macros) are destroyed by clang-format, so either don't run it on those files, or wrap the sensitive code in `// clang-format off` and `// clang-format on`.
113 61
114# General Guidelines 62# General Guidelines
115 63