Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQF Lint Cleanup Pass #5157

Merged
merged 8 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

TRACE_1("Reading Ammo Config",_this);
private ["_ammo", "_airFriction", "_caliber", "_bulletLength", "_bulletMass", "_transonicStabilityCoef", "_dragModel", "_ballisticCoefficients", "_velocityBoundaries", "_atmosphereModel", "_ammoTempMuzzleVelocityShifts", "_muzzleVelocityTable", "_barrelLengthTable", "_result"];
_ammoConfig = configFile >> "CfgAmmo" >> _this;
private _ammoConfig = configFile >> "CfgAmmo" >> _this;

_airFriction = getNumber(_ammoConfig >> "airFriction");
_caliber = getNumber(_ammoConfig >> "ACE_caliber");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ private _barrelLength = getNumber(_weaponConfig >> "ACE_barrelLength");

private _result = [_barrelTwist, _twistDirection, _barrelLength];

uiNamespace setVariable [format[QGVAR(%1), _weapon], _result];
uiNamespace setVariable [format[QGVAR(%1), _this], _result];

_result
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ GVAR(peakPower) = VO2MAX_STRENGTH * GVAR(VO2MaxPower);

GVAR(ae1PathwayPower) = GVAR(peakPower) / (13.3 + 16.7 + 113.3) * 13.3 * ANTPERCENT ^ 1.28 * 1.362;
GVAR(ae2PathwayPower) = GVAR(peakPower) / (13.3 + 16.7 + 113.3) * 16.7 * ANTPERCENT ^ 1.28 * 1.362;
GVAR(anPathwayPower) = GVAR(peakPower) - _ae1PathwayPower - _ae2PathwayPower;

GVAR(ppeBlackoutLast) = 100;
GVAR(lastBreath) = 0;
Expand Down
2 changes: 1 addition & 1 deletion addons/advanced_throwing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ addMissionEventHandler ["Draw3D", { // Blue is predicted before throw, red is re
drawIcon3D ["\a3\ui_f\data\gui\cfg\hints\icon_text\group_1_ca.paa", [0,0,1,1], _newTrajAGL, 1, 1, 0, "", 2];
} forEach GVAR(predictedPath);
{
_newTrajAGL = _x;
private _newTrajAGL = _x;
drawIcon3D ["\a3\ui_f\data\gui\cfg\hints\icon_text\group_1_ca.paa", [1,0,0,1], _newTrajAGL, 1, 1, 0, "", 2];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably just use _x here without _newTrajAGL

} forEach GVAR(flightPath)
}];
Expand Down
1 change: 0 additions & 1 deletion addons/attach/functions/fnc_attach.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ if (_unit == _attachToVehicle) then { //Self Attachment
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(CancelAction)], {GVAR(placeAction) = PLACE_CANCEL}];

