summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format89
-rw-r--r--scripts/command/format47
2 files changed, 136 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000..84181d348
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,89 @@
+---
+Language: Cpp
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignEscapedNewlinesLeft: true
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: 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
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBraces: Allman
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 100
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IndentCaseLabels: false
+IndentWidth: 2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+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: Cpp11
+TabWidth: 4
+UseTab: Never
diff --git a/scripts/command/format b/scripts/command/format
new file mode 100644
index 000000000..fb5cd4d38
--- /dev/null
+++ b/scripts/command/format
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+CLANG_FORMAT_CANDIDATES=()
+CLANG_FORMAT_CANDIDATES+=("clang-format")
+CLANG_FORMAT_CANDIDATES+=("clang-format-3.9")
+
+for CLANG_FORMAT_CANDIDATE in ${CLANG_FORMAT_CANDIDATES[@]}; do
+ if [[ -n $(which ${CLANG_FORMAT_CANDIDATE}) ]]; then
+ CLANG_FORMAT="${CLANG_FORMAT_CANDIDATE}"
+ fi
+done
+
+if [[ -z ${CLANG_FORMAT} ]]; then
+ echo "[ERROR] clang-format is unavailable"
+ echo
+ echo "Please install clang-format before running format check"
+ exit 255
+fi
+
+if [[ -n $(git -C "${NNCC_PROJECT_PATH}" diff) ]]; then
+ echo "[ERROR] Commit all the changes before running format check"
+ exit 255
+fi
+
+DIRECTORIES_TO_BE_TESTED=()
+
+for DIRECTORY_TO_BE_TESTED in $(find "${NNCC_PROJECT_PATH}" -name '.FORMATCHECKED' -exec dirname {} \;); do
+ DIRECTORIES_TO_BE_TESTED+=("$DIRECTORY_TO_BE_TESTED")
+done
+
+CANDIDATE_FILES=$(find "${DIRECTORIES_TO_BE_TESTED[@]}" -iname '*.h' -o -iname '*.cpp')
+TRACKED_FILES=$(git ls-files $CANDIDATE_FILES)
+
+if [[ -z "$TRACKED_FILES" ]]; then
+ "${CLANG_FORMAT}" -i $TRACKED_FILES
+fi
+
+DIFF=$(git -C "${NNCC_PROJECT_PATH}" diff)
+
+if [[ -n "${DIFF}" ]]; then
+ echo "${DIFF}" > "${NNCC_PROJECT_PATH}/format.patch"
+
+ echo "[FAILED] Please find format.patch for details"
+ exit 255
+fi
+
+echo "[PASSED]"