Closed Bug 782164 Opened 12 years ago Closed 12 years ago

another false-positive "Global variable overwrite" warning

Categories

(addons.mozilla.org Graveyard :: Add-on Validation, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 724997

People

(Reporter: davemgarrett, Unassigned)

Details

Reminiscent of bug 660421.

I wrote a new extension which gets only one warning in the validator.

https://addons.mozilla.org/en-US/developers/addon/config-descriptions/file/163173/validation

The warning:
"Global variable overwrite
Warning: An attempt was made to overwrite a global variable in some JavaScript code."

The offending code, with more context than the validator gives:

for (var i in files)
{
    var lines = loadDefaultPrefsFile(files[i]);
    if (!lines)
        continue;
    var pref, donePrefComment;
    while (lines.length)
    {
        var line = lines.pop();
        if (line[0] != '/')
        {
            pref = line.split(/"/g)[1];  ////// <== the validator gets mad here
            if (defaultPrefsComments[pref])  // if there's already a comment recorded for this pref, then it was from a previously checked file; skip this one
                donePrefComment = true;
            else
                donePrefComment = false;
            var side = line.split(/\)\s*;\s*/)[1];
            if (side && side[0] == '/')  // if there's a comment to the side, parse it on the next iteration
                lines.push(side);
            continue;
        }
        else if (line.length == 0 ||               // assume everything not directly next to the pref isn't for it (at least directly)
                  line.substr(0,7) == "//@line" ||  // skip build system notes (?)
                  /pref\s*\(.*\)/.test(line) )      // skip commented out prefs (and their comments)
        {
            donePrefComment = true;
            continue;
        }
        if (!donePrefComment && pref)
        {
            line = line.replace(/(^\/\/|^\/\*|\*\/$)/g,"").trim();  // remove comment syntax ("//", "/*", & "*/")
            line = " " + line;                                      // leave in a leading space so multiline comments show correctly when fitting into one line in the tree
            if (!defaultPrefsComments[pref])
                defaultPrefsComments[pref] = line;
            else
                defaultPrefsComments[pref] = line + "\n" + defaultPrefsComments[pref];
        }
    }
}

I had run this through the validator a bit back and tried putting each of "var pref, donePrefComment;" on their own line, but it still complained.

This code is inside a bootstrap.js file, so no window to muck around in implicitly.

This is probably not that important of a bug, but I thought I might as well report it nonetheless.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → DUPLICATE
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.