whitespace_checks.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. name: whitespace_checks
  2. # Check whitespaces of the following file types
  3. # Not checked: .lua, .yml, .properties, .conf, .java, .py, .svg, .gradle, .xml, ...
  4. # (luacheck already checks .lua files)
  5. on:
  6. push:
  7. paths:
  8. - '**.txt'
  9. - '**.md'
  10. - '**.[ch]'
  11. - '**.cpp'
  12. - '**.hpp'
  13. - '**.sh'
  14. - '**.cmake'
  15. - '**.glsl'
  16. - '**.lua'
  17. pull_request:
  18. paths:
  19. - '**.txt'
  20. - '**.md'
  21. - '**.[ch]'
  22. - '**.cpp'
  23. - '**.hpp'
  24. - '**.sh'
  25. - '**.cmake'
  26. - '**.glsl'
  27. - '**.lua'
  28. jobs:
  29. trailing_whitespaces:
  30. runs-on: ubuntu-latest
  31. steps:
  32. - uses: actions/checkout@v4
  33. # Line endings are already ensured by .gitattributes
  34. - name: Check trailing whitespaces
  35. run: |
  36. if git ls-files |\
  37. grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' |\
  38. xargs grep -n '\s$';\
  39. then\
  40. echo -e "\033[0;31mFound trailing whitespace";\
  41. (exit 1);\
  42. else\
  43. (exit 0);\
  44. fi
  45. indent_spaces:
  46. runs-on: ubuntu-latest
  47. steps:
  48. - uses: actions/checkout@v4
  49. # Line endings are already ensured by .gitattributes
  50. # Multiple multline comments in one line is not supported by this check
  51. # and there is no reason to use them
  52. # So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error
  53. - name: Check for unsupported multiline comments
  54. run: |
  55. if git ls-files |\
  56. grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
  57. xargs grep -n '\*/.*/\*';\
  58. then
  59. echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
  60. (exit 1);\
  61. else\
  62. (exit 0);\
  63. fi
  64. if git ls-files |\
  65. grep -E '\.lua$' |\
  66. xargs grep -n -e '\]\].*--\[\[';\
  67. then
  68. echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
  69. (exit 1);\
  70. else\
  71. (exit 0);\
  72. fi
  73. # This prepare files for final check
  74. # See python script ./util/ci/indent_tab_preprocess.py for details.
  75. - name: Preprocess files
  76. run: |
  77. git ls-files |\
  78. grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
  79. xargs -L 1 -P $(($(nproc) + 1)) \
  80. python3 ./util/ci/indent_tab_preprocess.py "/*" "*/"
  81. git ls-files |\
  82. grep -E '\.lua$' |\
  83. xargs -L 1 -P $(($(nproc) + 1)) \
  84. python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]"
  85. # Check for bad indent.
  86. # This runs over preprocessed files.
  87. # If there is any remaining space on line beginning or after tab,
  88. # error is generated
  89. - name: Check indent spaces
  90. run: |
  91. if git ls-files |\
  92. grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' |\
  93. xargs grep -n -P '^\t*[ ]';\
  94. then\
  95. echo -e "\033[0;31mFound incorrect indent whitespaces";\
  96. (exit 1);\
  97. else\
  98. (exit 0);\
  99. fi
  100. tabs_lua_api_files:
  101. runs-on: ubuntu-latest
  102. steps:
  103. - uses: actions/checkout@v4
  104. # Some files should not contain tabs
  105. - name: Check tabs in Lua API files
  106. run: |
  107. if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md;\
  108. then\
  109. echo -e "\033[0;31mFound tab in markdown file";\
  110. (exit 1);\
  111. else\
  112. (exit 0);\
  113. fi