mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
misc: add clang format stylesheet
- Run to clang-format all committed files. - Run with --all to format all cpp|cxx|cc|h|hpp|mm files in src/. - Run with --install to install as a pre-commit hook. Requires that clang-format be installed. Devs should either install the pre-commit hook or configure their editors to format on save etc. Change-Id: I73c2b19e0673115c1f7d33cbae5094f3a88d43e3
This commit is contained in:

committed by
Sébastien Blin

parent
a0c3cd723b
commit
85510893d5
110
.clang-format
Normal file
110
.clang-format
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
# Based on the .clang-format for Qt Creator
|
||||||
|
#
|
||||||
|
# This is for clang-format >= 10.0.
|
||||||
|
#
|
||||||
|
# https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||||
|
#
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: true
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignConsecutiveMacros: true
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: Inline
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterReturnType: TopLevelDefinitions
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
BreakBeforeBinaryOperators: All
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 100
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- forever # avoids { wrapped to next line
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<Q.*'
|
||||||
|
Priority: 200
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
MacroBlockBegin: ""
|
||||||
|
MacroBlockEnd: ""
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 150
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 300
|
||||||
|
PenaltyBreakComment: 500
|
||||||
|
PenaltyBreakFirstLessLess: 400
|
||||||
|
PenaltyBreakString: 600
|
||||||
|
PenaltyExcessCharacter: 50
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 300
|
||||||
|
PointerAlignment: Left
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Cpp11
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
18
astylerc
18
astylerc
@ -1,18 +0,0 @@
|
|||||||
# Filename: astylerc
|
|
||||||
# Purpose: config file for astyle
|
|
||||||
# http://astyle.sourceforge.net/astyle.html
|
|
||||||
# Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
|
|
||||||
# Savoir-faire Linux Inc
|
|
||||||
# https://jami.net
|
|
||||||
|
|
||||||
style=stroustrup # stroustrup style http://astyle.sourceforge.net/astyle.html#_style=stroustrup
|
|
||||||
indent=spaces=4 # Use spaces instead of tabs for indentation
|
|
||||||
indent-classes # Indent 'class' and 'struct' blocks so that the blocks 'public:', 'protected:' and 'private:' are indented
|
|
||||||
indent-switches # Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block
|
|
||||||
break-blocks # Pad empty lines around header blocks (e.g. 'if', 'while'...).
|
|
||||||
brackets=linux
|
|
||||||
unpad-paren # Remove unwanted space around parentheses
|
|
||||||
pad-header # Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...)
|
|
||||||
pad-oper # Insert space padding around operator
|
|
||||||
formatted # only display files that have changed
|
|
||||||
suffix=none # don't create backup files (that's what version control is for)
|
|
91
format.sh
Executable file
91
format.sh
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
command_exists ()
|
||||||
|
{
|
||||||
|
type "$1" &> /dev/null ;
|
||||||
|
}
|
||||||
|
|
||||||
|
CFVERSION="9"
|
||||||
|
CLANGFORMAT=""
|
||||||
|
if command_exists clang-format; then
|
||||||
|
CLANGFORMAT=clang-format
|
||||||
|
else
|
||||||
|
if command_exists clang-format-${CFVERSION}; then
|
||||||
|
CLANGFORMAT=clang-format-${CFVERSION}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v $CLANGFORMAT &> /dev/null; then
|
||||||
|
echo "Required version of clang-format not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
format_file()
|
||||||
|
{
|
||||||
|
if [ -f "${1}" ]; then
|
||||||
|
$CLANGFORMAT -i -style=file "${1}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
format_files()
|
||||||
|
{
|
||||||
|
for file in $1; do
|
||||||
|
echo -ne "Formatting: ${file}\\033[0K\\r"
|
||||||
|
format_file "${file}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_if_no_files()
|
||||||
|
{
|
||||||
|
echo No files to format
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
install_hook()
|
||||||
|
{
|
||||||
|
# check for lone repo ring-daemon
|
||||||
|
hooks_path=".git/hooks"
|
||||||
|
if [ ! -d "$hooks_path=" ]; then
|
||||||
|
# or ring-project
|
||||||
|
hooks_path="../.git/modules/daemon/hooks"
|
||||||
|
if [ ! -d "$hooks_path" ]; then
|
||||||
|
echo "Can't find a git directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo Installing pre-commit hook in "$hooks_path"
|
||||||
|
echo "/bin/bash $0" > "$hooks_path"/pre-commit
|
||||||
|
chmod +x "$hooks_path"/pre-commit
|
||||||
|
}
|
||||||
|
|
||||||
|
display_help()
|
||||||
|
{
|
||||||
|
echo "Usage: $0 [OPTION...] -- Clang format source files with a .clang-format file" >&2
|
||||||
|
echo
|
||||||
|
echo " --all format all files instead of only committed ones"
|
||||||
|
echo " --install install a pre-commit hook to run this script"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" == "--help" ]; then
|
||||||
|
display_help
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "${1}" in
|
||||||
|
--all )
|
||||||
|
files=$(find src -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|mm\)') || true
|
||||||
|
echo Formatting all source files...
|
||||||
|
format_files "$files"
|
||||||
|
;;
|
||||||
|
--install )
|
||||||
|
install_hook
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
files=$(git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cxx|cc|h|hpp|mm)') || exit_if_no_files
|
||||||
|
echo Formatting committed source files...
|
||||||
|
format_files "$files"
|
||||||
|
;;
|
||||||
|
esac
|
Reference in New Issue
Block a user