Skip to content

Commit a2a81f0

Browse files
committed
ci: add linting step with LuaCheck to GitHub Actions
1 parent b412b62 commit a2a81f0

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

.github/workflows/deploy.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ on:
77
pull_request:
88

99
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install LuaJIT and LuaRocks
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y luajit luarocks
20+
21+
- name: Install luacheck
22+
run: sudo luarocks install luacheck
23+
24+
- name: Run LuaCheck
25+
run: make lint
26+
1027
test-unit:
1128
runs-on: ubuntu-latest
1229
steps:

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ test:
1818
done
1919

2020
test-e2e:
21-
@go test -v ./...
21+
@go test -v ./...
22+
23+
lint:
24+
luacheck --std ngx_lua ./lib/
25+
luacheck -g ./test/

lib/resty/libjwt/cached.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local cached = {}
22

33
local instance = nil
44

5-
function cached:getInstance()
5+
function cached.getInstance()
66
if not instance then
77
instance = {
88
data = {}

lib/resty/libjwt/decode.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function _M.jwt(jwt)
1414
return nil, err
1515
end
1616

17-
local payload, err = b64.decode_base64url(payload_b64)
17+
local payload
18+
payload, err = b64.decode_base64url(payload_b64)
1819
if err then
1920
return nil, err
2021
end

lib/resty/libjwt/init.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local cached = require("resty.libjwt.cached")
44
local decode = require("resty.libjwt.decode")
55
local cjson = require("cjson.safe")
66
local _M = {}
7+
local ngx = ngx
78

89
local open = io.open
910
function _M.read_file(path)
@@ -15,20 +16,23 @@ function _M.read_file(path)
1516
end
1617

1718
local TOKEN_VALID = 0
18-
function _M.validate(params)
19-
local params, err = utils.get_params(params)
19+
function _M.validate(user_params)
20+
local params, err = utils.get_params(user_params)
2021
if params == nil then
2122
return false, _M.response_error(err, false)
2223
end
2324
if err ~= "" then
2425
return false, _M.response_error(err, params.return_unauthorized_default)
2526
end
2627
local headers = ngx.req.get_headers()
27-
local token, err = utils.get_token(headers, params.header_token)
28+
29+
local token
30+
token, err = utils.get_token(headers, params.header_token)
2831
if err ~= "" then
2932
return false, _M.response_error(err, params.return_unauthorized_default)
3033
end
31-
local parsed_token, err = decode.jwt(token)
34+
local parsed_token
35+
parsed_token, err = decode.jwt(token)
3236
if err ~= nil then
3337
return nil, _M.response_error(err, params.return_unauthorized_default)
3438
end
@@ -37,7 +41,7 @@ function _M.validate(params)
3741
end
3842

3943
local files_cached = cached:getInstance()
40-
for i, jwks_file in ipairs(params.jwks_files) do
44+
for _, jwks_file in ipairs(params.jwks_files) do
4145
local file
4246
if files_cached:get(jwks_file) == nil then
4347
file = _M.read_file(jwks_file)

0 commit comments

Comments
 (0)