diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000000..0a5d001356 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,11 @@ +-- Use the default LuaJIT globals. +std = 'luajit' +-- This fork also introduces a new global for misc API namespace. +read_globals = { 'misc' } + +-- These files are inherited from the vanilla LuaJIT and need to +-- be coherent with the upstream. +exclude_files = { + 'dynasm/', + 'src/', +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 471e00df67..d166c9d88a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,6 +3,35 @@ # See the rationale in the root CMakeLists.txt. cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +find_program(LUACHECK luacheck) +if(LUACHECK) + set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc) + file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua) + add_custom_target(${PROJECT_NAME}-luacheck + DEPENDS ${LUACHECK_RC} ${LUACHECK_DEPS} + ) + add_custom_command(TARGET ${PROJECT_NAME}-luacheck + COMMENT "Running luacheck static analysis" + COMMAND + ${LUACHECK} ${PROJECT_SOURCE_DIR} + --codes + --config ${LUACHECK_RC} + # XXX: jit/vmdef.lua is an autogenerated Lua source, so + # there is no need to run luacheck against it. Hence + # explicitly exclude this file from the list for check. + --exclude-files ${LUAJIT_BINARY_DIR}/jit/vmdef.lua + # XXX: Filenames in .luacheckrc are considered relative to + # the working directory, hence luacheck should be run in the + # project root directory. + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) +else() + add_custom_target(${PROJECT_NAME}-luacheck) + add_custom_command(TARGET ${PROJECT_NAME}-luacheck + COMMENT "`luacheck' is not found, so ${PROJECT_NAME}-luacheck target is dummy" + ) +endif() + add_subdirectory(tarantool-tests) add_custom_target(${PROJECT_NAME}-test DEPENDS @@ -24,5 +53,6 @@ if(LUAJIT_USE_TEST) add_custom_target(test DEPENDS ${PROJECT_NAME}-test + ${PROJECT_NAME}-luacheck ) endif()