Bradley Braithwaite
Bradley Braithwaite

Reputation: 1122

JsLint4Java 'is not defined' warnings when using multiple .js files

When working with more than one .js file e.g. if I have a separate .js file that contains unit tests I start to see lots of warnings (I'm using the Eclipse plug-in) like the following where a .js file is referencing elements from another:

'<variable name>' is not defined

I can satisfy the warning and not break my code by including the following for any variables being used but are not within the physical .js file:

var myVariableReference = myVariableFromOtherFile || {};

The downside of course is that I have to keep repeating code such as the above in my unit tests files. For example as I am using a unit testing framework I would have to keep adding the inline variable 'references' for the functions that I'm using from the framework e.g:

var assertEquals = assertEquals || {}; 
var TestCase = TestCase || {};

Is there a way of configuring within eclipse so JsLint4Java scans the files as a whole? Or setting up 'Ignore' rules would be good so that I could avoid the repetitive variables as previously described.

Upvotes: 1

Views: 396

Answers (1)

Zorayr
Zorayr

Reputation: 24962

Have you tried using the undef option? You may also try to use the predef tag to define any global variables that lint should except:

<target name = "lint">
    <echo message = "Running source files through JSLint..."></echo>
    <jslint options = "newcap,vars,browser">
        <formatter type = "plain" />
        <predef>app,$,other-variables-that-are-global-go-here</predef>
        <fileset dir = "${js}" includes = "**/*.js" />
    </jslint>
</target>

Upvotes: 1

Related Questions