Skip to content

Commit 7f7c9a5

Browse files
authored
Merge pull request #2021 from joto/lua-checks-and-fixes
Add configuration for luacheck and run luacheck in Github actions
2 parents 62b64ea + 64e1202 commit 7f7c9a5

File tree

9 files changed

+71
-14
lines changed

9 files changed

+71
-14
lines changed

.github/workflows/luacheck.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Check Lua scripts with luacheck
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
luacheck:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Install prerequisites
13+
run: |
14+
sudo apt-get update -qq
15+
sudo apt-get install -yq --no-install-suggests --no-install-recommends lua-check
16+
17+
- name: Run luacheck
18+
run: luacheck flex-config/*.lua flex-config/gen/*.lua tests/data/*.lua tests/lua/tests.lua
19+

.luacheckrc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--
2+
-- Configuration for luacheck
3+
--
4+
-- To check Lua files call like this:
5+
-- luacheck flex-config/*.lua flex-config/gen/*.lua tests/data/*.lua tests/lua/tests.lua
6+
--
7+
8+
unused_args = false
9+
10+
stds.osm2pgsql = {
11+
read_globals = {
12+
osm2pgsql = {
13+
fields = {
14+
process_node = {
15+
read_only = false
16+
},
17+
process_way = {
18+
read_only = false
19+
},
20+
process_relation = {
21+
read_only = false
22+
},
23+
select_relation_members = {
24+
read_only = false
25+
},
26+
process_gen = {
27+
read_only = false
28+
},
29+
},
30+
other_fields = true,
31+
}
32+
}
33+
}
34+
35+
std = 'min+osm2pgsql'
36+
37+
files['tests/lua/tests.lua'].globals = { 'osm2pgsql' }
38+

tests/data/test_output_flex.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tables.route = osm2pgsql.define_table{
3737
}
3838
}
3939

40-
function is_polygon(tags)
40+
local function is_polygon(tags)
4141
if tags.aeroway
4242
or tags.amenity
4343
or tags.area

tests/data/test_output_flex_stage2.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function osm2pgsql.process_way(object)
3232
local d = w2r[object.id]
3333
if d then
3434
local refs = {}
35-
for rel_id, rel_ref in pairs(d) do
35+
for _, rel_ref in pairs(d) do
3636
refs[#refs + 1] = rel_ref
3737
end
3838
table.sort(refs)

tests/data/test_output_flex_stage2_alt.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function osm2pgsql.process_way(object)
3636
local d = w2r[object.id]
3737
if d then
3838
local refs = {}
39-
for rel_id, rel_ref in pairs(d) do
39+
for _, rel_ref in pairs(d) do
4040
refs[#refs + 1] = rel_ref
4141
end
4242
table.sort(refs)

tests/data/test_output_flex_uni.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ local table2idcol = osm2pgsql.define_table{
2020
}
2121
}
2222

23-
function is_empty(some_table)
23+
local function is_empty(some_table)
2424
return next(some_table) == nil
2525
end
2626

tests/data/test_output_flex_validgeom.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local polygons = osm2pgsql.define_table{
77
}
88
}
99

10-
function is_empty(some_table)
10+
local function is_empty(some_table)
1111
return next(some_table) == nil
1212
end
1313

tests/data/test_output_flex_way.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tables.tboth = osm2pgsql.define_way_table('osm2pgsql_test_tboth', {
2020

2121
local w2r = {}
2222

23-
function get_ids(data)
23+
local function get_ids(data)
2424
if data then
2525
local ids = {}
2626
for rel_id, _ in pairs(data) do
@@ -59,7 +59,7 @@ function osm2pgsql.process_way(object)
5959
end
6060
end
6161

62-
function way_member_ids(relation)
62+
local function way_member_ids(relation)
6363
local ids = {}
6464
for _, member in ipairs(relation.members) do
6565
if member.type == 'w' and member.role == 'mark' then

tests/lua/tests.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ do
9393
assert(tags['source:vs:source'] == nil)
9494
assert(tags['with:source:infix'] == 'keepme')
9595

96-
num = 0
96+
local num = 0
9797
for k, v in pairs(tags) do
9898
num = num + 1
9999
end
@@ -116,7 +116,7 @@ assert(osm2pgsql.trim(nil) == nil)
116116

117117
-- split_unit
118118

119-
v, u = o.split_unit('20m', '')
119+
local v, u = o.split_unit('20m', '')
120120
assert(v == 20 and u == 'm')
121121

122122
v, u = o.split_unit('20 m')
@@ -147,16 +147,16 @@ v, u = o.split_unit('-20000', 'leagues')
147147
assert(v == -20000 and u == 'leagues')
148148

149149
v, u = o.split_unit('20xx20', '')
150-
assert(v == nil)
150+
assert(v == nil and u == nil)
151151

152152
v, u = o.split_unit('20-20', '')
153-
assert(v == nil)
153+
assert(v == nil and u == nil)
154154

155155
v, u = o.split_unit('20xx20', 'foo')
156-
assert(v == nil)
156+
assert(v == nil and u == nil)
157157

158158
v, u = o.split_unit('abc', 'def')
159-
assert(v == nil)
159+
assert(v == nil and u == nil)
160160

161161
v, u = o.split_unit(nil)
162162
assert(v == nil and u == nil)
@@ -166,7 +166,7 @@ assert(v == nil and u == nil)
166166

167167
-- split_string
168168

169-
r = o.split_string('ab c;d;e f;ghi')
169+
local r = o.split_string('ab c;d;e f;ghi')
170170
assert(#r == 4)
171171
assert(r[1] == 'ab c')
172172
assert(r[2] == 'd')

0 commit comments

Comments
 (0)