-
-
Save zhanglongqi/64b7df48775fe6ea9f8ed16c52261d37 to your computer and use it in GitHub Desktop.
Script that runs clang-format on files in a set of directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
Language: Cpp | |
# BasedOnStyle: WebKit | |
AccessModifierOffset: -4 | |
AlignAfterOpenBracket: Align | |
AlignConsecutiveAssignments: true | |
AlignConsecutiveDeclarations: true | |
AlignEscapedNewlinesLeft: false | |
AlignOperands: true | |
AlignTrailingComments: true | |
AllowAllParametersOfDeclarationOnNextLine: true | |
AllowShortBlocksOnASingleLine: false | |
AllowShortCaseLabelsOnASingleLine: false | |
AllowShortFunctionsOnASingleLine: All | |
AllowShortIfStatementsOnASingleLine: false | |
AllowShortLoopsOnASingleLine: false | |
AlwaysBreakAfterDefinitionReturnType: None | |
AlwaysBreakAfterReturnType: None | |
AlwaysBreakBeforeMultilineStrings: false | |
AlwaysBreakTemplateDeclarations: false | |
BinPackArguments: true | |
BinPackParameters: true | |
BreakBeforeBinaryOperators: All | |
BreakBeforeBraces: WebKit | |
BreakBeforeTernaryOperators: true | |
BreakConstructorInitializersBeforeComma: true | |
ColumnLimit: 0 | |
CommentPragmas: '^ IWYU pragma:' | |
ConstructorInitializerAllOnOneLineOrOnePerLine: false | |
ConstructorInitializerIndentWidth: 4 | |
ContinuationIndentWidth: 4 | |
Cpp11BracedListStyle: false | |
DerivePointerAlignment: false | |
DisableFormat: false | |
ExperimentalAutoDetectBinPacking: false | |
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] | |
IncludeCategories: | |
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' | |
Priority: 2 | |
- Regex: '^(<|"(gtest|isl|json)/)' | |
Priority: 3 | |
- Regex: '.*' | |
Priority: 1 | |
IndentCaseLabels: false | |
IndentWidth: 4 | |
IndentWrappedFunctionNames: false | |
IndentPPDirectives: 'AfterHash' | |
KeepEmptyLinesAtTheStartOfBlocks: true | |
MacroBlockBegin: '' | |
MacroBlockEnd: '' | |
MaxEmptyLinesToKeep: 1 | |
NamespaceIndentation: Inner | |
ObjCBlockIndentWidth: 4 | |
ObjCSpaceAfterProperty: true | |
ObjCSpaceBeforeProtocolList: true | |
PenaltyBreakBeforeFirstCallParameter: 19 | |
PenaltyBreakComment: 300 | |
PenaltyBreakFirstLessLess: 120 | |
PenaltyBreakString: 1000 | |
PenaltyExcessCharacter: 1000000 | |
PenaltyReturnTypeOnItsOwnLine: 60 | |
PointerAlignment: Right | |
ReflowComments: true | |
SortIncludes: false | |
SpaceAfterCStyleCast: false | |
SpaceBeforeAssignmentOperators: true | |
SpaceBeforeParens: ControlStatements | |
SpaceInEmptyParentheses: false | |
SpacesBeforeTrailingComments: 1 | |
SpacesInAngles: false | |
SpacesInContainerLiterals: true | |
SpacesInCStyleCastParentheses: false | |
SpacesInParentheses: false | |
SpacesInSquareBrackets: false | |
Standard: Cpp03 | |
TabWidth: 4 | |
UseTab: ForIndentation | |
IndentPPDirectives: AfterHash | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script reformats source files using the clang-format utility. | |
# Set the list of source directories on the "for" line below. | |
# | |
# The file .clang-format in this directory specifies the formatting parameters. | |
# | |
# Files are changed in-place, so make sure you don't have anything open in an | |
# editor, and you may want to commit before formatting in case of awryness. | |
# | |
# Note that clang-format is not included with OS X or Xcode; you must | |
# install it yourself. There are multiple ways to do this: | |
# | |
# - If you use Xcode, install the ClangFormat-Xcode plugin. See instructions at | |
# <https://github.com/travisjeffery/ClangFormat-Xcode/>. | |
# After installation, the executable can be found at | |
# $HOME/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/bin/clang-format. | |
# | |
# - Download an LLVM release from <http://llvm.org/releases/download.html>. | |
# For OS X, use the pre-built binaries for "Darwin". | |
# | |
# - Build the LLVM tools from source. See the documentation at <http://llvm.org>. | |
# Change this if your clang-format executable is somewhere else | |
CLANG_FORMAT="/usr/local/bin/clang-format" | |
for DIRECTORY in . | |
do | |
echo "Formatting code under $DIRECTORY/" | |
find "$DIRECTORY" \( -name '*.h' -or -name '*.m' -or -name '*.mm' \) -print0 | xargs -0 "$CLANG_FORMAT" -i | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment