Skip to content

Commit

Permalink
[ci] Add padding check for logical operators
Browse files Browse the repository at this point in the history
Modify regex, add todo for other items noticed
  • Loading branch information
claywar committed Sep 22, 2023
1 parent 9710f54 commit 8529085
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 24 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
2 changes: 1 addition & 1 deletion scripts/globals/garrison.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ xi.garrison.getAllyInfo = function(zoneID, zoneData, nationID)
allyName == nil or
allyGroupId == nil or
allyLooks == nil or
#allyLooks == 0 or
#allyLooks == 0 or
pos == nil
then
local zone = GetZone(zoneID)
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
6 changes: 3 additions & 3 deletions scripts/quests/crystalWar/Downward_Helix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- Downward Helix
-----------------------------------
-- !addquest 7 33
-- Erlene : !pos 376.936 -39.999 17.914 175
-- Indescript Markings : !pos 322 24 113 98
-- Erlene : !pos 376.936 -39.999 17.914 175
-- Indescript Markings : !pos 322 24 113 98
-----------------------------------

local quest = Quest:new(xi.quest.log_id.CRYSTAL_WAR, xi.quest.id.crystalWar.DOWNWARD_HELIX)
Expand All @@ -18,7 +18,7 @@ quest.sections =
{
check = function(player, status, vars)
return status == QUEST_AVAILABLE and
xi.quest.getVar(player, xi.quest.log_id.CRYSTAL_WAR, xi.quest.id.crystalWar.ON_SABBATICAL, 'Timer') <= VanadielUniqueDay() and
xi.quest.getVar(player, xi.quest.log_id.CRYSTAL_WAR, xi.quest.id.crystalWar.ON_SABBATICAL, 'Timer') <= VanadielUniqueDay() and
player:getMainJob() == xi.job.SCH and
player:getMainLvl() >= xi.settings.main.AF2_QUEST_LEVEL
end,
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
17 changes: 14 additions & 3 deletions tools/ci/lua_stylecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ 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,}

# lstrip current line to prevent false-positives.
# TODO: Handle lines starting with and|or, or ending with not in separate check

code_line = line.lstrip()
if re.search("\s{2,}(and|or)(\s{1,}|$)|\s{1,}(and|or)\s{2,}", code_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 +367,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 +387,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 @@ -479,8 +490,8 @@ def run_style_check(self):
for filename in glob.iglob('scripts/**/*.lua', recursive = True):
total_errors += LuaStyleCheck(filename).errcount
elif target == 'test':
total_errors = LuaStyleCheck('tools/ci/tests/stylecheck.lua', show_errors = False).errcount
expected_errors = 72
total_errors = LuaStyleCheck('tools/ci/tests/stylecheck.lua', show_errors = True).errcount
expected_errors = 77
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 8529085

Please sign in to comment.