Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I5G96F Test: Test262 suit, ark unittest, rk3568 XTS, ark previewer demo Signed-off-by: huangyu <huangyu76@huawei.com> Change-Id: I3f63d129a07deaa27a390f556dcaa5651c098185
2.3 KiB
CodeStyle
Our CodeStyle based on google code style (you can get google config like this: clang-format -dump-config -style=Google
).
But we have some modifications:
-
Indent: spaces 4. Line length: 120.
-
Delete spaces before public/private/protected.
-
All constants in UPPERCASE.
-
Enums in uppercase Example:
enum ShootingHand { LEFT, RIGHT };
-
Unix/Linux line ending for all files.
-
Same parameter names in Method definitions and declarations.
-
No
k
prefix in constant names. -
No one-line if-clauses:
if (x == kFoo) return new Foo();
-
Do not use special naming for getters/setters (google allows this:
int count() and void set_count(int count))
-
Always explicitly mark fall through in switch … case. Google uses its own macro, we can agree on /* fallthrough */.
switch (x) { case 41: // No annotation needed here. case 43: if (dont_be_picky) { // Use this instead of or along with annotations in comments. /* fallthrough */ } else { CloseButNoCigar(); break; } case 42: DoSomethingSpecial(); /* fallthrough */ default: DoSomethingGeneric(); break; }
-
When a return statement is unreachable, but the language syntax requires it, mark it with something like return nullptr; /* unreachable */, or define UNREACHABLE as assert(0 && "Unreachable") and insert it before such return
-
Use standard notices in comments (e.g. TODO:, NB!, no FIXME: allowed).
-
Use standard flowerbox comments at the top of headers and translation units (agree on the format). Temporary you can use this:
/**
- Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
*/
-
switch and case on the same level For example:
switch (ch) { case ‘A’: ... }
-
Always put { } even if the body is one line: For example
if (foo) { return 5; }
-
Use
maybe_unused
attribute for unused vars/arguments.int foo3([[maybe_unused]] int bar) { // ... }
We are using clang-format and clang-tidy to check code style.