diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/docs/clang_format.md | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/docs/clang_format.md')
-rw-r--r-- | chromium/docs/clang_format.md | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/chromium/docs/clang_format.md b/chromium/docs/clang_format.md index 1fa34d076fc..c14eb33ae0d 100644 --- a/chromium/docs/clang_format.md +++ b/chromium/docs/clang_format.md @@ -1,5 +1,7 @@ # Using clang-format on Chromium C++ Code +[TOC] + *** note NOTE: This page does not apply to the Chromium OS project. See [Chromium Issue 878506](https://bugs.chromium.org/p/chromium/issues/detail?id=878506#c10) @@ -9,15 +11,16 @@ for updates. ## Easiest usage, from the command line To automatically format a pending patch according to -[Chromium style](https://www.chromium.org/developers/coding-style), from -the command line, simply run: ``` git cl format ``` This should work on all -platforms _(yes, even Windows)_ without any set up or configuration: the tool -comes with your checkout. Like other `git-cl` commands, this operates on a diff -relative to the upstream branch. Only the lines that you've already touched in -your patch will be reformatted. You can commit your changes to your git branch -and then run `git cl format`, after which `git diff` will show you what -clang-format changed. Alternatively, you can run `git cl format` with your -changes uncommitted, and then commit your now-formatted code. +[Chromium style](https://www.chromium.org/developers/coding-style), run: +``` git cl format ``` from the command line. This should work on all platforms +without any extra set up: the tool is integrated with depot_tools and the +Chromium checkout. + +Like other `git-cl` commands, this operates on a diff relative to the upstream +branch. Only the lines that changed in a CL will be reformatted. To see what +clang-format would choose, commit any local changes and then run `git cl +format` followed by `git diff`. Alternatively, run `git cl format` and commit +the now-formatted code. ## Editor integrations @@ -44,27 +47,36 @@ For further guidance on editor integration, see these specific pages: * For vim, `:so tools/vim/clang-format.vim` and then hit cmd-shift-i (mac) ctrl-shift-i (elsewhere) to indent the current line or current selection. -## Are robots taking over my freedom to choose where newlines go? - -No. For the project as a whole, using clang-format is just one optional way to -format your code. While it will produce style-guide conformant code, other -formattings would also satisfy the style guide, and all are okay. - -Having said that, many clang-format converts have found that relying on a tool -saves both them and their reviewers time. The saved time can then be used to -discover functional defects in their patch, to address style/readability -concerns whose resolution can't be automated, or to do something else that -matters. - -In directories where most contributors have already adopted clang-format, and -code is already consistent with what clang-format would produce, some teams -intend to experiment with standardizing on clang-format. When these local -standards apply, it will be enforced by a PRESUBMIT.py check. - ## Reporting problems If clang-format is broken, or produces badly formatted code, please file a -[bug]. Assign it to thakis@chromium.org who will route it upstream. +[bug]. Assign it to thakis@chromium.org or dcheng@chromium.org, who will route +it upstream. [bug]: https://code.google.com/p/chromium/issues/entry?comment=clang-format%20produced%20code%20that%20(choose%20all%20that%20apply):%20%0A-%20Doesn%27t%20match%20Chromium%20style%0A-%20Doesn%27t%20match%20blink%20style%0A-%20Riles%20my%20finely%20honed%20stylistic%20dander%0A-%20No%20sane%20human%20would%20ever%20choose%0A%0AHere%27s%20the%20code%20before%20formatting:%0A%0A%0AHere%27s%20the%20code%20after%20formatting:%0A%0A%0AHere%27s%20how%20it%20ought%20to%20look:%0A%0A%0ACode%20review%20link%20for%20full%20files/context:&summary=clang-format%20quality%20problem&cc=thakis@chromium.org&labels=Type-Bug,Build-Tools,OS-?,clang-format + +## Are robots taking over my freedom to choose where newlines go? + +Mostly. At upload time, a presubmit check warns if a CL is not clang-formatted, +but this is a non-blocking warning, and the CL may still be submitted. Even so, +try to prefer clang-format's output when possible: + +- While clang-format does not necessarily format code the exact same way a human + might choose, it produces style-conformat code by design. This can allow + development and review time to be focused on discovering functional defects, + addressing readability/understandability concerns that can't be automatically + fixed by tooling, et cetera. +- Continually fighting the tooling is a losing battle. Most Chromium developers + use clang-format. Large-scale changes will simply run `git cl format` once to + avoid having to deal with the particulars of formatting. Over time, this will + likely undo any carefully-curated manual formatting of the affected lines. + +There is one notable exception where clang-format is often disabled: large +tables of data are often surrounded by `// clang-format off` and `// +clang-format on`. Try to use this option sparingly, as widespread usage makes +tool-assisted refactoring more difficult. + +Again, if clang-format produces something odd, please err on the side of +[reporting an issue](#Reporting-problems): bugs that aren't reported can't be +fixed. |