Permalink
Browse files

Tolerate __dirname and __filename even in node environment even when …

…nomen is set. Closes #197
  • Loading branch information...
1 parent 5dfca02 commit 3c77ac7a4edfd24c150d1f690825f60e1cd470fc @valueof valueof committed Aug 15, 2011
Showing with 23 additions and 2 deletions.
  1. +4 −2 jshint.js
  2. +19 −0 tests/envs.js
View
@@ -1029,8 +1029,10 @@ var JSHINT = (function () {
line, from, value);
} else if (option.nomen && (value.charAt(0) === '_' ||
value.charAt(value.length - 1) === '_')) {
- warningAt("Unexpected {a} in '{b}'.", line, from,
- "dangling '_'", value);
+ if (!option.node || token.id == '.' ||
+ (value != '__dirname' && value != '__filename')) {
+ warningAt("Unexpected {a} in '{b}'.", line, from, "dangling '_'", value);
+ }
}
}
t.value = value;
View
@@ -59,6 +59,25 @@ exports.node = function () {
assert.globalsImplied(globals);
assert.globalsKnown(globals, { node: true });
+
+ // Make sure that the `node` option doesn't conflict with `nomen`
+ var asGlobals = [
+ 'console.log(__dirname);',
+ 'console.log(__filename);'
+ ];
+
+ var asProps = [
+ 'console.log(a.__dirname);',
+ 'console.log(a.__filename);',
+ 'console.log(__hello);'
+ ];
+
+ assert.ok(JSHINT(asGlobals, { node: true, nomen: true }));
+ assert.ok(!JSHINT(asProps, { node: true, nomen: true }));
+ assert.eql(JSHINT.errors.length, 3);
+ assert.eql(JSHINT.errors[0].reason, "Unexpected dangling '_' in '__dirname'.");
+ assert.eql(JSHINT.errors[1].reason, "Unexpected dangling '_' in '__filename'.");
+ assert.eql(JSHINT.errors[2].reason, "Unexpected dangling '_' in '__hello'.");
};
/** Option `jquery` predefines jQuery globals */

0 comments on commit 3c77ac7

Please sign in to comment.