Changeset View
Standalone View
kde-modules/clang-format.cmake
- This file was added.
| 1 | --- | ||||
|---|---|---|---|---|---|
| 2 | # SPDX-License-Identifier: MIT | ||||
| 3 | # | ||||
| 4 | # Copyright (C) 2019 Christoph Cullmann <cullmann@kde.org> | ||||
| 5 | # Copyright (C) 2019 Gernot Gebhard <gebhard@absint.com> | ||||
| 6 | # | ||||
| 7 | # Permission is hereby granted, free of charge, to any person obtaining | ||||
| 8 | # a copy of this software and associated documentation files (the | ||||
| 9 | # "Software"), to deal in the Software without restriction, including | ||||
| 10 | # without limitation the rights to use, copy, modify, merge, publish, | ||||
| 11 | # distribute, sublicense, and/or sell copies of the Software, and to | ||||
| 12 | # permit persons to whom the Software is furnished to do so, subject to | ||||
| 13 | # the following conditions: | ||||
| 14 | # | ||||
| 15 | # The above copyright notice and this permission notice shall be included | ||||
| 16 | # in all copies or substantial portions of the Software. | ||||
| 17 | # | ||||
| 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||
| 19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||
| 20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||||
| 21 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||||
| 22 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||||
| 23 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||||
| 24 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
| 25 | | ||||
| 26 | # Style for C++ | ||||
| 27 | Language: Cpp | ||||
| 28 | | ||||
| 29 | # base is WebKit coding style: http://www.webkit.org/coding/coding-style.html | ||||
| 30 | # below are only things set that diverge from this style! | ||||
| 31 | BasedOnStyle: WebKit | ||||
| 32 | | ||||
| 33 | # enforce C++11 (e.g. for std::vector<std::vector<lala>> | ||||
| 34 | Standard: Cpp11 | ||||
| 35 | | ||||
| 36 | # 4 spaces indent | ||||
| 37 | TabWidth: 4 | ||||
| 38 | | ||||
| 39 | # 3 * 80 wide lines | ||||
| 40 | ColumnLimit: 240 | ||||
| 41 | | ||||
| 42 | # sort includes inside line separated groups | ||||
| 43 | SortIncludes: true | ||||
dfaure: Typo: semantics | |||||
| 44 | | ||||
I'm confused because here it says "true" will group via empty lines, while https://code.qt.io/cgit/qt/qt5.git/tree/_clang-format says the SortInclude feature of clang-format does not re-order includes separated by empty lines. Maybe different versions of clang-format? Or I misunderstand something? dfaure: I'm confused because here it says "true" will group via empty lines, while https://code.qt. | |||||
Perhaps my comment is not understandable. cullmann: Perhaps my comment is not understandable.
true means clang-format will sort stuff inside… | |||||
| 45 | # break before braces on function, namespace and class definitions. | ||||
| 46 | BreakBeforeBraces: Linux | ||||
| 47 | | ||||
| 48 | # CrlInstruction *a; | ||||
| 49 | PointerAlignment: Right | ||||
| 50 | | ||||
https://code.qt.io/cgit/qt/qt5.git/tree/_clang-format says PointerBindsToType: false, what's the difference? dfaure: https://code.qt.io/cgit/qt/qt5.git/tree/_clang-format says `PointerBindsToType: false`, what's… | |||||
My file is for some recent clang, whereas PointerBindsToType seems to be ancient, see: https://releases.llvm.org/3.4/tools/clang/docs/ClangFormatStyleOptions.html (there you still have that) http://releases.llvm.org/9.0.0/tools/clang/docs/ClangFormatStyleOptions.html (here I can only find the variant I use) cullmann: My file is for some recent clang, whereas PointerBindsToType seems to be ancient, see:
https… | |||||
| 51 | # horizontally aligns arguments after an open bracket. | ||||
| 52 | AlignAfterOpenBracket: Align | ||||
| 53 | | ||||
| 54 | # align trailing comments | ||||
| 55 | AlignTrailingComments: true | ||||
| 56 | | ||||
| 57 | # don't move all parameters to new line | ||||
| 58 | AllowAllParametersOfDeclarationOnNextLine: false | ||||
| 59 | | ||||
| 60 | # no single line functions | ||||
| 61 | AllowShortFunctionsOnASingleLine: None | ||||
| 62 | | ||||
| 63 | # always break before you encounter multi line strings | ||||
| 64 | AlwaysBreakBeforeMultilineStrings: true | ||||
| 65 | | ||||
| 66 | # don't move arguments to own lines if they are not all on the same | ||||
| 67 | BinPackArguments: false | ||||
| 68 | | ||||
| 69 | # don't move parameters to own lines if they are not all on the same | ||||
| 70 | BinPackParameters: false | ||||
| 71 | | ||||
| 72 | # don't break binary ops | ||||
| 73 | BreakBeforeBinaryOperators: None | ||||
| 74 | | ||||
| 75 | # format C++11 braced lists like function calls | ||||
| 76 | Cpp11BracedListStyle: true | ||||
dfaure: typo: ternary | |||||
I've been always wondering how one should break long ternary operators when writing KF code. There are several ways to do it (a) w/o breaking (BreakBeforeTernaryOperators: false) const FooBar *foobar = someStupidCondition() ? someSuperDuperBeatifulFunctionWithLongName() : anotherSuperDuperBeatifuuuulFunctionWithLongName(); (b) w/ breaking (BreakBeforeTernaryOperators: true) const FooBar *foobar = someStupidCondition() ? someSuperDuperBeatifulFunctionWithLongName() : anotherSuperDuperBeatifuuuulFunctionWithLongName(); According to the _clang-format file from the qt5 super repo, Qt fellas prefer (b) to break before ternary operators. Do we really want to not break before ternary opeartors? zzag: I've been always wondering how one should break long ternary operators when writing KF code. | |||||
cullmann: I have no strong opinion on that, we can remove that or keep it. | |||||
(b) looks good to me, and more importantly, I like the goal of being as close as possible to the Qt coding style. dfaure: (b) looks good to me, and more importantly, I like the goal of being as close as possible to… | |||||
removed that setting, back to Webkit default of BreakBeforeTernaryOperators: true cullmann: removed that setting, back to Webkit default of BreakBeforeTernaryOperators: true | |||||
| 77 | | ||||
| 78 | # remove empty lines | ||||
| 79 | KeepEmptyLinesAtTheStartOfBlocks: false | ||||
| 80 | | ||||
| 81 | # no namespace indentation to keep indent level low | ||||
| 82 | NamespaceIndentation: None | ||||
| 83 | | ||||
| 84 | # we use template< without space. | ||||
| 85 | SpaceAfterTemplateKeyword: false | ||||
| 86 | | ||||
| 87 | # macros for which the opening brace stays attached. | ||||
| 88 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ] | ||||
Typo: semantics