Skip to content

Commit

Permalink
[ci] Add padding check for logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
claywar committed Sep 22, 2023
1 parent 9710f54 commit 0b4f2c9
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion scripts/commands/addlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ commandObj.onTrigger = function(player, light, amount, target)

local selectedLight = tostring(light)

if lightType[selectedLight] == nil or selectedLight == nil then
if lightType[selectedLight] == nil or selectedLight == nil then
error(player, 'Invalid light type.\nValid light types: pearl, azure, ruby, amber, gold, silver, ebon')
return
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/missions/wotg/04_The_Queen_of_the_Dance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ mission.sections =
-- 0: Try to enter without a ticket
{
check = function(player, currentMission, missionStatus, vars)
return currentMission == mission.missionId and missionStatus == 0
and xi.wotg.helpers.meetsMission4Reqs(player)
return currentMission == mission.missionId and missionStatus == 0 and
xi.wotg.helpers.meetsMission4Reqs(player)
end,

[xi.zone.SOUTHERN_SAN_DORIA_S] =
Expand Down
4 changes: 2 additions & 2 deletions scripts/quests/ahtUrhgan/Promotion_Superior_Private.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ quest.sections =
{
{
check = function(player, status, vars)
return status == QUEST_AVAILABLE and player:getCharVar('AssaultPromotion') >= 25
and player:getQuestStatus(xi.quest.log_id.AHT_URHGAN, xi.quest.id.ahtUrhgan.PROMOTION_PRIVATE_FIRST_CLASS) == QUEST_COMPLETED
return status == QUEST_AVAILABLE and player:getCharVar('AssaultPromotion') >= 25 and
player:getQuestStatus(xi.quest.log_id.AHT_URHGAN, xi.quest.id.ahtUrhgan.PROMOTION_PRIVATE_FIRST_CLASS) == QUEST_COMPLETED
end,

[xi.zone.AHT_URHGAN_WHITEGATE] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ entity.onMobRoam = function(mob)

for _, doorID in ipairs(escort.doors) do
local npc = GetNPCByID(doorID)
if doorID ~= openedDoor and mob:checkDistance(npc) <= 8 then
if doorID ~= openedDoor and mob:checkDistance(npc) <= 8 then
npc:setAnimation(xi.animation.OPEN_DOOR)
mob:setLocalVar('opened_door', doorID)
end
Expand Down
12 changes: 7 additions & 5 deletions scripts/zones/Rolanberry_Fields/npcs/Saarlan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ entity.onTrigger = function(player, npc)
elseif player:getCharVar('LegionStatus') == 1 then
local maximus = player:hasKeyItem(xi.ki.LEGION_TOME_PAGE_MAXIMUS) and 1 or 0
local minimus = player:hasKeyItem(xi.ki.LEGION_TOME_PAGE_MINIMUS) and 1 or 0

-- TODO: Table these and iterate
local title =
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_LOFTY) and 1 or 0) +
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_MIRED) and 2 or 0) +
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_SOARING) and 4 or 0) +
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_VEILED) and 8 or 0) +
(player:hasTitle(xi.title.LEGENDARY_LEGIONNAIRE) and 16 or 0)
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_LOFTY) and 1 or 0) +
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_MIRED) and 2 or 0) +
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_SOARING) and 4 or 0) +
(player:hasTitle(xi.title.SUBJUGATOR_OF_THE_VEILED) and 8 or 0) +
(player:hasTitle(xi.title.LEGENDARY_LEGIONNAIRE) and 16 or 0)

player:startEvent(8005, 0, title, maximus, player:getCurrency('legion_point'), minimus)
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/zones/Sea_Serpent_Grotto/npcs/_4w3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ entity.onTrigger = function(player, npc)
local zPos = player:getZPos()
local mythrilDoorCheck = player:getCharVar('SSG_MythrilDoor')

if xPos >= 40 and zPos >= 15 then
if xPos >= 40 and zPos >= 15 then
if mythrilDoorCheck == 0 then -- Door has never been checked
player:messageSpecial(ID.text.FIRST_CHECK)
player:setCharVar('SSG_MythrilDoor', 1)
Expand Down
10 changes: 5 additions & 5 deletions scripts/zones/Yuhtunga_Jungle/npcs/qm2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ local ID = zones[xi.zone.YUHTUNGA_JUNGLE]
local entity = {}

local function isFightInProgress()
return GetMobByID(ID.mob.NASUS_OFFSET):isAlive()
or GetMobByID(ID.mob.NASUS_OFFSET + 1):isAlive()
or GetMobByID(ID.mob.NASUS_OFFSET + 2):isAlive()
or GetMobByID(ID.mob.NASUS_OFFSET + 3):isAlive()
or GetMobByID(ID.mob.NASUS_OFFSET + 4):isAlive()
return GetMobByID(ID.mob.NASUS_OFFSET):isAlive() or
GetMobByID(ID.mob.NASUS_OFFSET + 1):isAlive() or
GetMobByID(ID.mob.NASUS_OFFSET + 2):isAlive() or
GetMobByID(ID.mob.NASUS_OFFSET + 3):isAlive() or
GetMobByID(ID.mob.NASUS_OFFSET + 4):isAlive()
end

local function spawnNMs(player)
Expand Down
11 changes: 9 additions & 2 deletions tools/ci/lua_stylecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ def check_parameter_padding(self, line):
for _ in re.finditer(",[^ \n]", line):
self.error("Multiple parameters used without an appropriate following space or newline")

def check_conditional_padding(self, line):
# \s{2,}(and|or)\s{1,}|\s{1,}(and|or)\s{2,}

if re.search("\s{2,}(and|or)\s{1,}|\s{1,}(and|or)\s{2,}", line):
self.error("Multiple spaces detected around logical operator.")

def check_semicolon(self, line):
"""No semi-colons should be used in Lua scripts.
Expand Down Expand Up @@ -357,7 +363,7 @@ def run_style_check(self):
self.error("Standard comment block lines of '-' should be 35 characters.")

# Remove in-line comments
code_line = re.sub("(?=--)(.*?)(?=\r\n|\n)", "", line)
code_line = re.sub("(?=--)(.*?)(?=\r\n|\n)", "", line).rstrip()

# Before replacing strings, see if we're only using single quotes and check requires
if re.search(r"\"[^\"']*\"(?=(?:[^']*'[^']*')*[^']*$)", code_line):
Expand All @@ -377,6 +383,7 @@ def run_style_check(self):
self.check_variable_names(code_line)
self.check_semicolon(code_line)
self.check_indentation(code_line)
self.check_conditional_padding(code_line)
self.check_operator_padding(code_line)
self.check_parentheses_padding(code_line)
self.check_no_single_line_functions(code_line)
Expand Down Expand Up @@ -480,7 +487,7 @@ def run_style_check(self):
total_errors += LuaStyleCheck(filename).errcount
elif target == 'test':
total_errors = LuaStyleCheck('tools/ci/tests/stylecheck.lua', show_errors = False).errcount
expected_errors = 72
expected_errors = 76
else:
total_errors = LuaStyleCheck(target).errcount

Expand Down
7 changes: 7 additions & 0 deletions tools/ci/tests/stylecheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,10 @@ require('scripts/zones/Bastok_Markets/IDs') -- FAIL
-- Bad:
-------------------------------------
---------------------------------

this and this -- PASS
this or this -- PASS
this and -- FAIL
this and this -- FAIL
this or -- FAIL
this or this -- FAIL

0 comments on commit 0b4f2c9

Please sign in to comment.