Reactos

[REACTOS] Introduce .clang-format file And set up a Travis job for checking formatting on PRs

authored by

Victor Perevertkin and committed by
Victor Perevertkin
0c64aed8 5b4dbec1

+101 -4
+35
.clang-format
··· 1 + # full manual is at https://clang.llvm.org/docs/ClangFormatStyleOptions.html 2 + --- 3 + BasedOnStyle: Microsoft 4 + 5 + IndentWidth: 4 6 + UseTab: Never 7 + 8 + IndentCaseLabels: true 9 + 10 + AllowAllArgumentsOnNextLine: false 11 + AllowAllParametersOfDeclarationOnNextLine: false 12 + 13 + BinPackParameters: false 14 + BinPackArguments: true 15 + 16 + # This applies to () [] <> 17 + AlignAfterOpenBracket: AlwaysBreak 18 + 19 + # Always break before braces 20 + BreakBeforeBraces: Allman 21 + 22 + # return type on it's own line 23 + AlwaysBreakAfterReturnType: All 24 + 25 + SpaceBeforeAssignmentOperators: true 26 + SpaceBeforeParens: ControlStatements 27 + SpaceBeforeRangeBasedForLoopColon: true 28 + SpaceInEmptyParentheses: false 29 + SpacesBeforeTrailingComments: 1 30 + SpacesInAngles: false 31 + SpacesInContainerLiterals: true 32 + SpacesInCStyleCastParentheses: false 33 + SpacesInParentheses: false 34 + SpacesInSquareBrackets: false 35 + ...
+27 -4
.travis.yml
··· 1 - language: bash 1 + dist: bionic 2 + language: cpp 3 + 4 + addons: 5 + apt: 6 + sources: 7 + - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main' 8 + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' 9 + packages: 10 + clang-format-9 2 11 3 12 git: 4 - depth: 5 13 + depth: 1 14 + 15 + env: 16 + global: 17 + - DO_BUILD=0 18 + - DO_CHECK=0 19 + - CLFORMAT_BINARY=clang-format-9 20 + jobs: 21 + - DO_BUILD=1 22 + - DO_CHECK=1 5 23 6 - before_script: 24 + before_install: 25 + - ln -s /usr/share/clang/clang-format-9/clang-format-diff.py ./sdk/tools/; 7 26 - wget https://svn.reactos.org/amine/RosBEBinFull.tar.gz -O RosBE.tar.gz 8 27 - tar -xzf RosBE.tar.gz 9 28 - echo 'mkdir ../Build && cd ../Build && $TRAVIS_BUILD_DIR/configure.sh -DENABLE_ROSTESTS=1 && ninja -k 0 && ninja bootcd' > tmp_file 10 29 11 30 script: 12 - - ./RosBEBinFull/RosBE.sh < tmp_file 31 + - if [ $DO_BUILD == "1" ]; then 32 + ./RosBEBinFull/RosBE.sh < tmp_file; 33 + elif [ $DO_CHECK == "1" ]; then 34 + ./sdk/tools/check_code_format.sh; 35 + fi
+39
sdk/tools/check_code_format.sh
··· 1 + #!/bin/bash 2 + # Copyright (c) 2017 Google Inc. 3 + 4 + # Licensed under the Apache License, Version 2.0 (the "License"); 5 + # you may not use this file except in compliance with the License. 6 + # You may obtain a copy of the License at 7 + # 8 + # http://www.apache.org/licenses/LICENSE-2.0 9 + # 10 + # Unless required by applicable law or agreed to in writing, software 11 + # distributed under the License is distributed on an "AS IS" BASIS, 12 + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + # See the License for the specific language governing permissions and 14 + # limitations under the License. 15 + # 16 + # Script to determine if source code in Pull Request is properly formatted. 17 + # Exits with non 0 exit code if formatting is needed. 18 + # 19 + # This script assumes to be invoked at the project root directory. 20 + 21 + BASE_BRANCH=${1:-master} 22 + 23 + FILES_TO_CHECK=$(git diff --name-only ${BASE_BRANCH} | grep -E ".*\.(cpp|cc|c\+\+|cxx|c|h|hpp)$") 24 + 25 + if [ -z "${FILES_TO_CHECK}" ]; then 26 + echo "No source code to check for formatting." 27 + exit 0 28 + fi 29 + 30 + FORMAT_DIFF=$(git diff -U0 ${BASE_BRANCH} -- ${FILES_TO_CHECK} | python3 ./sdk/tools/clang-format-diff.py -binary ${CLFORMAT_BINARY} -p1 -style=file) 31 + 32 + if [ -z "${FORMAT_DIFF}" ]; then 33 + echo "All source code in PR properly formatted." 34 + exit 0 35 + else 36 + echo "Found formatting errors!" 37 + echo "${FORMAT_DIFF}" 38 + exit 1 39 + fi