webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
Indentation

[](#indentation-no-tabs) Use spaces, not tabs. Tabs should only appear in files that require them for semantic meaning, like Makefiles.

[](#indentation-4-spaces) The indent size is 4 spaces.

Right:
int main()
{
return 0;
}
Wrong:
int main()
{
return 0;
}

[](#indentation-namespace) The contents of an outermost namespace block (and any nested namespaces with the same scope) should not be indented. The contents of other nested namespaces should be indented.

Right:
// Document.h
namespace WebCore {
class Document {
...
};
namespace NestedNamespace {
...
}
} // namespace WebCore
// Document.cpp
namespace WebCore {
{
...
}
} // namespace WebCore
Wrong:
// Document.h
namespace WebCore {
class Document {
...
};
namespace NestedNamespace {
...
}
} // namespace WebCore
// Document.cpp
namespace WebCore {
{
...
}
} // namespace WebCore

[](#indentation-case-label) A case label should line up with its switch statement. The case statement is indented.

Right:
switch (condition) {
case fooCondition:
case barCondition:
i++;
break;
default:
i--;
}
Wrong:
switch (condition) {
case fooCondition:
case barCondition:
i++;
break;
default:
i--;
}

[](#indentation-wrap-bool-op) Boolean expressions at the same nesting level that span multiple lines should have their operators on the left side of the line instead of the right side.

Right:
return attribute.name() == srcAttr
|| attribute.name() == lowsrcAttr
|| (attribute.name() == usemapAttr && attribute.value().string()[0] != '#');
Wrong:
return attribute.name() == srcAttr ||
attribute.name() == lowsrcAttr ||
(attribute.name() == usemapAttr && attr->value().string()[0] != '#');

Spacing

[](#spacing-unary-op) Do not place spaces around unary operators.

Right:
i++;
Wrong:
i ++;

[](#spacing-binary-ternary-op) Do place spaces around binary and ternary operators.

Right:
y = m * x + b;
f(a, b);
c = a | b;
return condition ? 1 : 0;
Wrong:
y=m*x+b;
f(a,b);
c = a|b;
return condition ? 1:0;

[](#spacing-for-colon) Place spaces around the colon in a range-based for loop.

Right:
Vector<PluginModuleInfo> plugins;
for (auto& plugin : plugins)
registerPlugin(plugin);
Wrong:
Vector<PluginModuleInfo> plugins;
for (auto& plugin: plugins)
registerPlugin(plugin);

[](#spacing-comma-semicolon) Do not place spaces before comma and semicolon.

Right:
for (int i = 0; i < 10; ++i)
doSomething();
f(a, b);
Wrong:
for (int i = 0 ; i < 10 ; ++i)
doSomething();
f(a , b) ;

[](#spacing-control-paren) Place spaces between control statements and their parentheses.

Right:
doIt();
Wrong:
doIt();

[](#spacing-function-paren) Do not place spaces between a function and its parentheses, or between a parenthesis and its content.

Right:
f(a, b);
Wrong:
f (a, b);
f( a, b );

Line breaking

[](#linebreaking-multiple-statements) Each statement should get its own line.

Right:
x++;
y++;
doIt();
Wrong:
x++; y++;
if (condition) doIt();

[](#linebreaking-else-braces) An else statement should go on the same line as a preceding close brace if one is present, else it should line up with the if statement.

Right:
if (condition) {
...
} else {
...
}
doSomething();
else
doSomethingElse();
doSomething();
else {
...
}
Wrong:
if (condition) {
...
}
else {
...
}
if (condition) doSomething(); else doSomethingElse();
if (condition) doSomething(); else {
...
}

[](#linebreaking-else-if) An else if statement should be written as an if statement when the prior if concludes with a return statement.

Right:
if (condition) {
...
return someValue;
}
if (condition) {
...
}
Wrong:
if (condition) {
...
return someValue;
} else if (condition) {
...
}

Braces

[](#braces-function) Function definitions: place each brace on its own line.

Right:
int main()
{
...
}
Wrong:
int main() {
...
}

[](#braces-blocks) Other braces: place the open brace on the line preceding the code block; place the close brace on its own line.

Right:
class MyClass {
...
};
namespace WebCore {
...
}
for (int i = 0; i < 10; ++i) {
...
}
Wrong:
class MyClass
{
...
};

[](#braces-one-line) One-line control clauses should not use braces unless comments are included or a single statement spans multiple lines.

Right:
doIt();
if (condition) {
// Some comment
doIt();
}
if (condition) {
myFunction(reallyLongParam1, reallyLongParam2, ...
reallyLongParam5);
}
Wrong:
if (condition) {
doIt();
}
// Some comment
doIt();
myFunction(reallyLongParam1, reallyLongParam2, ...
reallyLongParam5);

[](#braces-empty-block) Control clauses without a body should use empty braces:

Right:
for ( ; current; current = current->next) { }
Wrong:
for ( ; current; current = current->next);

Null, false and zero

[](#zero-null) In C++, the null pointer value should be written as nullptr. In C, it should be written as NULL. In Objective-C and Objective-C++, follow the guideline for C or C++, respectively, but use nil to represent a null Objective-C object.

[](#zero-bool) C++ and C bool values should be written as true and false. Objective-C BOOL values should be written as YES and NO.

[](#zero-comparison) Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.

Right:
doIt();
if (!ptr)
return;
if (!count)
return;
Wrong:
if (condition == true)
doIt();
if (ptr == NULL)
return;
if (count == 0)
return;

[](#zero-objc-variables) In Objective-C, instance variables are initialized to zero automatically. Don't add explicit initializations to nil or NO in an init method.

Floating point literals

[](#float-suffixes) Unless required in order to force floating point math, do not append .0, .f and .0f to floating point literals.

Right:
const double duration = 60;
void setDiameter(float diameter)
{
radius = diameter / 2;
}
setDiameter(10);
const int framesPerSecond = 12;
double frameDuration = 1.0 / framesPerSecond;
Wrong:
const double duration = 60.0;
void setDiameter(float diameter)
{
radius = diameter / 2.f;
}
setDiameter(10.f);
const int framesPerSecond = 12;
double frameDuration = 1 / framesPerSecond; // integer division

Names

[](names-basic) Use CamelCase. Capitalize the first letter, including all letters in an acronym, in a class, struct, protocol, or namespace name. Lower-case the first letter, including all letters in an acronym, in a variable or function name.

Right:
struct Data;
size_t bufferSize;
String mimeType();
Wrong:
struct data;
size_t buffer_size;
class HtmlDocument;
String MIMEType();

[](names-full-words) Use full words, except in the rare case where an abbreviation would be more canonical and easier to understand.

Right:
size_t characterSize;
size_t length;
short tabIndex; // more canonical
Wrong:
size_t charSize;
size_t len;
short tabulationIndex; // bizarre

[](names-data-members) Data members in C++ classes should be private. Static data members should be prefixed by "s_". Other data members should be prefixed by "m_".

Right:
class String {
public:
...
private:
short m_length;
};
Wrong:
class String {
public:
...
short length;
};

[](names-objc-instance-variables) Prefix Objective-C instance variables with "_".

Right:

```cpp