From 96a17c1b667c7b7ac783a49663c976b685236cba Mon Sep 17 00:00:00 2001 From: Marco Feder Date: Fri, 4 Nov 2022 09:21:04 +0100 Subject: [PATCH] Add indent --- .clang-format | 175 ++++++++++++++++++++++++++++++ .github/workflows/indentation.yml | 18 +++ scripts/check_indentation.sh | 4 + scripts/indent | 35 ++++++ 4 files changed, 232 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/indentation.yml create mode 100755 scripts/check_indentation.sh create mode 100755 scripts/indent diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..c9e7c785 --- /dev/null +++ b/.clang-format @@ -0,0 +1,175 @@ +# +# The clang-format (Clang 6) style file used by deal.II. +# + +AccessModifierOffset: -2 + +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true + +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false + +AlwaysBreakAfterReturnType: All +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true + +BinPackArguments: false +BinPackParameters: false + +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: true + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false + +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: BeforeComma +BreakStringLiterals: false + +ColumnLimit: 80 + +CompactNamespaces: false + +ConstructorInitializerIndentWidth: 2 + +ContinuationIndentWidth: 2 + +Cpp11BracedListStyle: true + +DerivePointerAlignment: false + +FixNamespaceComments: true + +IncludeBlocks: Regroup +IncludeCategories: +# config.h must always be first: + - Regex: "deal.II/base/config.h" + Priority: -1 +# deal.II folders in sorted order: + - Regex: "deal.II/algorithms/.*\\.h" + Priority: 110 + - Regex: "deal.II/base/.*\\.h" + Priority: 120 + - Regex: "deal.II/boost_adaptors/.*\\.h" + Priority: 125 + - Regex: "deal.II/differentiation/.*\\.h" + Priority: 130 + - Regex: "deal.II/distributed/.*\\.h" + Priority: 140 + - Regex: "deal.II/dofs/.*\\.h" + Priority: 150 + - Regex: "deal.II/fe/.*\\.h" + Priority: 160 + - Regex: "deal.II/gmsh/.*\\.h" + Priority: 170 + - Regex: "deal.II/grid/.*\\.h" + Priority: 180 + - Regex: "deal.II/hp/.*\\.h" + Priority: 190 + - Regex: "deal.II/integrators/.*\\.h" + Priority: 200 + - Regex: "deal.II/lac/.*\\.h" + Priority: 210 + - Regex: "deal.II/matrix_free/.*\\.h" + Priority: 220 + - Regex: "deal.II/meshworker/.*\\.h" + Priority: 230 + - Regex: "deal.II/multigrid/.*\\.h" + Priority: 240 + - Regex: "deal.II/non_matching/.*\\.h" + Priority: 250 + - Regex: "deal.II/numerics/.*\\.h" + Priority: 260 + - Regex: "deal.II/opencascade/.*\\.h" + Priority: 270 + - Regex: "deal.II/optimization/.*\\.h" + Priority: 280 + - Regex: "deal.II/particles/.*\\.h" + Priority: 290 + - Regex: "deal.II/physics/.*\\.h" + Priority: 300 + - Regex: "deal.II/sundials/.*\\.h" + Priority: 310 +# put boost right after deal: + - Regex: "" + Priority: 500 +# try to group PETSc headers: + - Regex: "" + Priority: 1000 +# try to catch all third party headers and put them after deal.II but before +# standard headers: + - Regex: "<.*\\.(h|hpp|hxx)>" + Priority: 2000 +# match all standard headers. Things like '#include ' should be +# surrounded by #ifdef checks (which will not be merged by clang-format) so they +# should not be caught here + - Regex: "<[a-z_]+>" + Priority: 100000 +# make sure that "../tests.h" appears before all other local include files +# such that replacing Assert in tests also applies to the testing header files. + - Regex: "\\.\\./tests\\.h" + Priority: 200000 + +IndentCaseLabels: true +IndentPPDirectives: AfterHash +IndentWidth: 2 + +IndentWrappedFunctionNames: false + +KeepEmptyLinesAtTheStartOfBlocks: false + +Language: Cpp + +MaxEmptyLinesToKeep: 3 + +NamespaceIndentation: All + +PenaltyBreakBeforeFirstCallParameter: 90 + +PointerAlignment: Right + +ReflowComments: true +CommentPragmas: '( \| |\*--|
  • |@ref | @p |@param |@name |@returns |@warning |@ingroup |@author |@date |@related |@relates |@relatesalso |@deprecated |@image |@return |@brief |@attention |@copydoc |@addtogroup |@todo |@tparam |@see |@note |@skip |@skipline |@until |@line |@dontinclude |@include)' + +SortIncludes: true +SortUsingDeclarations: true + +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +Standard: Cpp11 + +TabWidth: 2 + +UseTab: Never \ No newline at end of file diff --git a/.github/workflows/indentation.yml b/.github/workflows/indentation.yml new file mode 100644 index 00000000..00ea232d --- /dev/null +++ b/.github/workflows/indentation.yml @@ -0,0 +1,18 @@ +name: Indent + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Check indentation + run: | + ./scripts/dr.sh ./scripts/check_indentation.sh \ No newline at end of file diff --git a/scripts/check_indentation.sh b/scripts/check_indentation.sh new file mode 100755 index 00000000..ade38b58 --- /dev/null +++ b/scripts/check_indentation.sh @@ -0,0 +1,4 @@ +#!/bin/sh +./scripts/indent +git diff +git diff-files --quiet \ No newline at end of file diff --git a/scripts/indent b/scripts/indent new file mode 100755 index 00000000..179491a2 --- /dev/null +++ b/scripts/indent @@ -0,0 +1,35 @@ +#!/bin/bash +## --------------------------------------------------------------------- +## +## Copyright (C) 2012 - 2013, 2015 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +if test ! -d source ; then + echo "*** This script must be run from the top-level directory of your project." + exit +fi + +if test ! -f .clang-format ; then + echo "*** No style file .clang-format found." + exit +fi + + +# loop over all directories in which we may have source files; +# collect a list of files and then spawn a parallel process to +# indent all of them +echo "--- Indenting all header and source files" +SRC_FILES=`find . -name "*.cc"` +H_FILES=`find . -name "*.h"` +clang-format -i $SRC_FILES +clang-format -i $H_FILES \ No newline at end of file