skacekamen / sqflint Goto Github PK
View Code? Open in Web Editor NEWProvides basic syntax error checking for SQF language.
License: MIT License
Provides basic syntax error checking for SQF language.
License: MIT License
Input
_string = "my string ""with"" quotes";
_string2 = 'my other string "with" quotes';
Expected
Should be valid according to https://community.bistudio.com/wiki/String
Error
Exception in thread "main" cz.zipek.sqflint.parser.TokenMgrError: Lexical error at line 2, column 29. Encountered: "\"" (34), after : "\'my other string "
at cz.zipek.sqflint.parser.SQFParserTokenManager.getNextToken(SQFParserTokenManager.java:1214)
at cz.zipek.sqflint.parser.SQFParser.jj_ntk_f(SQFParser.java:1047)
at cz.zipek.sqflint.parser.SQFParser.Expression(SQFParser.java:259)
at cz.zipek.sqflint.parser.SQFParser.Expression(SQFParser.java:273)
at cz.zipek.sqflint.parser.SQFParser.Expression(SQFParser.java:273)
at cz.zipek.sqflint.parser.SQFParser.Expression(SQFParser.java:273)
at cz.zipek.sqflint.parser.SQFParser.Expression(SQFParser.java:273)
at cz.zipek.sqflint.parser.SQFParser.StatementExpression(SQFParser.java:518)
at cz.zipek.sqflint.parser.SQFParser.Statement(SQFParser.java:503)
at cz.zipek.sqflint.parser.SQFParser.BlockStatement(SQFParser.java:458)
at cz.zipek.sqflint.parser.SQFParser.CompilationUnit(SQFParser.java:55)
at cz.zipek.sqflint.linter.Linter.start(Linter.java:56)
at cz.zipek.sqflint.SQFLint.main(SQFLint.java:68)
with missionNamespace do {
//anything
};
This produces a lint error, yet syntax is correct.
Functions declared through a class with a folder name are not recognized as functions, functions are in folders that are located in the folder "functions", called according to the principle "fn_nameFunction1.sqf". LInter does not recognize them, which causes thousands of extra warnings
It would be nice if variables declared using param/params were detected
Example
params ["_var"];
hint _var;
Current Result
Warning: Possibly undefined variable _var at line 2 column 6
I think, it would be an enhancement, if you could define additional searchpaths.
#include "\x\cba\addons\main\script_macros_common.hpp"
private _testvar = QUOTE(Hello World);
With additional paths, you could check for scripts in your arma3 home directory.
This could be usefull for the sqflint.checkPaths
option too.
if-then-else expects code literals.
_then = {};
if true then _then;
The last fix of complex statements just fixed the if
statement.
But there are two more: the switch (...) do {}
and try { ... } catch { ... }
statement, which can be applied for example:
... format["%1", (
switch (true): {
case "example1": {};
...
}
)];
...
... format["%1", (
try {
...
} catch {
...
}
)];
...
Because every of those clauses/statements can return only one type of any you can use them in this commands.
It is important to know that even the engine of BI needs some ()
brackets around these statements (like the array after format []
).
I hope you can fix this.
And for me: Happy testing :)
"message": "Expected "/*", "//", ";", comment, end of line, or whitespace but "/" found.",
example class:
class Menu_Frame : RscFrame {
colorText[] = MENU_TEXT_COLOR;
colorBackground[] = MENU_BG_COLOR;
sizeEx = 0.01925 / (getResolution select 5);
x = (UI_BASE_X + 0.15) * safezoneW + safezoneX;
y = (UI_BASE_Y + 0.343) * safezoneH + safezoneY;
w = 0.1 * safezoneW;
h = 0.165 * safezoneH;
};
Token errors thrown as expcetion leak to main function without being properly handled. They should be handled same way as parse errors.
Not entirely sure what's causing this, initially I thought it was related to multiple errors, but I now believe it has something specific to do with the pattern.
When linting this code, with --json
passed to sqflint.exe, it returns the result in text, and not in JSON. If <>;
is removed from line 1, the result is properly returned in JSON.
_caller = _this select 1;<>;
_nearstuff = nearestobjects [_lc, ["landvehicle", "camanbase"], 8];qsdasrfd1234adf;'l[;a.d;[sd,c[opsalfksf'
.]';.'/d'a.d';asd['asdsd;a;sdasd;a[s/';;'d'asd/]asd
_attachedObjs = [];
<>;
):PS C:\sqflint> .\sqflint.exe --json .\testfile.sqf
Encountered " "<" "< "" at line 1, column 28.
Was expecting one of:
<EOF>
"!" ...
"not " ...
"for" ...
"if" ...
"objNull" ...
"switch" ...
"while" ...
"true" ...
"false" ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<STRING_LITERAL> ...
<STRING_LITERAL_OTHER> ...
<IDENTIFIER> ...
"(" ...
"{" ...
"[" ...
";" ...
<>;
):PS C:\sqflint> .\sqflint.exe --json .\testfile.sqf
{"line":[3,3],"column":[3,3],"type":"error","message":"Encountered \".\".\r\nWas expecting one of:\r\n \"=\" ...\r\n \">\" ...\r\n \"<\" ...\r\n \">=\" ...\r\n \"<=\" ...\r\n \"!\" ...\r\n \"not \" ...\r\n \"==\" ...\r\n \"||\" ...\r\n \"&&\" ...\r\n \"+\" ...\r\n \"-\" ...\r\n \"*\" ...\r\n \"/\" ...\r\n \"^\" ...\r\n \"%\" ...\r\n \"mod\" ...\r\n \">>\" ...\r\n \"objNull\" ...\r\n \"true\" ...\r\n \"false\" ...\r\n <INTEGER_LITERAL> ...\r\n <FLOATING_POINT_LITERAL> ...\r\n <STRING_LITERAL> ...\r\n <STRING_LITERAL_OTHER> ...\r\n <IDENTIFIER> ...\r\n \"(\" ...\r\n \"{\" ...\r\n \"[\" ...\r\n \";\" ...\r\n \"!=\" ...\r\n "}
{"line":[2,2],"column":[32,34],"type":"warning","message":"Possibly undefined variable _lc"}
Empty statements are treated as errors:
_x =
{
;
};
The error was initially caused by this:
#define DEBUG_LOG_TRACE
#define Debug_Log_Impl(mode, message) (diag_log format ['mode: %1', message])
#ifdef DEBUG_LOG_TRACE
#define Debug_LogTrace(message) Debug_Log_Impl(TRACE,message)
#else
#define Debug_LogTrace(message)
#endif
Debug_LogTrace("");
_exit =
{
endMission "END1";
};
It seems that the preprocessor flow control is ignored, and Debug_LogTrace("")
is incorrectly expanded as nothing, creating an empty statement. The empty statement in itself is of course perfectly valid.
An option to treat warnings as errors would be nice. Or an option to stop on warnings.
SQFLint doesn't correctly parse macros with arguments.
#define SVAR(name,subname) SCRIPT_##subname##_##name
SVAR(test, test) = 5;
^ ^--- error unexpected ','
\--------- warning, undefined SVAR
#define SVAR(name,subname) SCRIPT_##subname##_##name
SVAR(test, test) = 5;
should resolve into
SCRIPT_test_test = 5;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.