kayler-renslow / arma-intellij-plugin

A plugin for Intellij IDEA that allows for syntactical analysis, code inspections, and other nifty features for the SQF scripting language in Arma 3.
MIT License
41 stars 9 forks source link

Params compatibility with initialisation variables #18

Open Windmolders opened 8 years ago

Windmolders commented 8 years ago

Would it be possible to add variable initialisation recognition for parameters?

example:

_ZCP_RWB_data is marked as an UNinitialized variable

params
[
    "_ZCP_RWB_data",
    "_ZCP_RWB_boxType"
];

private _ZCP_RWB_currentCapper = _ZCP_RWB_data select 0;
kayler-renslow commented 8 years ago

It is already in place. For instance:

params [["_xb", 1]]; //initialized
params ["_hello"]; //uninitialized

The issue I suppose is finding when the param is set outside the function code, like this scenario:

[123] call {
    params ["_myvar"];
};

This gets very complex to detect. I may put in place something to detect it, but the best way of making sure your code is robust is explicitly defining your variables inside the function. (e.g. params [["_var"], 1])

BangL commented 8 years ago

if you really want your param be nil by default, you can also set nil explicitly to mute the IDE. like this: params [["_hello", nil]]; // still nil, but no warning

BangL commented 8 years ago

by the way:

and to make your functions even more robust, you should also whitelist types like this: params [["_hello", nil, ["", 0]]]; this example allows strings and numbers as first param, while still beeing unitializied by default. having no bracket there basically means "allow any type here"

kayler-renslow commented 8 years ago

There is now a check for nil values.

BangL commented 8 years ago

do you mean youre showing those as warning now as well? :O please don't ... i mean there are cases where i want nil. it was perfect in my opinion.... when i forget to set a default it warns me, and if i say explicit its nil then its fine.

BangL commented 8 years ago

but technically nil means undefined, so actually youre right. damnit