Bruno
Bruno

Reputation: 9077

Javascript code not accepted by validator (JSHint)

I've written some code to display my bookmarks in IE8. To check it I've used JSHint and I get the following errors :

Does someone know why ?

my code :

var i=0;
var favString="";
var fso;



function GetFavourites(Folder)
{
var FavFolder=fso.GetFolder(Folder);
//Gets Favourite Names & URL's for given folder.
var files=new Enumerator(FavFolder.Files);
for(; !files.atEnd() ;files.moveNext())
{
var fil=files.item();
if(fil.Type=="Internet Shortcut")
{
var textReader=fso.OpenTextFile(fil.Path,1,false,-2);
var favtext=textReader.ReadAll();
var start=favtext.indexOf("URL",16);
var stop=favtext.indexOf("\n",start);
favString+=fil.Name.replace(/.url/,"");
favString+=":URL:";
//to separate favourite name & favorite URL
favString+=favtext.substring(start+4,stop-1);
favorites.innerHTML+=favString;
favString+=":NEXT:"; //to separate favorites.
i++;
}
}
//Checks any subfolder exists
var subfolders=new Enumerator(FavFolder.SubFolders);
for(; !subfolders.atEnd() ;subfolders.moveNext())
{
var folder=subfolders.item();
GetFavourites(folder.Path);
}
}

function Import()
{
try
{
fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso !==null )
{
//Create windows script shell object to access Favorites folder in user system.
var object=new ActiveXObject("WScript.Shell");
var favfolderName=object.SpecialFolders("Favorites");
if(favString==="")
{
GetFavourites(favfolderName);
}
} 
}
catch(err)
{
alert("Security settings to be modified in your browser ");
}
}

Upvotes: 3

Views: 1478

Answers (5)

Mutation Person
Mutation Person

Reputation: 30530

Enumerator and ActiveXObject are globals that are defined externally. You can tell JSHint to ignore these by putting the folllowing at the top of your JavaScript:

/*global Enumerator: false, ActiveXObject: false */

Upvotes: 6

Arvind
Arvind

Reputation: 671

I dont if this is the correct way of doing, but this works for me

"predef": ["XDomainRequest","ActiveXObject"]

I added this to my .jshintrc.

Upvotes: 0

Jad
Jad

Reputation: 932

They're both specific to IE, maybe the parser has an "IE" flag? Other than that you'll need to define them somehow if you really want your code to pass.

Upvotes: 1

otakustay
otakustay

Reputation: 12425

jslint is commonly for javascript in all browsers, not IE specified, so Enumerator and ActiveXObject or other browser specified objects are not supported.

If you are developing for IE only, just ignore these warnings.

Also, you may add Enumerator, ActiveXObject in the Predefined textbox.

Upvotes: 2

T.J. Crowder
T.J. Crowder

Reputation: 1075785

I don't see Enumerator defined anywhere, and ActiveXObject is a Microsoft extension. (Enumerator may be as well, at least in Windows Scripting Host.) JSHint checks against the specification, not vendor-specific additions.

Upvotes: 1

Related Questions