#2 Warn about undeclared variables.

closed
nobody
None
5
2006-07-10
2006-07-05
Cam Woods
No

Lint should warn about use of undeclared variables
(and therefore considered global) in methods. For
example:

function DoSomething()
{
for (i=0; ii<8; ii++)
{
msg += '.';
}

window.status = msg;
}

Is valid javascript and JavaScriptLint won't warn,
but using "i" and "msg" in this manner is dangerous
because they are considered global variables. What
should generally be implemented is more like:

function DoSomething()
{
var i;
var msg;

for (i=0; ii<8; ii++)
{
msg += '.';
}

window.status = msg;
}

Lint should warn that "i" and "msg" are undeclared
variables and will be treated as globals. I have
seen other javascript syntax checkers that issue this
warning.

Cam

Discussion

  • Cam Woods

    Cam Woods - 2006-07-05

    Logged In: YES
    user_id=1549553

    Sorry, I turned on always_use_option_explicit and am now
    getting these warnings, however I'm also getting warnings
    about methods in other .js files. It seems like Lint
    should differentiate between variables and Method calls.

     
  • Martin Harper

    Martin Harper - 2006-07-07

    Logged In: YES
    user_id=861973

    If you turn on option explicit, you will need to tell
    JavaScriptLint about the existence of methods in other
    relevant .js files.

    From http://www.javascriptlint.com/docs/index.htm :

    "If a script references a variable, function, or object from
    another script, you will need to add a /*jsl:import
    PathToOtherScript*/ comment in your script. This tells
    JavaScript Lint to check for items declared in the other
    script. Relative paths are resolved based on the path of the
    current script."

    Hope this helps.

     
  • Matthias Miller

    Matthias Miller - 2006-07-10

    Logged In: YES
    user_id=1357599

    It looks like this issue has been resolved. Thanks myreddice.

     
  • Matthias Miller

    Matthias Miller - 2006-07-10
    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks