mirror of
https://github.com/TangentFoxy/lua-date.git
synced 2025-07-27 18:42:18 +00:00
chore(*) update linter, add makefile
This commit is contained in:
30
.luacheckrc
30
.luacheckrc
@@ -1,35 +1,31 @@
|
|||||||
--std = "ngx_lua+busted"
|
|
||||||
unused_args = false
|
unused_args = false
|
||||||
redefined = false
|
redefined = false
|
||||||
max_line_length = false
|
max_line_length = false
|
||||||
|
|
||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
--"_KONG",
|
-- "ngx",
|
||||||
--"kong",
|
|
||||||
--"ngx.IS_CLI",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
not_globals = {
|
not_globals = {
|
||||||
|
-- deprecated Lua 5.0 functions
|
||||||
"string.len",
|
"string.len",
|
||||||
"table.getn",
|
"table.getn",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_files = {
|
||||||
ignore = {
|
"**/*.lua",
|
||||||
--"6.", -- ignore whitespace warnings
|
"**/*.rockspec",
|
||||||
|
".busted",
|
||||||
|
".luacheckrc",
|
||||||
}
|
}
|
||||||
|
|
||||||
include_files = {
|
files["spec/**/*.lua"] = {
|
||||||
"**/*.lua",
|
std = "+busted",
|
||||||
"*.rockspec",
|
|
||||||
".busted",
|
|
||||||
".luacheckrc",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exclude_files = {
|
exclude_files = {
|
||||||
"here/**",
|
-- The Github Actions Lua Environment
|
||||||
"samples/**",
|
".lua",
|
||||||
|
".luarocks",
|
||||||
|
".install",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
91
Makefile
Normal file
91
Makefile
Normal 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
37
date-dev-1.rockspec
Normal 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" },
|
||||||
|
}
|
31
rockspecs/date-2.1.3-1.rockspec
Normal file
31
rockspecs/date-2.1.3-1.rockspec
Normal 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" },
|
||||||
|
}
|
||||||
|
|
@@ -8,21 +8,21 @@ arg:
|
|||||||
|
|
||||||
local date = require"date"
|
local date = require"date"
|
||||||
|
|
||||||
function makemonth(y,m)
|
local function makemonth(y,m)
|
||||||
local t = {}
|
local t = {}
|
||||||
local d = date(y,m,1)
|
local d = date(y,m,1)
|
||||||
t.name = d:fmt("%B")
|
t.name = d:fmt("%B")
|
||||||
t.year = y
|
t.year = y
|
||||||
-- get back to the nearest sunday
|
-- get back to the nearest sunday
|
||||||
d:adddays(-(d:getweekday()-1))
|
d:adddays(-(d:getweekday()-1))
|
||||||
repeat
|
repeat
|
||||||
local tt = {}
|
local tt = {}
|
||||||
table.insert(t,tt)
|
table.insert(t,tt)
|
||||||
repeat -- insert the week days
|
repeat -- insert the week days
|
||||||
table.insert(tt, d:getday())
|
table.insert(tt, d:getday())
|
||||||
until d:adddays(1):getweekday() == 1
|
until d:adddays(1):getweekday() == 1
|
||||||
until d:getmonth() ~= m
|
until d:getmonth() ~= m
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local htm_foot = '\n</html>'
|
local htm_foot = '\n</html>'
|
||||||
@@ -39,16 +39,16 @@ 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_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_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>'
|
local htm_yearfoot = '\n</table>'
|
||||||
function makecalendar(y, iox)
|
local function makecalendar(y, iox)
|
||||||
iox:write(htm_yearhead)
|
iox:write(htm_yearhead)
|
||||||
for i = 1, 12 do
|
for i = 1, 12 do
|
||||||
local tm = makemonth(y, i)
|
local tm = makemonth(y, i)
|
||||||
iox:write(string.format(htm_monhead, tm.name, tm.year))
|
iox:write(string.format(htm_monhead, tm.name, tm.year))
|
||||||
for k, v in ipairs(tm) do
|
for k, v in ipairs(tm) do
|
||||||
iox:write(string.format(htm_monweek, v[1], v[2], v[3], v[4], v[5], v[6], v[7]))
|
iox:write(string.format(htm_monweek, v[1], v[2], v[3], v[4], v[5], v[6], v[7]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
iox:write(htm_yearfoot)
|
iox:write(htm_yearfoot)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -12,17 +12,17 @@ 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_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_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>]]
|
local htm_yearfoot = [[</table>]]
|
||||||
function makecalendar(year, iow)
|
local function makecalendar(year, iow)
|
||||||
local d = date():setisoyear(year,1,1)
|
local d = date():setisoyear(year,1,1)
|
||||||
iow(htm_yearhead)
|
iow(htm_yearhead)
|
||||||
iow("<!--".. d .. "-->\n")
|
iow("<!--".. d .. "-->\n")
|
||||||
while d:getisoyear() == year do
|
while d:getisoyear() == year do
|
||||||
iow(d:fmt("<tr><td>%G</td><td>%V<br/><small class='s'>%Y-%j</small></td>"))
|
iow(d:fmt("<tr><td>%G</td><td>%V<br/><small class='s'>%Y-%j</small></td>"))
|
||||||
repeat iow(d:fmt("<td>%u<br/><small class='s'>%b %d %Y</small></td>"))
|
repeat iow(d:fmt("<td>%u<br/><small class='s'>%b %d %Y</small></td>"))
|
||||||
until d:adddays(1):getisoweekday() == 1
|
until d:adddays(1):getisoweekday() == 1
|
||||||
iow("</tr>\n")
|
iow("</tr>\n")
|
||||||
end
|
end
|
||||||
iow(htm_yearfoot)
|
iow(htm_yearfoot)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -120,8 +120,8 @@ describe("Testing the 'date' module", function()
|
|||||||
local c = date("20131230 00:57:04") -- same as a
|
local c = date("20131230 00:57:04") -- same as a
|
||||||
assert(a < b)
|
assert(a < b)
|
||||||
assert(a <= b)
|
assert(a <= b)
|
||||||
assert(not (a > b))
|
assert(not (a > b)) -- luacheck: ignore
|
||||||
assert(not (a >= b))
|
assert(not (a >= b)) -- luacheck: ignore
|
||||||
assert(a == c)
|
assert(a == c)
|
||||||
assert(a <= c)
|
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 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()
|
a = b:copy()
|
||||||
|
|
||||||
assert(not (a > b and b < a))
|
assert(not (a > b and b < a))
|
||||||
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
|
||||||
|
|
||||||
assert((a .. 565369) == (b .. 565369))
|
assert((a .. 565369) == (b .. 565369))
|
||||||
assert((a .. "????") == (b .. "????"))
|
assert((a .. "????") == (b .. "????"))
|
||||||
|
Reference in New Issue
Block a user