WebStorm, JSLint/JSHint: exception.stack causes "Undefined variable stack"

When I have code like this for Node.js under WebStorm 3.0 #WS-111.19:

try {
} catch (e) {
  console.log(e.stack);  // Actually doing something more useful with the stack:)

JSHint complains "Undefined variable stack". "Assume Node.js" is checked in WebStorm Preferences > Project Settings > Inspections > JSLint validation. It does not complain about e.message or e.path, and autocomplete offers message and path as defined in module.js under lib in the NodeJS sources.

I tried playing with /*global ...*/, but that seems to only affect top level names, not attributes. If I change it to e['stack'], I get a warning that it's "better written in dot notation", which I like and don't want to turn off.

How can I force it into JSHint/WebStorm's head that .stack is a valid field?

On a somewhat related note, I am having kind of a similar issue with a flags parsing library (nopt in particular, but they are all similar in this respect) -- it returns a map with flag-named attributes, which I like to reference as attributes not []-style. Right now I am working around it by saying

var flags = {flag1: undefined, flag2: undefined, ...};
flags = nopt(...);

but I would much rather just say var flags = nopt(...) and somehow suppress the warning for just these fields, or just the flags var, or just the lines where I access these fields. This is a slightly different issue, because for "e.stack" in the exceptions example above I don't want to have to suppress anything, because .stack is a perfectly valid predefined field, not something dynamically assigned by a custom library -- JSHint must realize that it's there, same as it does for .message and .path.

1 comment

It seems it isn't about JSHint, because JSHint accepts all properties for any object without any restrictions.
I guess you have a problem that is depicted in the attached image - exception-stack-property.png.
If so, please file an issue about NodeJS integration -- accept e.stack if "Assume Node.js" option is checked.


Please sign in to leave a comment.