Question

I have an application that consumes a JSON web service produced by IBM Domino. Several of the members in each object have variable names that begin with an @ symbol, like obj.@unid for example. This causes JSHint to thrown an error saying 'Unexpected @'. Is there an option that would turn this off?

Was it helpful?

Solution

I don't think an object's property names can contain an "@" symbol and not be encapsulated with quotes (just like other characters, such as "-", "+", "^", etc.).

These are all invalid:

// Invalid: SyntaxError
var obj = { @uid:123 };
console.log(obj.@uid);

// Perfectly valid
var obj = { "@uid":123 };
console.log(obj["@uid"]);

It sounds like your json webservice is not returning valid JSON in the first place by not encapsulating the names with quotes.

Now, to answer your JSHint issue (and, for others that stumble upon this for JSHint). The list of options are here: http://www.jshint.com/docs/options/ but I don't think anything will help you for this specific case.

According to the docs (http://www.jshint.com/docs/) you can hide explicit warnings by running your file with the --verbose option and adding the specific error code to the /* jshint */ options. For instance, if the following triggered:

$ jshint --verbose myfile.js
myfile.js: line 6, col 3, Unnecessary directive "use strict". (W034)

You could add that warning code to hide it:

/* jshint -W034 */

Unfortunately, your variable naming is not a warning, but an error (E024) and those "E" error codes cannot be suppressed so the above example would not work for you in this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top