Skip to content

Commit

Permalink
Use clang-format and clang-tidy in CI (esphome#540)
Browse files Browse the repository at this point in the history
* Add automated linters

* Run clang-format

* Update travis [WIP]

* Fix

* Try fix

* PyYaml is not needed

* Try

* Try again

* Try

* This must be a bug in clang-tidy

* Try again

* Cleanup

* Annoying

* Update .travis.yml

* Update .travis.yml

* Found it

* Exit with 1 on formatting error

* Update gitignore

* Apply more caching

* Apply replacements

* Add param

* Update .travis.yml

* Update travis

* Update

* Fixes for global/static case

* Apply Fixes

* Manual Fixes

* Manual Fixes

* switch_ -> a_switch

* this_ -> a_this

* Apply fixes

* register

* data_ -> data

* aProtocol -> a_protocol

* Apply fixes

* Apply fixes

* Apply fixes

* Apply Fixes

* Apply Fixes

* Apply fixes

* Fix

* Apply fixes for sensor

* Update run-clang-tidy script

* Apply fixes

* Run clang-format

* Update format

* Also run clang-format over header files

* Fix

* Update platformio.ini

* Fixes

* Run lint job first

* Travis has two cores

* Fix format
  • Loading branch information
OttoWinter authored Mar 3, 2019
1 parent 6088a6d commit acccea7
Show file tree
Hide file tree
Showing 338 changed files with 6,821 additions and 9,168 deletions.
137 changes: 129 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,16 +1,137 @@
BasedOnStyle: Google
Language: Cpp
ColumnLimit: 120
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 2000
PointerAlignment: Right
SortIncludes: false
TabWidth: 2
UseTab: Never
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
IndentPPDirectives: None
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 2
UseTab: Never
65 changes: 65 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
Checks: >-
*,
-android-*,-boost-*,-clang-analyzer-osx.*,-objc-*,-zircon-*,-mpi-*,-llvm-header-guard,-llvm-include-order,-fuchsia-default-arguments,-fuchsia-overloaded-operator,-fuchsia-statically-constructed-objects,-fuchsia-multiple-inheritance,-google-runtime-int,-google-explicit-constructor,-google-readability-braces-around-statements,-google-runtime-references,-google-readability-casting,-cppcoreguidelines-pro-type-varar,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-c-copy-assignment-signature,-cppcoreguidelines-special-member-functions,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-readability-named-parameter,-readability-braces-around-statements,-readability-implicit-bool-conversion,-readability-else-after-return,-hicpp-*,-abseil-*,-fuchsia-*,-cert-err58-cpp,-cppcoreguidelines-pro-type-member-init,-cert-dcl50-cpp,-modernize-use-equals-default,-modernize-deprecated-headers,-modernize-use-auto,-modernize-pass-by-value,-bugprone-macro-parentheses,-misc-unused-parameters,-misc-unconventional-assign-operator,-performance-unnecessary-value-param,-modernize-pass-by-value,-modernize-return-braced-init-list,-cppcoreguidelines-pro-type-const-cast,-clang-analyzer-security.*,-google-readability-todo,-readability-redundant-member-init,-modernize-use-default-member-init,-cppcoreguidelines-pro-type-static-cast-downcast,-warnings-as-errors,-google-build-using-namespace,-clang-analyzer-core.CallAndMessage
WarningsAsErrors: '*'
HeaderFilterRegex: '^.*/src/esphome/.*'
AnalyzeTemporaryDtors: false
FormatStyle: google
CheckOptions:
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: readability-identifier-naming.LocalVariableCase
value: 'lower_case'
- key: readability-identifier-naming.ClassCase
value: 'CamelCase'
- key: readability-identifier-naming.StructCase
value: 'CamelCase'
- key: readability-identifier-naming.EnumCase
value: 'CamelCase'
- key: readability-identifier-naming.EnumConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.StaticConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.StaticVariableCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.GlobalConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.ParameterCase
value: 'lower_case'
- key: readability-identifier-naming.PrivateMemberPrefix
value: 'NO_PRIVATE_MEMBERS_ALWAYS_USE_PROTECTED'
- key: readability-identifier-naming.PrivateMethodPrefix
value: 'NO_PRIVATE_METHODS_ALWAYS_USE_PROTECTED'
- key: readability-identifier-naming.ClassMemberCase
value: 'lower_case'
- key: readability-identifier-naming.ProtectedMemberSuffix
value: '_'
- key: readability-identifier-naming.FunctionCase
value: 'lower_case'
- key: readability-identifier-naming.ClassMethodCase
value: 'lower_case'
- key: readability-identifier-naming.ProtectedMethodSuffix
value: '_'
- key: readability-identifier-naming.VirtualMethodCase
value: 'lower_case'
- key: readability-identifier-naming.VirtualMethodSuffix
value: ''
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.piolibdeps
.vscode
CMakeListsPrivate.txt
CMakeLists.txt

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down Expand Up @@ -36,3 +37,4 @@ cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
/*.cbp
45 changes: 37 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,44 @@ cache:
- "~/.platformio"
- "$TRAVIS_BUILD_DIR/.piolibdeps"

script:
- python travis.py
- platformio run -e $BUILD_TARGET

matrix:
fast_finish: true
include:
- env: BUILD_TARGET=livingroom
- env: BUILD_TARGET=livingroom8266
- env: BUILD_TARGET=custombmp180
- env: BUILD_TARGET=fastled
- env: TARGET=lint
dist: trusty
sudo: required
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
packages:
- cmake
- clang-tidy-7
- clang-format-7
before_script:
- pio init --ide clion
- |
if ! patch -R -p0 -s -f --dry-run <travis/neopixelbus.patch; then
patch -p0 < travis/neopixelbus.patch
fi
- cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
- clang-tidy-7 -version
- clang-format-7 -version
- clang-apply-replacements-7 -version
- nproc
script:
- python travis/run-clang-tidy.py -j 2 --fix
- python travis/run-clang-format.py -i -j 2
- travis/suggest-changes.sh
- env: TARGET=livingroom
script: &run_script
- python travis/travis.py
- platformio run -e $TARGET --disable-auto-clean
- env: TARGET=livingroom8266
script: *run_script
- env: TARGET=custombmp180
script: *run_script
- env: TARGET=fastled
script: *run_script
if: branch = dev AND type = push
54 changes: 0 additions & 54 deletions CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; This file is here for developing esphome-core

[platformio]
env_default = livingroom
env_default = livingroom8266
src_dir = .
include_dir = src

Expand Down
Loading

0 comments on commit acccea7

Please sign in to comment.