chore(*) update linter, add makefile

This commit is contained in:
Thijs Schreijer
2023-09-06 16:52:54 +02:00
parent ebbdef7593
commit b8147d8e6b
8 changed files with 212 additions and 57 deletions

View File

@@ -1,35 +1,31 @@
--std = "ngx_lua+busted"
unused_args = false
redefined = false
max_line_length = false
globals = {
--"_KONG",
--"kong",
--"ngx.IS_CLI",
-- "ngx",
}
not_globals = {
-- deprecated Lua 5.0 functions
"string.len",
"table.getn",
}
ignore = {
--"6.", -- ignore whitespace warnings
}
include_files = {
"**/*.lua",
"*.rockspec",
"**/*.rockspec",
".busted",
".luacheckrc",
}
exclude_files = {
"here/**",
"samples/**",
files["spec/**/*.lua"] = {
std = "+busted",
}
exclude_files = {
-- The Github Actions Lua Environment
".lua",
".luarocks",
".install",
}

91
Makefile Normal file
View File

@@ -0,0 +1,91 @@
# additional Busted options to pass
BUSTED:=
# SCM rockspec label; scm/cvs/dev
SCM_LABEL:=$(shell cat *.rockspec | grep "local package_version" | sed "s/ //g" | sed "s/localpackage_version=//g" | sed "s/\"//g")
ROCK_REV:=$(shell cat *.rockspec | grep "local rockspec_revision" | sed "s/ //g" | sed "s/localrockspec_revision=//g" | sed "s/\"//g")
ROCK_NAME:=$(shell cat *.rockspec | grep "local package_name" | sed "s/ //g" | sed "s/localpackage_name=//g" | sed "s/\"//g")
ROCKSPEC:=${ROCK_NAME}-${SCM_LABEL}-${ROCK_REV}.rockspec
TAB=$(shell printf "\t")
# dev/test dependencies; versions can be pinned. Example: "ldoc 1.4.6"
DEV_ROCKS = "busted" "luacheck" "luacov"
target_not_specified: help
@exit 1
help:
@echo "Available make targets for ${ROCK_NAME}:"
@echo ""
@echo "install: uses LuaRocks to install ${ROCK_NAME}"
@echo "uninstall: uninstalls ALL versions of ${ROCK_NAME} (using LuaRocks with"
@echo " the '--force' flag)"
@echo "clean: removes LuaCov output and packed rocks"
@echo "test: runs the test suite using Busted"
@echo "testinst: installs ${ROCK_NAME} and runs tests using the installed version"
@echo " (this modifies the local installation, but also tests the"
@echo " .rockspec file). This is best used when testing in CI."
@echo "lint: will validate all 'rockspec' files using LuaRocks, and the"
@echo " '.lua' files with LuaCheck"
@echo "dev: installs the development dependencies (Busted, LuaCheck, etc.)"
@echo "help: displays this list of make targets"
@echo ""
install: luarocks
luarocks make
uninstall: luarocks
if (luarocks list --porcelain ${ROCK_NAME} | grep "^${ROCK_NAME}${TAB}" | grep -q "installed") ; then \
luarocks remove ${ROCK_NAME} --force; \
fi;
# note: restore the docs to the last committed version
clean: clean_luacov clean_luarocks
.PHONY: test
test: clean_luacov dev
busted ${BUSTED}
# test while having the code installed; also tests the rockspec, but
# this will modify the local luarocks installation/tree!!
.PHONY: testinst
testinst: clean_luacov dev uninstall install
busted --lpath="" --cpath="" ${BUSTED}
.PHONY: lint
lint: dev
@echo "luarocks lint ..."
@for spec in $(shell find . -type f -name "*.rockspec") ; do \
(luarocks lint $$spec && echo "$$spec [OK]") || (echo "$$spec [NOK]"; exit 1); \
done
luacheck .
.PHONY: dev
dev: luarocks
@for rock in $(DEV_ROCKS) ; do \
(luarocks list --porcelain $$rock | grep -q "installed") || (luarocks install $$rock || exit 1); \
done;
.PHONY: clean_luarocks
clean_luarocks:
$(RM) *.rock
.PHONY: clean_luacov
clean_luacov:
$(RM) luacov.report.out luacov.stats.out
.PHONY: luarocks
luarocks:
@which luarocks > /dev/null || (echo "LuaRocks was not found. Please install and/or make available in the path." && exit 1)

37
date-dev-1.rockspec Normal file
View File

@@ -0,0 +1,37 @@
local package_name = "date"
local package_version = "dev"
local rockspec_revision = "1"
local github_account_name = "Tieske"
local github_repo_name = package_name
local git_checkout = package_version == "dev" and "master" or ("version_"..package_version)
package = package_name
version = package_version .. "-" .. rockspec_revision
source = {
url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git",
branch = git_checkout
}
description = {
summary = "Date & Time module for Lua 5.x",
detailed = [[
Pure Lua Date & Time module for Lua 5.x featuring date and time string
parsing, time addition & subtraction, time span calculation, support for
ISO 8601 dates, local time support, strftime-like formatting.
]],
license = "MIT",
homepage = "https://github.com/"..github_account_name.."/"..github_repo_name,
}
dependencies = {
"lua >= 5.0, < 5.5"
}
build = {
type = "builtin",
modules = {
date = "src/date.lua"
},
copy_directories = { "docs" },
}

View File

@@ -0,0 +1,31 @@
package = "date"
version = "2.1.3-1"
description = {
summary = "Date & Time module for Lua 5.x",
detailed = [[
Pure Lua Date & Time module for Lua 5.x featuring date and time string
parsing, time addition & subtraction, time span calculation, support for
ISO 8601 dates, local time support, strftime-like formatting.
]],
license = "MIT",
homepage = "https://github.com/Tieske/date",
}
dependencies = {
"lua >= 5.0, < 5.5"
}
source = {
url = "git://github.com/Tieske/date/",
tag = "version_2.1.3",
}
build = {
type = "builtin",
modules = {
date = "src/date.lua"
},
copy_directories = { "docs" },
}

View File

@@ -8,7 +8,7 @@ arg:
local date = require"date"
function makemonth(y,m)
local function makemonth(y,m)
local t = {}
local d = date(y,m,1)
t.name = d:fmt("%B")
@@ -39,7 +39,7 @@ local htm_yearhead = '\n<table align="left">'
local htm_monhead = '\n<tr><th colspan = "7">%s, %s</th></tr><tr><td>sun</td><td>mon</td><td>tue</td><td>wed</td><td>thu</td><td>fri</td><td>sat</td></tr>'
local htm_monweek = '\n<tr><td class="sun">%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td class="sat">%s</td></tr>'
local htm_yearfoot = '\n</table>'
function makecalendar(y, iox)
local function makecalendar(y, iox)
iox:write(htm_yearhead)
for i = 1, 12 do
local tm = makemonth(y, i)

View File

@@ -12,7 +12,7 @@ local htm_foot = [[</body></html>]]
local htm_head = [[<html><head><style>body{color:#000000;background-color:#FFFFFF;font-family:sans-serif;}th{background:#000000;color:#CCCCCC;vertical-align:middle;}td{vertical-align:top;text-align:center;font-weight:bold;}.s{color:#999999;font-size:60%;}</style></head><body>]]
local htm_yearhead = [[<table align="center" width="100%" border="1"><tr><th>Year</th><th>Week</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>]]
local htm_yearfoot = [[</table>]]
function makecalendar(year, iow)
local function makecalendar(year, iow)
local d = date():setisoyear(year,1,1)
iow(htm_yearhead)
iow("<!--".. d .. "-->\n")

View File

@@ -120,8 +120,8 @@ describe("Testing the 'date' module", function()
local c = date("20131230 00:57:04") -- same as a
assert(a < b)
assert(a <= b)
assert(not (a > b))
assert(not (a >= b))
assert(not (a > b)) -- luacheck: ignore
assert(not (a >= b)) -- luacheck: ignore
assert(a == c)
assert(a <= c)
assert(a >= c)
@@ -140,13 +140,13 @@ describe("Testing the 'date' module", function()
assert(a > b and b < a)
assert(a >= b and b <= a)
assert(a ~= b and (not(a == b)))
assert(a ~= b and (not(a == b))) -- luacheck: ignore
a = b:copy()
assert(not (a > b and b < a))
assert(a >= b and b <= a)
assert(a == b and (not(a ~= b)))
assert(a == b and (not(a ~= b))) -- luacheck: ignore
assert((a .. 565369) == (b .. 565369))
assert((a .. "????") == (b .. "????"))