add new brace guidelines and clang-format info (#3414)
Add new brace guidelines, correct code sample. Add detail to indentation guidelines. Add basic clang-format information and a link to the documentation on llvm. closes #3413 A quick edit to the contributing guide from the web ui, hope it comes out right.
This commit is contained in:
parent
75203cf385
commit
986e405ca7
1 changed files with 16 additions and 18 deletions
34
.github/CONTRIBUTING.md
vendored
34
.github/CONTRIBUTING.md
vendored
|
@ -91,35 +91,28 @@ If you find any usage of the old keywords, we encourage you to fix it.
|
||||||
|
|
||||||
### Braces ###
|
### Braces ###
|
||||||
|
|
||||||
Braces should almost always go on their own line:
|
Braces should go on their own line except for control statements, the use of braces around single line statements is preferred.
|
||||||
|
See the following example:
|
||||||
```c++
|
```c++
|
||||||
int main()
|
int main()
|
||||||
{
|
{ // function or class: own line
|
||||||
if (someCondition)
|
if (someCondition) { // control statement: same line
|
||||||
{
|
doSomething(); // single line statement, braces preferred
|
||||||
doSomething();
|
} else if (someOtherCondition1) { // else goes after closing brace
|
||||||
}
|
for (int i = 0; i < 100; i++) {
|
||||||
else if (someOtherCondition1)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 100; i++)
|
|
||||||
{
|
|
||||||
doSomethingElse();
|
doSomethingElse();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
while (someOtherCondition2) {
|
||||||
{
|
|
||||||
while (someOtherCondition2)
|
|
||||||
{
|
|
||||||
doSomethingElse();
|
doSomethingElse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Braces should never be omitted for single-statement. Keeping the code legibile is a high priority of ours and we hope you share a similar belief :)
|
|
||||||
|
|
||||||
### Tabs vs Spaces ###
|
### Indentation ###
|
||||||
|
|
||||||
We _highly_ encourate the use of spaces. If you use tabs, please readjust them to 4 spaces per tab before submitting.
|
Always indent using 4 spaces, do not use tabs. Opening and closing braces should be on the same indentation layer, member access specifiers in classes or structs should not be indented.
|
||||||
|
|
||||||
### Lines ###
|
### Lines ###
|
||||||
|
|
||||||
|
@ -127,6 +120,11 @@ Do not have trailing whitespace in your lines, if possible. Most IDEs check for
|
||||||
|
|
||||||
Lines should be 120 characters or less, but you can exceed this if you find it necessary.
|
Lines should be 120 characters or less, but you can exceed this if you find it necessary.
|
||||||
|
|
||||||
|
### Automatic Formatting ###
|
||||||
|
|
||||||
|
The handy tool `clang-format` can format your code for you, a special `.clang-format` configuration file is included [here](https://github.com/Cockatrice/Cockatrice/blob/master/.clang-format).
|
||||||
|
See [the clang-format documentation](https://clang.llvm.org/docs/ClangFormat.html) for more information.
|
||||||
|
|
||||||
### Memory Management ###
|
### Memory Management ###
|
||||||
|
|
||||||
New code should be written using references over pointers and stack allocation
|
New code should be written using references over pointers and stack allocation
|
||||||
|
|
Loading…
Reference in a new issue