java sanityCheck added onlyUsedOnce
I have added a search for variables used only once to the java based sanityCheck.
The following things are read as a variable:
JavaScript:
- everything that starts with a
. - has NO digit (
0-9) in front of it - ends when there is a character that is NOT a letter or a digit
- has NO
(after it - has NO
= functionafter it
examples:
- IS a variable:
foo.bar:bar - IS a variable:
.foo.bar:fooandbar - IS a variable:
.foo[?].bar:fooandbar - IS a variable:
foo[foobar.bar]:bar - IS a variable:
${foo.bar}:bar - IS a variable:
.1: 1 - is NO variable:
foo = 10 - is NO variable:
${foo} - is NO variable:
0.1
That I am starting with a . means that local variables are ignored which is a part of hell I am not entering. .1 is detected as a variable, but you can just use 0.1 so I am fine with it.
SugarCube:
- everything that starts with a
$ - everything that starts with
_foo. - ends when there is a character that is NOT a letter or digit
- has NO
(after it
examples:
- IS a variable:
$foo:foo - IS a variable:
_foo.bar:bar - IS a variable:
$foo[$bar]:fooandbar - IS a variable:
$foo[?].bar:fooandbar - is NO variable:
_foo
I'm ignoring temporary variables as they are not the goal of this.The existing does that too so it's at least not a missing feature.
How well does it work?
I am currently finding some errors that are obviously false positives, mainly properties of objects coming from outside SugarCube, for example a.href in debugJS. Some errors are obviously correct, mainly spelling errors.
And a large quantity of errors where I am not sure whether they are correct or not. It might be helpful if the people who know a part of the code/a variable space well to download this branch, run the check and see if they find either correct errors or false positives in the part they know. I am trying to go through the errors too but it's hard without understanding the concepts.
If there are parts of the code that shouldn't be checked they can be marked with /* no-usedOnce */ and to re-enable /* usedOnce */. Note that variables in the ignored part are still counted. I am currently using that for the code that deals with BC.
@Pregmodder not sure if you want to merge it yet, since it's technically working, but throwing out a bunch possibly false positives.