From b389c15cc56a4b9f24644902e708202d79593f5f Mon Sep 17 00:00:00 2001 From: plague006 Date: Mon, 4 Mar 2019 06:54:55 -0500 Subject: [PATCH] luacheckrc tweaks to raise warnings when registering events through script, or registering a command through commands --- .luacheckrc | 15 ++++++++++++--- map_gen/maps/dimensions.lua | 4 ++-- map_gen/maps/meteor_strike.lua | 2 +- map_gen/maps/rings_and_boxes.lua | 2 +- map_gen/shared/spawn_control.lua | 8 ++++---- utils/command.lua | 4 +++- utils/event.lua | 1 + utils/event_core.lua | 1 + utils/math.lua | 2 +- utils/table.lua | 2 +- 10 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 5194ee27..b8242326 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,3 +1,11 @@ +--[[ + This is a RedMew-customized version of Nexala's luacheckrc and differs in + the following ways: + - RedMew adds its own globals. See: globals, or search for "RedMew-specific globals" + - Removes entries for certain LuaBootstrap (aka script) functions as they should + be used through the event module +]] + ------------------------------------------------------------------------------- --[LICENSE]-- ------------------------------------------------------------------------------- @@ -180,8 +188,9 @@ stds.factorio_control = { -- @commands@: commands = { fields = { - "add_command", "commands", "game_commands", "remove_command" + "commands", "game_commands", "remove_command" }, + other_fields = false, }, -- @settings@: @@ -198,8 +207,8 @@ stds.factorio_control = { -- (http://lua-api.factorio.com/latest/LuaBootstrap.html) script = { fields = { - "on_event", "on_nth_tick", "on_configuration_changed", "on_init", "on_load", "generate_event_name", - "raise_event", "get_event_handler", "mod_name", "get_event_order" + "on_configuration_changed", "raise_event", + "get_event_handler", "mod_name", "get_event_order" }, other_fields = false, }, diff --git a/map_gen/maps/dimensions.lua b/map_gen/maps/dimensions.lua index 3ede42eb..54cd8db3 100644 --- a/map_gen/maps/dimensions.lua +++ b/map_gen/maps/dimensions.lua @@ -160,8 +160,8 @@ local function linkportals() end end -commands.add_command('linkchests', 'Select a chest to link to another. Run this command again to select the other one.', linkchests) -commands.add_command('linkportals', 'Select a portal to link to another. Run this command again to select the other one.', linkportals) +commands.add_command('linkchests', 'Select a chest to link to another. Run this command again to select the other one.', linkchests) -- luacheck: ignore +commands.add_command('linkportals', 'Select a portal to link to another. Run this command again to select the other one.', linkportals) -- luacheck: ignore Event.add(defines.events.on_tick, dim_on_tick) return Public diff --git a/map_gen/maps/meteor_strike.lua b/map_gen/maps/meteor_strike.lua index 1a264c82..d337c1ba 100644 --- a/map_gen/maps/meteor_strike.lua +++ b/map_gen/maps/meteor_strike.lua @@ -70,7 +70,7 @@ local function get_resource(x, y) return {name = name, position = {x, y}, amount = value} end -function run_combined_module(event) -- luacheck: ignore global run_combined_module +function run_combined_module(event) -- luacheck: globals run_combined_module if not global.blocks then init_blocks() end diff --git a/map_gen/maps/rings_and_boxes.lua b/map_gen/maps/rings_and_boxes.lua index faa3f700..1c40fc89 100644 --- a/map_gen/maps/rings_and_boxes.lua +++ b/map_gen/maps/rings_and_boxes.lua @@ -13,7 +13,7 @@ box = b.any{box, line} local boxes = {} for i = 0, 3 do - local b = b.rotate(box, degrees(i*90)) -- luacheck:ignore 421 + local b = b.rotate(box, degrees(i*90)) -- luacheck: ignore 421 table.insert(boxes, b) end diff --git a/map_gen/shared/spawn_control.lua b/map_gen/shared/spawn_control.lua index 2296367d..1550303b 100644 --- a/map_gen/shared/spawn_control.lua +++ b/map_gen/shared/spawn_control.lua @@ -249,9 +249,9 @@ Event.add(defines.events.on_player_joined_game, player_joined_game) Event.add(defines.events.on_player_left_game, player_left_game) Event.add(defines.events.on_player_respawned, player_respawned) -commands.add_command('tpspawn', ' teleports a player to the spawn point (Admins only)', tp_spawn_command) -commands.add_command('changespawn', ' changes the spawn point for a player (Admins only)', change_spawn_command) -commands.add_command('printspawns', 'prints info on all spawn points (Admins only)', print_spawns_command) -commands.add_command('printplayersforspawn', ' prints all the connected players for a spawn (Admins only)', print_players_for_spawn_command) +commands.add_command('tpspawn', ' teleports a player to the spawn point (Admins only)', tp_spawn_command) -- luacheck: ignore +commands.add_command('changespawn', ' changes the spawn point for a player (Admins only)', change_spawn_command) -- luacheck: ignore +commands.add_command('printspawns', 'prints info on all spawn points (Admins only)', print_spawns_command) -- luacheck: ignore +commands.add_command('printplayersforspawn', ' prints all the connected players for a spawn (Admins only)', print_players_for_spawn_command) -- luacheck: ignore return Module diff --git a/utils/command.lua b/utils/command.lua index 4768f120..d2ba3171 100644 --- a/utils/command.lua +++ b/utils/command.lua @@ -1,3 +1,4 @@ +-- luacheck: globals commands local Event = require 'utils.event' local Game = require 'utils.game' local Utils = require 'utils.core' @@ -290,7 +291,8 @@ end --- Traps command errors if not in DEBUG. if not _DEBUG then local old_add_command = commands.add_command - commands.add_command = function(name, desc, func) -- luacheck: ignore 122 + commands.add_command = + function(name, desc, func) old_add_command( name, desc, diff --git a/utils/event.lua b/utils/event.lua index 5ab5b8c7..c2246053 100644 --- a/utils/event.lua +++ b/utils/event.lua @@ -1,3 +1,4 @@ +-- luacheck: globals script --- This Module allows for registering multiple handlers to the same event, overcoming the limitation of script.register. -- -- ** Event.add(event_name, handler) ** diff --git a/utils/event_core.lua b/utils/event_core.lua index 76e5eaf9..087477d7 100644 --- a/utils/event_core.lua +++ b/utils/event_core.lua @@ -1,3 +1,4 @@ +-- luacheck: globals script -- This module exists to break the circular dependency between event.lua and global.lua. -- It is not expected that any user code would require this module instead event.lua should be required. local ErrorLogging = require 'utils.error_logging' diff --git a/utils/math.lua b/utils/math.lua index 3a4e3652..efd40d55 100644 --- a/utils/math.lua +++ b/utils/math.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global math +--luacheck: globals math local _sin = math.sin local _cos = math.cos diff --git a/utils/table.lua b/utils/table.lua index b828f8a6..1f63c7a2 100644 --- a/utils/table.lua +++ b/utils/table.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global table +--luacheck: globals table local random = math.random local floor = math.floor local remove = table.remove