lint.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # Copyright (c) 2020-2021 Project CHIP Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. name: Lint Code Base
  15. on:
  16. push:
  17. pull_request:
  18. merge_group:
  19. workflow_dispatch:
  20. concurrency:
  21. group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
  22. cancel-in-progress: true
  23. jobs:
  24. code-lints:
  25. runs-on: ubuntu-latest
  26. if: github.actor != 'restyled-io[bot]'
  27. container:
  28. image: ghcr.io/project-chip/chip-build:1
  29. steps:
  30. - name: Checkout
  31. uses: actions/checkout@v4
  32. # Bootstrap and checkout for internal scripts (like idl_lint)
  33. # to run
  34. - name: Checkout submodules & Bootstrap
  35. uses: ./.github/actions/checkout-submodules-and-bootstrap
  36. with:
  37. platform: linux
  38. - name: Check for matter lint errors
  39. if: always()
  40. run: |
  41. for idl_file in $(find . -name '*.matter'); do
  42. # TODO: all these conformance failures should be fixed
  43. # Issues exist for most of them:
  44. # https://github.com/project-chip/connectedhomeip/issues/19176
  45. # https://github.com/project-chip/connectedhomeip/issues/19175
  46. # https://github.com/project-chip/connectedhomeip/issues/19173
  47. # https://github.com/project-chip/connectedhomeip/issues/19169
  48. # https://github.com/project-chip/connectedhomeip/issues/22640
  49. if [ "$idl_file" = './examples/all-clusters-app/all-clusters-common/all-clusters-app.matter' ]; then continue; fi
  50. if [ "$idl_file" = './examples/log-source-app/log-source-common/log-source-app.matter' ]; then continue; fi
  51. if [ "$idl_file" = './examples/placeholder/linux/apps/app1/config.matter' ]; then continue; fi
  52. if [ "$idl_file" = './examples/placeholder/linux/apps/app2/config.matter' ]; then continue; fi
  53. if [ "$idl_file" = './examples/thermostat/thermostat-common/thermostat.matter' ]; then continue; fi
  54. if [ "$idl_file" = './examples/window-app/common/window-app.matter' ]; then continue; fi
  55. # Test files are intentionally small and not spec-compilant, just parse-compliant
  56. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/cluster_struct_attribute.matter" ]; then continue; fi
  57. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/global_struct_attribute.matter" ]; then continue; fi
  58. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/optional_argument.matter" ]; then continue; fi
  59. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/several_clusters.matter" ]; then continue; fi
  60. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/simple_attribute.matter" ]; then continue; fi
  61. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/large_lighting_app.matter" ]; then continue; fi
  62. if [ "$idl_file" = "./scripts/py_matter_idl/matter_idl/tests/inputs/large_all_clusters_app.matter" ]; then continue; fi
  63. ./scripts/run_in_build_env.sh "./scripts/idl_lint.py --log-level warn $idl_file" >/dev/null || exit 1
  64. done
  65. - name: Check broken links
  66. # On-push disabled until the job can run fully green
  67. # At that point the step should be enabled.
  68. if: github.event_name == 'workflow_dispatch'
  69. uses: gaurav-nelson/github-action-markdown-link-check@v1
  70. # git grep exits with 0 if it finds a match, but we want
  71. # to fail (exit nonzero) on match. And we want to exclude this file,
  72. # to avoid our grep regexp matching itself.
  73. - name: Check for incorrect error use in VerifyOrExit
  74. if: always()
  75. run: |
  76. git grep -n "VerifyOrExit(.*, [A-Za-z]*_ERROR" -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
  77. # git grep exits with 0 if it finds a match, but we want
  78. # to fail (exit nonzero) on match. And we want to exclude this file,
  79. # to avoid our grep regexp matching itself.
  80. - name: Check for use of PRI*8, which are not supported on some libcs.
  81. if: always()
  82. run: |
  83. git grep -n "PRI.8" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)third_party/lwip/repo/lwip/src/include/lwip/arch.h' && exit 1 || exit 0
  84. # git grep exits with 0 if it finds a match, but we want
  85. # to fail (exit nonzero) on match. And we want to exclude this file,
  86. # to avoid our grep regexp matching itself.
  87. - name: Check for use of PRI*16, which are not supported on some libcs.
  88. if: always()
  89. run: |
  90. git grep -n "PRI.16" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)third_party/lwip/repo/lwip/src/include/lwip/arch.h' && exit 1 || exit 0
  91. # git grep exits with 0 if it finds a match, but we want
  92. # to fail (exit nonzero) on match. And we want to exclude this file,
  93. # to avoid our grep regexp matching itself.
  94. - name: Check for use of %zu, which are not supported on some libcs.
  95. if: always()
  96. run: |
  97. git grep -n "%zu" -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
  98. # Comments like '{{! ... }}' should be used in zap files
  99. - name: Do not allow TODO in generated files
  100. if: always()
  101. run: |
  102. git grep -n 'TODO:' -- ./zzz_generated './*/zap-generated/*' && exit 1 || exit 0
  103. - name: Check for disallowed include files
  104. if: always()
  105. run: scripts/tools/check_includes.sh
  106. - name: Check for zcl.json and extension sync status
  107. if: always()
  108. run: scripts/tools/check_zcl_file_sync.py .
  109. - name: Ensure all PICS are set for tests (to true or false)
  110. if: always()
  111. run: |
  112. scripts/tools/check_test_pics.py src/app/tests/suites/certification/ci-pics-values src/app/tests/suites/certification/PICS.yaml
  113. # git grep exits with 0 if it finds a match, but we want
  114. # to fail (exit nonzero) on match. And we want to exclude this file,
  115. # to avoid our grep regexp matching itself.
  116. - name: Check for use of 0x%u and the like, which lead to misleading output.
  117. if: always()
  118. run: |
  119. git grep -n '0x%[0-9l.-]*[^0-9lxX".-]' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
  120. # git grep exits with 0 if it finds a match, but we want
  121. # to fail (exit nonzero) on match. And we want to exclude this file,
  122. # to avoid our grep regexp matching itself.
  123. - name: Check for use of '"0x" PRIu*' and the like, which lead to misleading output.
  124. if: always()
  125. run: |
  126. git grep -n '0x%[0-9-]*" *PRI[^xX]' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
  127. # git grep exits with 0 if it finds a match, but we want
  128. # to fail (exit nonzero) on match.
  129. - name: Check for use of NSLog instead of Matter logging in Matter framework
  130. if: always()
  131. run: |
  132. git grep -n 'NSLog(' -- src/darwin/Framework/CHIP && exit 1 || exit 0
  133. # git grep exits with 0 if it finds a match, but we want
  134. # to fail (exit nonzero) on match. And we want to exclude this file,
  135. # to avoid our grep regexp matching itself, as well as excluding the files
  136. # that implement the type-safe accessors
  137. - name: Check for use of 'emberAfReadAttribute' instead of the type-safe getters
  138. if: always()
  139. run: |
  140. git grep -n 'emberAfReadAttribute' -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)src/app/util/af.h' ':(exclude)zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp' ':(exclude)src/app/zap-templates/templates/app/attributes/Accessors-src.zapt' ':(exclude)src/app/util/attribute-table.cpp' && exit 1 || exit 0
  141. # git grep exits with 0 if it finds a match, but we want
  142. # to fail (exit nonzero) on match. And we want to exclude this file,
  143. # to avoid our grep regexp matching itself, as well as excluding the files
  144. # that implement the type-safe accessors, attribute writing from the wire, and some
  145. # Pigweed RPC code that seems hard to update.
  146. - name: Check for use of 'emberAfWriteAttribute' instead of the type-safe setters
  147. if: always()
  148. run: |
  149. git grep -n 'emberAfWriteAttribute' -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)src/app/util/af.h' ':(exclude)zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp' ':(exclude)src/app/zap-templates/templates/app/attributes/Accessors-src.zapt' ':(exclude)src/app/util/attribute-table.cpp' ':(exclude)examples/common/pigweed/rpc_services/Attributes.h' ':(exclude)src/app/util/attribute-table.h' ':(exclude)src/app/util/ember-compatibility-functions.cpp' && exit 1 || exit 0
  150. # Run python Linter (flake8) and verify python files
  151. # ignore some style errors, restyler should do that
  152. - name: Check for errors using flake8 Python linter
  153. if: always()
  154. run: |
  155. flake8 --extend-ignore=E501,W391
  156. # git grep exits with 0 if it finds a match, but we want
  157. # to fail (exit nonzero) on match. And we want to exclude this file,
  158. # to avoid our grep regexp matching itself.
  159. - name: Check for use of "SuccessOrExit(CHIP_ERROR_*)", which should probably be "SuccessOrExit(err = CHIP_ERROR_*)"
  160. if: always()
  161. run: |
  162. git grep -n 'SuccessOrExit(CHIP_ERROR' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
  163. # git grep exits with 0 if it finds a match, but we want
  164. # to fail (exit nonzero) on match. And we want to exclude this file,
  165. # to avoid our grep regexp matching itself.
  166. - name: Check for use of "SuccessOrExit(something-without-assignment(", which should probably be "SuccessOrExit(err = something("
  167. if: always()
  168. run: |
  169. git grep -n 'SuccessOrExit([^=)]*(' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0