run-luacheck-linux.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. set -e
  3. exists() {
  4. if command -v "$1" >/dev/null 2>&1
  5. then
  6. return 0
  7. else
  8. return 1
  9. fi
  10. }
  11. usage() {
  12. echo "
  13. usage: bash tools/travis/run-luacheck.sh [-s]
  14. Avarible options are:
  15. -s: Standalone mode: Lua, LuaRocks and luacheck
  16. will be installed in nodemcu-firmare/cache folder.
  17. By default script will use luarocks installed in host system.
  18. "
  19. }
  20. install_tools() {
  21. if ! exists luarocks; then
  22. echo "LuaRocks not found!"
  23. exit 1
  24. fi
  25. eval "`luarocks path --bin`" #Set PATH for luacheck
  26. #In Travis Path it's not changed by LuaRocks for some unknown reason
  27. if [ "${TRAVIS}" = "true" ]; then
  28. export PATH=$PATH:/home/travis/.luarocks/bin
  29. fi
  30. if ! exists luacheck; then
  31. echo "Installing luacheck"
  32. luarocks install --local luacheck || exit
  33. fi
  34. }
  35. install_tools_standalone() {
  36. if ! [ -x cache/localua/bin/luarocks ]; then
  37. echo "Installing Lua 5.3 and LuaRocks"
  38. bash tools/travis/localua.sh cache/localua || exit
  39. fi
  40. if ! [ -x cache/localua/bin/luacheck ]; then
  41. echo "Installing luacheck"
  42. cache/localua/bin/luarocks install luacheck || exit
  43. fi
  44. }
  45. if [[ $1 == "" ]]; then
  46. install_tools
  47. else
  48. while getopts "s" opt
  49. do
  50. case $opt in
  51. (s) install_tools_standalone ;;
  52. (*) usage; exit 1 ;;
  53. esac
  54. done
  55. fi
  56. echo "Static analysys of"
  57. find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo
  58. (find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 luacheck --config tools/luacheck_config.lua) || exit