Index: .clang-format =================================================================== --- /dev/null +++ .clang-format @@ -0,0 +1,70 @@ +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: DontAlign +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +BreakInheritanceList: BeforeComma +BreakStringLiterals: true +ColumnLimit: 132 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +FixNamespaceComments: true +IncludeBlocks: Regroup +# The main include will be category 0. +IncludeCategories: + - Regex: '"precompiled.h"' + Priority: -1 + - Regex: '^"' + Priority: 1 + - Regex: '^<' + Priority: 2 +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: true +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: ForIndentation Index: .coafile =================================================================== --- .coafile +++ .coafile @@ -1,7 +1,9 @@ [Source] -bears = CPPCheckBear, LicenseYearBear +bears = CPPCheckBear, LicenseYearBear, ClangFormatBear files = source/**.(cpp|h) ignore = source/third_party/** +clang_style = file +clang_inplace = False [JS] bears = ESLintBear, JSHintBear Index: build/coala/ClangFormatBear.py =================================================================== --- /dev/null +++ build/coala/ClangFormatBear.py @@ -0,0 +1,64 @@ +from coalib.bearlib.abstractions.Linter import linter +from coalib.results.Result import Result +from coalib.results.Diff import Diff +from coalib.bears.LocalBear import LocalBear +from coalib.settings.Setting import typed_list +from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY +from dependency_management.requirements.DistributionRequirement import ( + DistributionRequirement) + +@linter(executable='clang-format', + use_stdout=True, + use_stderr=True) +class ClangFormatBear(): + """ + Apply clang format rules to a specific file. + """ + LANGUAGES = {'C', 'C++'} + REQUIREMENTS = {DistributionRequirement('clang-format')} + AUTHORS = {'Stanislas Daniel Claude Dolcini'} + LICENSE = 'GPL-2.0' + CAN_DETECT = {'Formatting'} + + def create_arguments(self, filename, file, config_file, + clang_style: str = None, + clang_inplace: bool = False, + ): + """ + :param clang_style: Coding style, currently supports: + LLVM, Google, Chromium, Mozilla, WebKit. + Use -style=file to load style configuration from + .clang-format file located in one of the parent + directories of the source file (or current + directory for stdin). + Use -style="{key: value, ...}" to set specific + parameters, e.g.: + -style="{BasedOnStyle: llvm, IndentWidth: 8}" + :param clang_inplace: Inplace edit s, if specified. + """ + args = tuple() + if clang_inplace: + args += ('-i',) + + if clang_style is not None: + args += ('--style=' + clang_style,) + + return args + (filename,) + + def process_output(self, output, filename, file): + if(len(output) == 0): + self.warn(filename + ' is empty.') + return + + lines = ''.join(file) + diff = Diff.from_string_arrays( + lines.splitlines(True), + output[0].splitlines(True) + ) + + yield Result.from_values( + origin=self, + message='Incorrect Formating detected.', + file=filename, + diffs={filename: diff}, + ) Index: build/jenkins/dockerfiles/coala.Dockerfile =================================================================== --- build/jenkins/dockerfiles/coala.Dockerfile +++ build/jenkins/dockerfiles/coala.Dockerfile @@ -2,7 +2,7 @@ RUN adduser -u 1006 -D builder -RUN apk add subversion cppcheck npm +RUN apk add subversion cppcheck npm clang-format RUN pip3 install coala-bears svn RUN npm install -g eslint@5.16.0 jshint eslint-plugin-brace-rules