-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cockpit Coding Guidelines
Stef Walter edited this page Jan 16, 2015
·
15 revisions
- No trailing whitespace, no tab characters, except in Makefile.am files
- Generally line length should be limited to 120 chars
- Gtk+ coding standards
- C99 is allowed and the default.
- When in doubt, check the surrounding code and try to imitate it.
/* Store the code/data payload */
if (len >= 2)
{
pv->peer_close_code = (guint16)data[0] << 8 | data[1];
}
if (len > 2)
{
data += 2;
len -= 2;
if (g_utf8_validate ((gchar *)data, len, NULL))
pv->peer_close_data = g_strndup ((gchar *)data, len);
else
g_message ("received non-UTF8 close data: %d '%.*s' %d", (int)len, (int)len, (gchar *)data, (int)data[0]);
}
- Use private scopes to reduce exposure of variables when they are not relevant to other callers.
- Crockford with lots of exceptions
- Chained calls may be placed on separate lines for readability (see example below)
Variables should be declared outside of loops or condition braces.
{
var demo = 1; /* here */
while(false) {
/* not here */
}
}
Function declarations and invocations should have no space after function name. Function starting brace goes on same line as function
keyword.
function name(arg) {
/* body */
}
Anonymous functions do not need a space between the function
keyword and arguments.
div.onclick = function(e) {
/* body */
}
Control flow keywords such as if
for
and while
should have a space after them. If there is only one statement in a conditional or loop, you may leave out the braces.
while (false)
console.log("never reached");
All binary operators except . (period) and ( (left parenthesis) and [ (left bracket) should be separated from their operands by a space.
/* if an image is older than two days, don't show the time */
var threshold_date = new Date(image.Created * 1000);
threshold_date.setDate(threshold_date.getDate() + 2);
if (threshold_date > (new Date())) {
$(row[1]).text(new Date(image.Created * 1000).toLocaleString());
} else {
var creation_date = new Date(image.Created * 1000);
/* we hide the time, so put full timestamp in the hover text */
$(row[1])
.text(creation_date.toLocaleDateString())
.attr("title", creation_date.toLocaleString());
}
/* Panels don't draw borders between them */
.panel > .table > tbody:first-child td {
border-top: 1px solid rgb(221, 221, 221);
}
/* Table headers should not generate a double border */
.panel .table thead tr th {
border-bottom: none;
}
def run(self, proc, output=""):
# Complete retrieval of the list of tests
output += proc.stdout.read()
proc.wait()
if proc.returncode:
sys.stderr.write("tap-gtester: listing GTest tests failed: %d\n" % proc.returncode)
return proc.returncode
self.test_remaining = []
for line in output.split("\n"):
if line.startswith("/"):
self.test_remaining.append(line.strip())
if not self.test_remaining:
print "Bail out! No tests found in GTest: %s" % self.command[0]
return 0
print "1..%d" % len(self.test_remaining)