Skip to content

Commit f820893

Browse files
committed
Add luacheck integration
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
1 parent 72dd860 commit f820893

File tree

7 files changed

+91
-9
lines changed

7 files changed

+91
-9
lines changed

.github/workflows/check_on_push.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Static analysis
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
static-analysis:
9+
if: |
10+
github.event_name == 'push' ||
11+
github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@master
15+
16+
- name: Setup Tarantool
17+
uses: tarantool/setup-tarantool@v1
18+
with:
19+
tarantool-version: '2.8'
20+
21+
- name: Setup luacheck
22+
run: tarantoolctl rocks install luacheck 0.25.0
23+
24+
- run: cmake -S . -B build
25+
26+
- name: Run luacheck
27+
run: make -C build luacheck

.luacheckrc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
std = "luajit"
2+
globals = {"box", "_TARANTOOL", "tonumber64", "utf8"}
3+
ignore = {
4+
-- Accessing an undefined field of a global variable <debug>.
5+
"143/debug",
6+
-- Accessing an undefined field of a global variable <os>.
7+
"143/os",
8+
-- Accessing an undefined field of a global variable <string>.
9+
"143/string",
10+
-- Accessing an undefined field of a global variable <table>.
11+
"143/table",
12+
-- Unused argument <self>.
13+
"212/self",
14+
-- Redefining a local variable.
15+
"411",
16+
-- Redefining an argument.
17+
"412",
18+
-- Shadowing a local variable.
19+
"421",
20+
-- Shadowing an upvalue.
21+
"431",
22+
-- Shadowing an upvalue argument.
23+
"432",
24+
}
25+
26+
include_files = {
27+
"**/*.lua",
28+
}
29+
30+
exclude_files = {
31+
"build/**/*.lua",
32+
".rocks/**/*.lua",
33+
".git/**/*.lua",
34+
"http/mime_types.lua",
35+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1717
- Replace Travis CI with Github Actions.
1818
- Add workflow that publish rockspec.
1919
- Add editorconfig to configure indentation.
20+
- Add luacheck integration.
2021

2122
### Fixed
2223

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ endif()
77
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
88

99
find_package(LuaTest)
10+
find_package(LuaCheck)
1011

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

1920
add_subdirectory(http)
2021

22+
add_custom_target(luacheck
23+
COMMAND ${LUACHECK} ${PROJECT_SOURCE_DIR}
24+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
25+
COMMENT "Run luacheck"
26+
)
27+
2128
add_custom_target(luatest
2229
COMMAND ${LUATEST} -v
2330
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ align="right">
55

66
# HTTP server for Tarantool 1.7.5+
77

8+
[![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)
89
[![Test](https://github.com/tarantool/http/actions/workflows/test.yml/badge.svg)](https://github.com/tarantool/http/actions/workflows/test.yml)
910

1011
> **Note:** In Tarantool 1.7.5+, a full-featured HTTP client is available aboard.

cmake/FindLuaCheck.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
find_program(LUACHECK luacheck
2+
HINTS .rocks/
3+
PATH_SUFFIXES bin
4+
DOC "Lua static analyzer"
5+
)
6+
7+
include(FindPackageHandleStandardArgs)
8+
find_package_handle_standard_args(LuaCheck
9+
REQUIRED_VARS LUACHECK
10+
)
11+
12+
mark_as_advanced(LUACHECK)

http/server.lua

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ local function request_content_type(self)
163163
end
164164

165165
local function post_param(self, name)
166-
local content_type = self:content_type()
167166
if self:content_type() == 'multipart/form-data' then
168167
-- TODO: do that!
169168
rawset(self, 'post_params', {})
@@ -213,7 +212,7 @@ local function catfile(...)
213212
return
214213
end
215214

216-
for i, pe in pairs(sp) do
215+
for _, pe in pairs(sp) do
217216
if path == nil then
218217
path = pe
219218
elseif string.match(path, '.$') ~= '/' then
@@ -441,7 +440,7 @@ local function render(tx, opts)
441440
return resp
442441
end
443442

444-
local function iterate(tx, gen, param, state)
443+
local function iterate(_, gen, param, state)
445444
return setmetatable({ body = { gen = gen, param = param, state = state } },
446445
response_mt)
447446
end
@@ -837,7 +836,7 @@ local function process_client(self, s, peer)
837836
};
838837
for k, v in pairs(hdrs) do
839838
if type(v) == 'table' then
840-
for i, sv in pairs(v) do
839+
for _, sv in pairs(v) do
841840
table.insert(response, sprintf("%s: %s\r\n", ucfirst(k), sv))
842841
end
843842
else
@@ -857,7 +856,7 @@ local function process_client(self, s, peer)
857856
if not s:write(response) then
858857
break
859858
end
860-
response = nil
859+
response = nil -- luacheck: no unused
861860
-- Transfer-Encoding: chunked
862861
for _, part in gen, param, state do
863862
part = tostring(part)
@@ -916,7 +915,7 @@ local function match_route(self, method, route)
916915
local fit
917916
local stash = {}
918917

919-
for k, r in pairs(self.routes) do
918+
for _, r in pairs(self.routes) do
920919
if r.method == method or r.method == 'ANY' then
921920
local m = { string.match(route, r.match) }
922921
local nfit
@@ -980,7 +979,7 @@ local function url_for_route(r, args, query)
980979
args = {}
981980
end
982981
local name = r.path
983-
for i, sn in pairs(r.stash) do
982+
for _, sn in pairs(r.stash) do
984983
local sv = args[sn]
985984
if sv == nil then
986985
sv = ''
@@ -1137,7 +1136,7 @@ local function add_route(self, opts, sub)
11371136

11381137
opts.match = '^' .. opts.match .. '$'
11391138

1140-
estash = nil
1139+
estash = nil -- luacheck: no unused
11411140

11421141
opts.stash = stash
11431142
opts.sub = sub
@@ -1196,7 +1195,7 @@ local function httpd_start(self)
11961195
local server = socket.tcp_server(self.host, self.port,
11971196
{ name = 'http',
11981197
handler = function(...)
1199-
local res = process_client(self, ...)
1198+
process_client(self, ...)
12001199
end})
12011200
if server == nil then
12021201
error(sprintf("Can't create tcp_server: %s", errno.strerror()))

0 commit comments

Comments
 (0)