File: styleguide.md

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (44 lines) | stat: -rw-r--r-- 2,356 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Chromium coding style

## Main style guides

  * [Chromium C++ style guide](c++/c++.md)
  * [Google Objective-C style guide](https://google.github.io/styleguide/objcguide.xml)
  * [Java style guide for Android](https://sites.google.com/a/chromium.org/dev/developers/coding-style/java)
  * [GN style guide](../tools/gn/docs/style_guide.md) for build files

Chromium also uses these languages to a lesser degree:

  * [Kernel C style](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodingStyle?id=refs/heads/master) for ChromiumOS firmware.
  * [IDL](https://sites.google.com/a/chromium.org/dev/blink/webidl#TOC-Style)
  * [Jinja style guide](https://sites.google.com/a/chromium.org/dev/developers/jinja#TOC-Style) for [Jinja](https://sites.google.com/a/chromium.org/dev/developers/jinja) templates.

## Python

Python code should follow [PEP-8](https://www.python.org/dev/peps/pep-0008/).

Some existing scripts were originally written following Google's internal
style guideline and have the following two exceptions. New scripts should,
however, be PEP-8 compliant.

  * Use two-space indentation instead of four-space indentation.
  * Use `CamelCase()` method and function names instead of `unix_hacker_style()` names.

[Depot tools](http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools.html)
contains a local copy of pylint, appropriately configured.

Note that asserts are of limited use, and should not be used for validating
input – throw an exception instead. Asserts can be used for validating program
logic, especially use of interfaces or invariants (e.g., asserting that a
function is only called with dictionaries that contain a certain key). [See
Using Assertions
Effectively](https://wiki.python.org/moin/UsingAssertionsEffectively).

See also the [Chromium OS Python Style
Guidelines](https://sites.google.com/a/chromium.org/dev/chromium-os/python-style-guidelines).

## Web languages (JavaScript, HTML, CSS)

When working on Web-based UI features, consult the [Web Development Style Guide](https://sites.google.com/a/chromium.org/dev/developers/web-development-style-guide) for the Chromium conventions used in JS/CSS/HTML files.

Internal uses of web languages, notably "layout" tests, should preferably follow these style guides, but it is not enforced.