Skip to content

Commit

Permalink
Add luacheck integration
Browse files Browse the repository at this point in the history
Patch reimplements commit 'Run luacheck on CI, fix warnings'
(b660d8e) added for http v2 and later
reverted in scope of issue with discard v2. File http/mime_types.lua
contains duplicate items in a table, I don't know what items can be
removed so I just ignored a file in a luacheck configuration file.

Follows up #95
Part of #134
  • Loading branch information
ligurio committed Oct 28, 2021
1 parent e4ee990 commit cd1e7a5
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/check_on_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Static analysis

on:
push:
pull_request:

jobs:
static-analysis:
if: |
github.event_name == 'push' ||
github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Setup Tarantool
uses: tarantool/setup-tarantool@v1
with:
tarantool-version: '2.8'

- name: Setup luacheck
run: tarantoolctl rocks install luacheck 0.25.0

- run: cmake -S . -B build

- name: Run luacheck
run: make -C build luacheck
35 changes: 35 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
std = "luajit"
globals = {"box", "_TARANTOOL", "tonumber64", "utf8"}
ignore = {
-- Accessing an undefined field of a global variable <debug>.
"143/debug",
-- Accessing an undefined field of a global variable <os>.
"143/os",
-- Accessing an undefined field of a global variable <string>.
"143/string",
-- Accessing an undefined field of a global variable <table>.
"143/table",
-- Unused argument <self>.
"212/self",
-- Redefining a local variable.
"411",
-- Redefining an argument.
"412",
-- Shadowing a local variable.
"421",
-- Shadowing an upvalue.
"431",
-- Shadowing an upvalue argument.
"432",
}

include_files = {
"**/*.lua",
}

exclude_files = {
"build/**/*.lua",
".rocks/**/*.lua",
".git/**/*.lua",
"http/mime_types.lua",
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Replace Travis CI with Github Actions.
- Add workflow that publish rockspec.
- Add editorconfig to configure indentation.
- Add luacheck integration.

### Fixed

Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

find_package(LuaTest)
find_package(LuaCheck)

# Find Tarantool and Lua dependecies
set(TARANTOOL_FIND_REQUIRED ON)
Expand All @@ -18,6 +19,12 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra")

add_subdirectory(http)

add_custom_target(luacheck
COMMAND ${LUACHECK} ${PROJECT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Run luacheck"
)

add_custom_target(luatest
COMMAND ${LUATEST} -v
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ align="right">

# HTTP server for Tarantool 1.7.5+

[![Static analysis](https://github.com/tarantool/http/actions/workflows/check_on_push.yaml/badge.svg)](https://github.com/tarantool/http/actions/workflows/check_on_push.yaml)
[![Test](https://github.com/tarantool/http/actions/workflows/test.yml/badge.svg)](https://github.com/tarantool/http/actions/workflows/test.yml)

> **Note:** In Tarantool 1.7.5+, a full-featured HTTP client is available aboard.
Expand Down
12 changes: 12 additions & 0 deletions cmake/FindLuaCheck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
find_program(LUACHECK luacheck
HINTS .rocks/
PATH_SUFFIXES bin
DOC "Lua static analyzer"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LuaCheck
REQUIRED_VARS LUACHECK
)

mark_as_advanced(LUACHECK)
17 changes: 8 additions & 9 deletions http/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ local function request_content_type(self)
end

local function post_param(self, name)
local content_type = self:content_type()
if self:content_type() == 'multipart/form-data' then
-- TODO: do that!
rawset(self, 'post_params', {})
Expand Down Expand Up @@ -213,7 +212,7 @@ local function catfile(...)
return
end

for i, pe in pairs(sp) do
for _, pe in pairs(sp) do
if path == nil then
path = pe
elseif string.match(path, '.$') ~= '/' then
Expand Down Expand Up @@ -441,7 +440,7 @@ local function render(tx, opts)
return resp
end

local function iterate(tx, gen, param, state)
local function iterate(_, gen, param, state)
return setmetatable({ body = { gen = gen, param = param, state = state } },
response_mt)
end
Expand Down Expand Up @@ -837,7 +836,7 @@ local function process_client(self, s, peer)
};
for k, v in pairs(hdrs) do
if type(v) == 'table' then
for i, sv in pairs(v) do
for _, sv in pairs(v) do
table.insert(response, sprintf("%s: %s\r\n", ucfirst(k), sv))
end
else
Expand All @@ -857,7 +856,7 @@ local function process_client(self, s, peer)
if not s:write(response) then
break
end
response = nil
response = nil -- luacheck: no unused
-- Transfer-Encoding: chunked
for _, part in gen, param, state do
part = tostring(part)
Expand Down Expand Up @@ -916,7 +915,7 @@ local function match_route(self, method, route)
local fit
local stash = {}

for k, r in pairs(self.routes) do
for _, r in pairs(self.routes) do
if r.method == method or r.method == 'ANY' then
local m = { string.match(route, r.match) }
local nfit
Expand Down Expand Up @@ -980,7 +979,7 @@ local function url_for_route(r, args, query)
args = {}
end
local name = r.path
for i, sn in pairs(r.stash) do
for _, sn in pairs(r.stash) do
local sv = args[sn]
if sv == nil then
sv = ''
Expand Down Expand Up @@ -1137,7 +1136,7 @@ local function add_route(self, opts, sub)

opts.match = '^' .. opts.match .. '$'

estash = nil
estash = nil -- luacheck: no unused

opts.stash = stash
opts.sub = sub
Expand Down Expand Up @@ -1196,7 +1195,7 @@ local function httpd_start(self)
local server = socket.tcp_server(self.host, self.port,
{ name = 'http',
handler = function(...)
local res = process_client(self, ...)
process_client(self, ...)
end})
if server == nil then
error(sprintf("Can't create tcp_server: %s", errno.strerror()))
Expand Down

0 comments on commit cd1e7a5

Please sign in to comment.