Skip to content

Commit 9d5ed56

Browse files
authored
feature: add lint check (#79)
fix #78
1 parent 8115cbf commit 9d5ed56

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ dkms.conf
5454
# dev
5555
go
5656
t/servroot
57+
utils/lj-releng
5758
[\.]*

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ install:
4343
- sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
4444
- sudo apt-get update
4545
- sudo apt-get install openresty
46+
- sudo luarocks install luacheck > build.log 2>&1 || (cat build.log && exit 1)
47+
- make utils
4648
- wget https://github.com/etcd-io/etcd/releases/download/v$ETCD_VER/etcd-v$ETCD_VER-linux-amd64.tar.gz
4749
- tar xf etcd-v$ETCD_VER-linux-amd64.tar.gz
4850
# run etcd local cluster, startup at localhost:2379, localhost:22379, and localhost:32379
@@ -51,7 +53,7 @@ install:
5153

5254
script:
5355
- cd test-nginx && (sudo cpanm --notest . > build.log 2>&1 || (cat build.log && exit 1)) && cd ..
54-
- export PATH=$OPENRESTY_PREFIX/nginx/sbin:$PWD/etcd-v$ETCD_VER-linux-amd64:$PATH
56+
- export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$PWD/etcd-v$ETCD_VER-linux-amd64:$PATH
5557
- etcd --version
5658
- goreman -f ./t/$GOREMAN_CONF start > goreman.log 2>&1 &
5759
- sleep 5
@@ -61,4 +63,7 @@ script:
6163
- ./t/v3/add-auth.sh
6264
- cat goreman.log
6365
- ps -ef | grep etcd
66+
- luajit -v
67+
- luajit -v | awk '{print$2}'| grep 2.1
68+
- make lint || exit 1
6469
- make test

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,19 @@ help:
1919
@echo
2020
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'
2121

22+
### lint: Lint Lua source code
23+
.PHONY: lint
24+
lint: utils
25+
chmod a+x utils/check-lua-code-style.sh
26+
./utils/check-lua-code-style.sh
27+
28+
### utils: Installation tools
29+
.PHONY: utils
30+
utils:
31+
ifeq ("$(wildcard utils/lj-releng)", "")
32+
wget -O utils/lj-releng https://raw.githubusercontent.com/iresty/openresty-devel-utils/master/lj-releng
33+
chmod a+x utils/lj-releng
34+
endif
35+
2236
test:
2337
prove -I../test-nginx/lib -r -s t/

lib/resty/etcd/utils.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ local concat_tab = table.concat
77
local tostring = tostring
88
local select = select
99
local ipairs = ipairs
10+
local pairs = pairs
11+
local type = type
1012

1113

1214
local _M = {http = http}

lib/resty/etcd/v3.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ end
684684

685685
function _M.watchcancel(self, http_cli)
686686
local res, err = http_cli:close()
687+
-- to avoid unused variable self
688+
local _ = self
687689
return res, err
688690
end
689691

utils/check-lua-code-style.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
luacheck -q lib
6+
7+
find lib -name '*.lua' -exec ./utils/lj-releng {} + > \
8+
/tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1)
9+
10+
grep -E "ERROR.*.lua:" /tmp/check.log > /tmp/error.log | true
11+
if [ -s /tmp/error.log ]; then
12+
echo "=====bad style====="
13+
cat /tmp/check.log
14+
exit 1
15+
fi

0 commit comments

Comments
 (0)