blob: 69e746bd9493c013be26cabc6b33d012be3cc85f [file] [log] [blame] [view]
brettwf0e606a52016-07-06 21:17:201# Chromium coding style
2
3## Main style guides
4
5 * [Chromium C++ style guide](c++/c++.md)
6 * [Google Objective-C style guide](https://google.github.io/styleguide/objcguide.xml)
7 * [Java style guide for Android](https://sites.google.com/a/chromium.org/dev/developers/coding-style/java)
brettw196290a2016-07-07 03:52:168 * [GN style guide](../tools/gn/docs/style_guide.md) for build files
brettwf0e606a52016-07-06 21:17:209
10Chromium also uses these languages to a lesser degree:
11
12 * [Kernel C style](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodingStyle?id=refs/heads/master) for ChromiumOS firmware.
13 * [IDL](https://sites.google.com/a/chromium.org/dev/blink/webidl#TOC-Style)
14 * [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.
15
16## Python
17
18Python code should follow [PEP-8](https://www.python.org/dev/peps/pep-0008/),
19except:
20
21 * Use two-space indentation instead of four-space indentation.
asargent6b84bda82016-07-15 19:59:3822 * Use `CamelCase()` method and function names instead of `unix_hacker_style()` names.
23
brettwf0e606a52016-07-06 21:17:2024(The rationale for these is mostly legacy: the code was originally written
25following Google's internal style guideline, the cost of updating all of the
26code to PEP-8 compliance was not small, and consistency was seen to be a
27greater virtue than compliance.)
28
29[Depot tools](http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools.html)
30contains a local copy of pylint, appropriately configured.
31
32Note that asserts are of limited use, and should not be used for validating
33input – throw an exception instead. Asserts can be used for validating program
34logic, especially use of interfaces or invariants (e.g., asserting that a
35function is only called with dictionaries that contain a certain key). [See
36Using Assertions
37Effectively](https://wiki.python.org/moin/UsingAssertionsEffectively).
38
39See also the [Chromium OS Python Style
40Guidelines](https://sites.google.com/a/chromium.org/dev/chromium-os/python-style-guidelines).
41
42## Web languages (JavaScript, HTML, CSS)
43
44When 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.
45
46Internal uses of web languages, notably "layout" tests, should preferably follow these style guides, but it is not enforced.