Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use and enforce clang-format google style #89

Merged
merged 19 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...

7 changes: 6 additions & 1 deletion .travis-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CHROOT_ARCH=armhf
HOST_DEPENDENCIES="debootstrap qemu-user-static binfmt-support sbuild"

# Debian package dependencies for the chrooted environment
GUEST_DEPENDENCIES="cmake git"
GUEST_DEPENDENCIES="cmake git clang-format"

function setup_arm_chroot {
# Host dependencies
Expand Down Expand Up @@ -113,6 +113,11 @@ else
echo "Running tests"
cppcheck . --error-exitcode=1 --suppressions cppcheck_suppressions.txt --force

clang-format -version
clang-format-8 -version
./clang-format.sh
git status | grep "nothing to commit, working tree clean"

cmake \
-DCBOR_CUSTOM_ALLOC=ON \
-DCMAKE_BUILD_TYPE=Debug \
Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ matrix:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
- george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main'
key_url: https://apt.llvm.org/llvm-snapshot.gpg.key
packages:
- clang-3.6
- libjansson-dev
Expand All @@ -19,12 +21,15 @@ matrix:
- lcov
- cmake
- cmake-data
- clang-format-8
- compiler: gcc-6
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main'
key_url: https://apt.llvm.org/llvm-snapshot.gpg.key
packages:
- gcc-6
- g++-6
Expand All @@ -34,6 +39,7 @@ matrix:
- lcov
- cmake
- cmake-data
- clang-format-8
# Temporarily disabled due to slow performance and problems with Raspbian
# chroot (https://travis-ci.org/PJK/libcbor/jobs/281748138)
# - env: ARCH=arm
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Next
- All cbor_new_ and cbor_build_ functions will now explicitly return NULL
when memory allocation fails
- It is up to the client to handle such cases
- Globally enforced code style [#83]

0.5.0 (2017-02-06)
---------------------
Expand Down
10 changes: 10 additions & 0 deletions clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# TravisCI workaround to use new clang-format while avoiding painful aliasing
# into the subshell
if which clang-format-8; then
clang-format-8 -style=file -i **/*.c **/*.h **/*.cpp
else
clang-format -style=file -i **/*.c **/*.h **/*.cpp
fi

3 changes: 1 addition & 2 deletions demo/hello_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <cbor.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
int main(int argc, char* argv[]) {
printf("Hello from libcbor %s\n", CBOR_VERSION);
}
7 changes: 5 additions & 2 deletions doc/source/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Development dependencies
- There are some `Ruby <https://www.ruby-lang.org/en/>`_ scripts in ``misc``
- `Valgrind <http://valgrind.org/>`_ (memory correctness & profiling)
- `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_ (test coverage)
- `clang-format`


Installing *sphinx*
Expand Down Expand Up @@ -38,11 +39,13 @@ Live preview of docs
Set up git hooks
~~~~~~~~~~~~~~~~~

A git hook that automatically refereshes the `GH pages <https://pages.github.com/>`_ contents located in ``docs`` can be symlinked:
A catch-all git hook that runs clang-format and automatically refreshes the `GH
pages <https://pages.github.com/>`_ contents located in ``docs`` can be
symlinked:

.. code-block:: bash

ln -s misc/hooks/pre-commit .git/hooks
ln -sf $(pwd)/misc/hooks/pre-commit .git/hooks


Testing and code coverage
Expand Down
Loading