//Display to show virtual object:
private [];
_model = getText (configFile >> "CfgAmmo" >> _itemVehClass >> "model");
if (_model == "") then {
_model = getText (configFile >> "CfgVehicles" >> _itemVehClass >> "model");
Expand Down
2 changes: 1 addition & 1 deletion addons/attach/functions/fnc_canDetach.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TRACE_2("params",_attachToVehicle,_unit);

if ((vehicle _unit) != _unit) exitWith {false};

_attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
private _attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
if ((count _attachedList) == 0) exitWith {false};

private ["_inRange"];
Expand Down
2 changes: 1 addition & 1 deletion addons/captives/functions/fnc_doEscortCaptive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (_state) then {
_unit setVariable [QGVAR(escortedUnit), _target, true];

//Add Actionmenu to release captive
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(StopEscorting)],
private _actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(StopEscorting)],
{[(_this select 0), ((_this select 0) getVariable [QGVAR(escortedUnit), objNull]), false] call FUNC(doEscortCaptive);},
nil, 20, false, true, "", QUOTE(!isNull (GETVAR(_target,QGVAR(escortedUnit),objNull)))];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (_unit == (vehicle _unit)) then {
[_unit, "ACE_AmovPercMstpScapWnonDnon", 1] call EFUNC(common,doAnimation);
};
} else {
_turretPath = [];
private _turretPath = [];
{
_x params ["_xUnit", "", "", "_xTurretPath"];
if (_unit == _xUnit) exitWith {_turretPath = _xTurretPath};
Expand Down
2 changes: 1 addition & 1 deletion addons/captives/functions/fnc_handleGetIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (local _unit) then {

if (_unit getVariable [QGVAR(isHandcuffed), false]) then {
//Need to force animation for FFV turrets
_turretPath = [];
private _turretPath = [];
{
_x params ["_xUnit", "", "", "_xTurretPath"];
if (_unit == _xUnit) exitWith {_turretPath = _xTurretPath};
Expand Down
4 changes: 2 additions & 2 deletions addons/captives/functions/fnc_handleRespawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (_respawn > 3) then {
};
[_unit, "setCaptive", QGVAR(Surrendered), false] call EFUNC(common,statusEffect_set);

if (_oldUnit getVariable [QGVAR(isEscorting), false]) then {
_oldUnit setVariable [QGVAR(isEscorting), false, true];
if (_unit getVariable [QGVAR(isEscorting), false]) then {
_unit setVariable [QGVAR(isEscorting), false, true];
};
};
4 changes: 2 additions & 2 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ GVAR(deviceKeyCurrentIndex) = -1;
["ACE3 Equipment", QGVAR(cycleDevice), (localize "STR_ACE_Common_cycleHandheldDevices"), {
[1] call FUNC(deviceKeyFindValidIndex);
if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false};
_displayName = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 0);
_iconImage = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 1);
private _displayName = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 0);
private _iconImage = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 1);
[_displayName, _iconImage] call FUNC(displayTextPicture);
true
},
Expand Down
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_checkFiles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ if (isMultiplayer) then {

_addons = _addons - GVAR(ServerAddons);
if !(_addons isEqualTo []) then {
_errorMsg = format ["Client/Server Addon Mismatch. Client has extra addons: %1.",_addons];
private _errorMsg = format ["Client/Server Addon Mismatch. Client has extra addons: %1.",_addons];

ERROR(_errorMsg);

Expand Down
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_deviceKeyFindValidIndex.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (_searchOffsetOrName isEqualType "") then {
} forEach GVAR(deviceKeyHandlingArray);
} else {
if (count GVAR(deviceKeyHandlingArray) > 0) then {
_baseIndex = [GVAR(deviceKeyCurrentIndex) + _searchOffsetOrName, 0] select (GVAR(deviceKeyCurrentIndex) == -1);
private _baseIndex = [GVAR(deviceKeyCurrentIndex) + _searchOffsetOrName, 0] select (GVAR(deviceKeyCurrentIndex) == -1);

for "_offset" from _baseIndex to (count GVAR(deviceKeyHandlingArray) - 1 + _baseIndex) do {
private _realIndex = _offset % (count GVAR(deviceKeyHandlingArray));
Expand Down
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_getDoorTurrets.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private _doorTurrets = [];

_config = [_config, _x] call FUNC(getTurretConfigPath);

if (getNumber (_config >> "isCopilot" == 0) && {count getArray (_config >> "weapons") > 0}) then {
if (((getNumber (_config >> "isCopilot")) == 0) && {count getArray (_config >> "weapons") > 0}) then {
_doorTurrets pushBack _x;
};
false
Expand Down
4 changes: 2 additions & 2 deletions addons/common/functions/fnc_getMGRSdata.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ private _altitude = getNumber (configFile >> "CfgWorlds" >> _map >> "elevationO
private _mapData = _map call FUNC(getMapData);
if (!(_mapData isEqualTo [])) then {
_lat = _mapData select 0;
_alt = _mapData select 1;
_altitude = _mapData select 1;
};
TRACE_2("Latitude and Altitude",_lat,_alt);
TRACE_2("Latitude and Altitude",_lat,_altitude);

private _UTM = [_long, _lat] call BIS_fnc_posDegToUTM;
private _easting = _UTM select 0;
Expand Down
4 changes: 2 additions & 2 deletions addons/common/functions/fnc_getMapGridData.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ while {_startGrid == _originGrid} do {
private _realOffsetY = (parseNumber (_originGrid select [count _formatX, count _formatY])) * _stepY + _heightOffset - 1;

//Calculate MGRS 10digit step - they should both be 1 meter:
_stepXat5 = _stepX * 10 ^ ((count _formatX) - 5);
_stepYat5 = -1 * _stepY * 10 ^ ((count _formatY) - 5);
private _stepXat5 = _stepX * 10 ^ ((count _formatX) - 5);
private _stepYat5 = -1 * _stepY * 10 ^ ((count _formatY) - 5);

if (_stepYat5 < 0) then {
WARNING_1("Map Grid Warning (%1) - Northing is reversed.",worldName);
Expand Down
2 changes: 1 addition & 1 deletion addons/common/functions/fnc_throttledPublicVariable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (isNil QGVAR(publishSchedId)) then {
GVAR(publishSchedId) = [{
if (diag_tickTime > GVAR(publishNextTime)) then {
{
_x params [_unit, _varName];
_x params ["_unit", "_varName"];
_unit setVariable [_varName, _unit getVariable _varName, true];
false
} count GVAR(publishVarNames);
Expand Down
2 changes: 1 addition & 1 deletion addons/common/scripts/checkVersionNumber.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if (!isServer) then {
} forEach _files;

// display and log error messages
_fnc_cutComma = {
private _fnc_cutComma = {
_string = _this;
_string = toArray _string;

Expand Down
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_firedNear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (isNil "_loudness") then {
};
} count _muzzles;
{
_ammoType = getText(configFile >> "CfgMagazines" >> _x >> "ammo");
private _ammoType = getText(configFile >> "CfgMagazines" >> _x >> "ammo");
_weaponMagazines set [_forEachIndex, [_x, _ammoType]];
} forEach _weaponMagazines;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
#include "script_component.hpp"

params ["_ars", "_elapsedTime", "_totalTime"];
params ["_args", "_elapsedTime", "_totalTime"];
_args params ["_magazineClassname", "_lastAmmoCount", "_simEvents"];

if !((_simEvents select 0) params ["_nextEventTime", "_nextEventIsBullet", "_nextEventMags"]) exitWith { ERROR("No Event"); false };
Expand Down
2 changes: 1 addition & 1 deletion addons/map/functions/fnc_compileFlashlightMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _unitLight params ["_flashlight", ""];
{[_player, _this select 2] call FUNC(switchFlashlight)}
};

_action = [_x, _displayName, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction);
private _action = [_x, _displayName, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
} forEach _flashlightItems;

Expand Down
2 changes: 1 addition & 1 deletion addons/minedetector/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ addMissionEventHandler ["Draw3D", {
GVAR(debugDetector) params ["_detectorPointAGL", "_mines"];
drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [0,0,1,1], _detectorPointAGL, 1, 1, 0, "detector", 1, 0.02, "PuristaMedium"];
{
_name = format ["%1@%2", typeOf _x, (floor ((_x distance _detectorPointAGL) * 10)) / 10];
private _name = format ["%1@%2", typeOf _x, (floor ((_x distance _detectorPointAGL) * 10)) / 10];
if ((getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> QGVAR(detectable))) == 1) then {
drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [1,0,0,1], (ASLtoAGL (getPosASL _x)), 1, 1, 0, _name, 1, 0.02, "PuristaMedium"];
} else {
Expand Down
2 changes: 1 addition & 1 deletion addons/overpressure/functions/fnc_getDistance.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private _distance = 999;

if (isNull _intersectObject) then { //Terrain:
// Calculate the angle between the terrain and the back blast direction
_angle = 90 - acos (- (_surfaceNormal vectorDotProduct _direction));
private _angle = 90 - acos (- (_surfaceNormal vectorDotProduct _direction));
TRACE_3("Terrain Intersect",_surfaceNormal,_direction,_angle);
// Angles is below 25deg, no backblast at all
if (_angle < 25) exitWith {_distance = 999};
Expand Down
2 changes: 1 addition & 1 deletion addons/repair/functions/fnc_addRepairActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _processedHitpoints = [];

// An action to remove the wheel is required
_name = format ["Remove_%1_%2", _forEachIndex, _hitpoint];
_text = localize LSTRING(RemoveWheel);
private _text = localize LSTRING(RemoveWheel);
_condition = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(canRepair)};
_statement = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(repair)};
_action = [_name, _text, _icon, _statement, _condition, {}, [_hitpoint], _position, 2] call EFUNC(interact_menu,createAction);
Expand Down
2 changes: 1 addition & 1 deletion addons/tagging/functions/fnc_tag.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private _v3 = _v2 vectorCrossProduct _v1;

TRACE_3("Reference:", _v1, _v2, _v3);

_fnc_isOk = {
private _fnc_isOk = {
params ["_rx", "_ry"];
private _startPosASL2 = _touchingPoint vectorAdd (_v2 vectorMultiply _rx) vectorAdd (_v3 vectorMultiply _ry) vectorAdd (_v1 vectorMultiply (-0.06));
private _endPosASL2 = _startPosASL2 vectorAdd (_v1 vectorMultiply (0.12));
Expand Down
63 changes: 63 additions & 0 deletions tools/sqf_linter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3

# Requires: https://github.com/LordGolias/sqf

import fnmatch
import os
import sys
import argparse
from sqf.parser import parse
import sqf.analyzer
from sqf.exceptions import SQFParserError


def analyze(filename, writer=sys.stdout):
with open(filename, 'r') as file:
code = file.read()
try:
result = parse(code)
except SQFParserError as e:
print("{}:".format(filename))
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message))
return -1

exceptions = sqf.analyzer.analyze(result).exceptions
if (exceptions):
print("{}:".format(filename))
for e in exceptions:
writer.write(' [%d,%d]:%s\n' % (e.position[0], e.position[1] - 1, e.message))
return len(exceptions)

return 0

def main():
print("#########################")
print("# Lint Check #")
print("#########################")

sqf_list = []
all_warnings = 0
all_errors = 0

parser = argparse.ArgumentParser()
parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".")
args = parser.parse_args()

for root, dirnames, filenames in os.walk('../addons' + '/' + args.module):
for filename in fnmatch.filter(filenames, '*.sqf'):
sqf_list.append(os.path.join(root, filename))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 space instead of 4 space indentation.


for filename in sqf_list:
ret = analyze(filename)
if (ret < 0):
all_errors = all_errors + 1
else:
all_warnings = all_warnings + ret

print ("Parse Errors {0} - Warnings {1}".format(all_errors,all_warnings))

# return (all_errors + all_warnings)
return all_errors

if __name__ == "__main__":
main()