diff options
author | Jeremy Lin <jjlin@users.noreply.github.com> | 2022-10-04 00:19:21 -0700 |
---|---|---|
committer | Jeremy Lin <jjlin@users.noreply.github.com> | 2022-10-04 00:19:21 -0700 |
commit | 77208f1e89d9a826ac69522426a570bbd61f5068 (patch) | |
tree | 464c7dba5a2b5baf82872df073e1d438029dc40a /docs | |
parent | 05c9e1f137fb62ab927060125c87b41e5a02ecb4 (diff) |
[docs] add some clarifications on code formatting
Diffstat (limited to 'docs')
-rw-r--r-- | docs/CODE_GUIDELINES.md | 10 | ||||
-rw-r--r-- | docs/CONTRIBUTING.md | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/docs/CODE_GUIDELINES.md b/docs/CODE_GUIDELINES.md index 6ea0b0cb2a..57b3ed7941 100644 --- a/docs/CODE_GUIDELINES.md +++ b/docs/CODE_GUIDELINES.md @@ -60,9 +60,11 @@ ## 1. Motivation When working in a large group, the two most important values are readability and maintainability. We code for other people, not computers. To accomplish these goals, we have created a unified set of code conventions. -Conventions can be bent or broken in the interest of making code more readable and maintainable. However, if you submit a patch that contains excessive style conflicts, you may be asked to improve your code before your pull request is reviewed. +In the repository root directory, there is a [`.clang-format`](https://github.com/xbmc/xbmc/blob/master/.clang-format) file that implements the rules as specified here. You are encouraged to run [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) on any newly created files. It is currently not recommended to do so on preexisting files because all the formatting changes will clutter your commits and pull request. + +When you create a pull request, the PR build job will run `clang-format` on your commits and provide patches for any parts that don't satisfy the current `.clang-format` rules. You should apply these patches and amend your pull request accordingly. -In the repository root directory, there is a `.clang-format` file that implements the rules as specified here. You are encouraged to run `clang-format` on any newly created files. It is currently not recommended to do so on preexisting files because all the formatting changes will clutter your commits and pull request. +Conventions can be bent or broken in the interest of making code more readable and maintainable. However, if you submit a patch that contains excessive style conflicts, you may be asked to improve your code before your pull request is reviewed. **[back to top](#table-of-contents)** @@ -247,8 +249,8 @@ void Test(void); ### 3.7. Exceptions to the Formatting Rules For Better Readability There are some special situations where vertical alignment and longer lines does greatly aid readability, for example the initialization of some table-like multiple row structures. In these **rare** cases exceptions can be made to the formatting rules on vertical alignment, and the defined line length can be exceeded. -The layout can be protected from being reformatted when `clang-format` is applied by adding `// clang-format off` and `// clang-format on` statements either side of the lines of code. -For example +To prevent the layout from being reformatted, tell `clang-format` to [disable formatting](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code) on that section of code by surrounding it with the special comments `// clang-format off` and `// clang-format on`. +For example: ``` // clang-format off static const CGUIDialogMediaFilter::Filter filterList[] = { diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index ba2ef112a7..650dbade16 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -25,7 +25,7 @@ Reviews are a great way to get familiar with the codebase. If you would like to ## Coding guidelines * **Follow our [code guidelines](CODE_GUIDELINES.md)**. New code should follow those guidelines even if existing code doesn't. If you're up to it, improve existing code and submit it in separate commits. * **Document the code**. You know you're brilliant, but maybe you'd like to understand what you did a year from now. Or, code God forbid, help others... Nope, `// Magic. Do not touch!` does not count as documentation. -* **Separate code from cosmetics**. Code and cosmetic changes should be in separate commits. It's already hard to review code without added noise. Of course, deleting a **few** trailing spaces does not warrant a separate commit. Use your judgement. +* **Separate code from cosmetics**. Don't mix code and unrelated cosmetic changes in the same commit. It's already hard to review code without added noise. Of course, deleting a **few** trailing spaces does not warrant a separate commit. Use your judgement. Also, note that the PR build job expects each individual commit to be formatted according to the [`.clang-format`](https://github.com/xbmc/xbmc/blob/master/.clang-format) rules, so if your change touches existing code that needs reformatting to satisfy the current rules, then those would be considered related cosmetic changes that should be included in the same commit. * **Test your changes**. Kodi's **[continuous integration system](http://jenkins.kodi.tv/)** builds every PR automatically. Nonetheless, you're expected to test the code on your development platform. ## Updating your PR |