eslint 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/config.js CHANGED
@@ -92,12 +92,18 @@ function loadConfig(filePath) {
92
92
  * @returns {Object} the local config object (empty object if there is no local config)
93
93
  */
94
94
  function getLocalConfig(helper, directory) {
95
- var localConfigFile = helper.findLocalConfigFile(directory),
96
- config = {};
95
+ var localConfigFile,
96
+ config = {},
97
+ parentDirectory;
97
98
 
98
- /* istanbul ignore else Too complicated to create unittest*/
99
- if (localConfigFile) {
100
- config = loadConfig(localConfigFile);
99
+ while ((localConfigFile = helper.findLocalConfigFile(directory))) {
100
+ config = util.mergeConfigs(loadConfig(localConfigFile), config);
101
+
102
+ parentDirectory = path.dirname(directory);
103
+ if (directory === parentDirectory) {
104
+ break;
105
+ }
106
+ directory = parentDirectory;
101
107
  }
102
108
 
103
109
  return config;
package/lib/eslint.js CHANGED
@@ -354,7 +354,9 @@ module.exports = (function() {
354
354
  currentScopes = null,
355
355
  currentFilename = null,
356
356
  controller = null,
357
- reportingConfig = [];
357
+ reportingConfig = [],
358
+ commentLocsEnter = [],
359
+ commentLocsExit = [];
358
360
 
359
361
  /**
360
362
  * Parses text into an AST. Moved out here because the try-catch prevents
@@ -396,6 +398,46 @@ module.exports = (function() {
396
398
  }
397
399
  }
398
400
 
401
+ /**
402
+ * Check collection of comments to prevent double event for comment as
403
+ * leading and trailing, then emit event if passing
404
+ * @param {ASTNode[]} comments Collection of comment nodes
405
+ * @param {Object[]} locs List of locations of previous comment nodes
406
+ * @param {string} eventName Event name postfix
407
+ * @returns {void}
408
+ */
409
+ function emitComments(comments, locs, eventName) {
410
+
411
+ if (comments.length) {
412
+ comments.forEach(function(node) {
413
+ if (locs.indexOf(node.loc) >= 0) {
414
+ locs.splice(locs.indexOf(node.loc), 1);
415
+ } else {
416
+ locs.push(node.loc);
417
+ api.emit(node.type + eventName, node);
418
+ }
419
+ });
420
+ }
421
+ }
422
+
423
+ /**
424
+ * Shortcut to check and emit enter of comment nodes
425
+ * @param {ASTNode[]} comments Collection of comment nodes
426
+ * @returns {void}
427
+ */
428
+ function emitCommentsEnter(comments) {
429
+ emitComments(comments, commentLocsEnter, "Comment");
430
+ }
431
+
432
+ /**
433
+ * Shortcut to check and emit exit of comment nodes
434
+ * @param {ASTNode[]} comments Collection of comment nodes
435
+ * @returns {void}
436
+ */
437
+ function emitCommentsExit(comments) {
438
+ emitComments(comments, commentLocsExit, "Comment:exit");
439
+ }
440
+
399
441
  // set unlimited listeners (see https://github.com/eslint/eslint/issues/524)
400
442
  api.setMaxListeners(0);
401
443
 
@@ -412,6 +454,8 @@ module.exports = (function() {
412
454
  currentScopes = null;
413
455
  controller = null;
414
456
  reportingConfig = [];
457
+ commentLocsEnter = [];
458
+ commentLocsExit = [];
415
459
  };
416
460
 
417
461
  /**
@@ -512,46 +556,20 @@ module.exports = (function() {
512
556
  controller.traverse(ast, {
513
557
  enter: function(node, parent) {
514
558
 
515
- var comments = api.getComments(node),
516
- leadingComments = comments.leading,
517
- trailingComments = comments.trailing;
518
-
519
- if (leadingComments.length) {
520
- leadingComments.forEach(function(node) {
521
- api.emit(node.type + "Comment", node);
522
- });
523
- }
559
+ var comments = api.getComments(node);
524
560
 
561
+ emitCommentsEnter(comments.leading);
525
562
  node.parent = parent;
526
-
527
563
  api.emit(node.type, node);
528
-
529
- if (trailingComments.length) {
530
- trailingComments.forEach(function(node) {
531
- api.emit(node.type + "Comment", node);
532
- });
533
- }
534
-
564
+ emitCommentsEnter(comments.trailing);
535
565
  },
536
566
  leave: function(node) {
537
567
 
538
- var comments = api.getComments(node),
539
- leadingComments = comments.leading,
540
- trailingComments = comments.trailing;
541
-
542
- if (trailingComments.length) {
543
- trailingComments.forEach(function(node) {
544
- api.emit(node.type + "Comment:exit", node);
545
- });
546
- }
568
+ var comments = api.getComments(node);
547
569
 
570
+ emitCommentsExit(comments.trailing);
548
571
  api.emit(node.type + ":exit", node);
549
-
550
- if (leadingComments.length) {
551
- leadingComments.forEach(function(node) {
552
- api.emit(node.type + "Comment:exit", node);
553
- });
554
- }
572
+ emitCommentsExit(comments.leading);
555
573
  }
556
574
  });
557
575
 
@@ -678,7 +696,7 @@ module.exports = (function() {
678
696
  return null;
679
697
  }
680
698
 
681
- switch(node.type) {
699
+ switch (node.type) {
682
700
  case "FunctionDeclaration":
683
701
  return findJSDocComment(node.leadingComments);
684
702
 
@@ -708,7 +726,7 @@ module.exports = (function() {
708
726
  api.getTokensBefore = function(node, beforeCount) {
709
727
  var beforeTokens = [], cursor = node.range[0] - 1;
710
728
  while (beforeCount > 0 && cursor >= 0) {
711
- if(currentTokens[cursor]) {
729
+ if (currentTokens[cursor]) {
712
730
  beforeTokens.unshift(currentTokens[cursor]);
713
731
  --beforeCount;
714
732
  }
@@ -744,7 +762,7 @@ module.exports = (function() {
744
762
  api.getTokensAfter = function(node, afterCount) {
745
763
  var afterTokens = [], cursor = node.range[1];
746
764
  while (afterCount > 0 && cursor < currentTokens.length) {
747
- if(currentTokens[cursor]) {
765
+ if (currentTokens[cursor]) {
748
766
  afterTokens.push(currentTokens[cursor]);
749
767
  --afterCount;
750
768
  cursor = currentTokens[cursor].range[1];
@@ -786,7 +804,7 @@ module.exports = (function() {
786
804
  tokens = [],
787
805
  cursor = node.range[0];
788
806
  while (cursor < node.range[1]) {
789
- if(currentTokens[cursor]) {
807
+ if (currentTokens[cursor]) {
790
808
  tokens.push(currentTokens[cursor]);
791
809
  cursor = currentTokens[cursor].range[1];
792
810
  } else {
@@ -805,7 +823,7 @@ module.exports = (function() {
805
823
  api.getFirstTokens = function(node, count) {
806
824
  var tokens = [], cursor = node.range[0];
807
825
  while (count > 0 && cursor < node.range[1]) {
808
- if(currentTokens[cursor]) {
826
+ if (currentTokens[cursor]) {
809
827
  tokens.push(currentTokens[cursor]);
810
828
  --count;
811
829
  cursor = currentTokens[cursor].range[1];
@@ -843,7 +861,7 @@ module.exports = (function() {
843
861
  api.getLastTokens = function(node, count) {
844
862
  var tokens = [], cursor = node.range[1] - 1;
845
863
  while (count > 0 && cursor >= node.range[0]) {
846
- if(currentTokens[cursor]) {
864
+ if (currentTokens[cursor]) {
847
865
  tokens.unshift(currentTokens[cursor]);
848
866
  --count;
849
867
  }
@@ -25,7 +25,7 @@ function getMessageType(message, rules) {
25
25
 
26
26
  function xmlEscape(s) {
27
27
  return ("" + s).replace(/[<>&"']/g, function(c) {
28
- switch(c) {
28
+ switch (c) {
29
29
  case "<":
30
30
  return "&lt;";
31
31
  case ">":
@@ -36,6 +36,7 @@ function xmlEscape(s) {
36
36
  return "&quot;";
37
37
  case "'":
38
38
  return "&apos;";
39
+ // no default
39
40
  }
40
41
  });
41
42
  }
@@ -96,6 +96,12 @@ module.exports = function(context) {
96
96
  declare(["arguments"]);
97
97
  }
98
98
 
99
+ function variableDeclarationHandler(node) {
100
+ declare(node.declarations.map(function(decl) {
101
+ return decl.id.name;
102
+ }));
103
+ }
104
+
99
105
  return {
100
106
  "Program": function() {
101
107
  scopeStack = [context.getScope().variables.map(function(v) {
@@ -108,9 +114,7 @@ module.exports = function(context) {
108
114
  pushScope();
109
115
  statements.forEach(function(stmt) {
110
116
  if (stmt.type === "VariableDeclaration") {
111
- declare(stmt.declarations.map(function(decl) {
112
- return decl.id.name;
113
- }));
117
+ variableDeclarationHandler(stmt);
114
118
  } else if (stmt.type === "FunctionDeclaration") {
115
119
  declare([stmt.id.name]);
116
120
  }
@@ -123,13 +127,30 @@ module.exports = function(context) {
123
127
  pushScope();
124
128
  declare([node.param.name]);
125
129
  },
130
+ "CatchClause:exit": popScope,
126
131
 
127
132
  "FunctionDeclaration": functionHandler,
128
- "FunctionExpression": functionHandler,
129
-
130
133
  "FunctionDeclaration:exit": popScope,
134
+
135
+ "FunctionExpression": functionHandler,
131
136
  "FunctionExpression:exit": popScope,
132
137
 
138
+ "ForStatement": function(node) {
139
+ pushScope();
140
+ if (node.init && node.init.type === "VariableDeclaration") {
141
+ variableDeclarationHandler(node.init);
142
+ }
143
+ },
144
+ "ForStatement:exit": popScope,
145
+
146
+ "ForInStatement": function(node) {
147
+ pushScope();
148
+ if (node.left.type === "VariableDeclaration") {
149
+ variableDeclarationHandler(node.left);
150
+ }
151
+ },
152
+ "ForInStatement:exit": popScope,
153
+
133
154
  "Identifier": function(node) {
134
155
  var ancestor = context.getAncestors().pop();
135
156
  if (isDeclaration(node, ancestor) || isProperty(node, ancestor)) {
@@ -34,7 +34,7 @@ module.exports = function(context) {
34
34
  [].forEach.call(blockProperties, function(blockProp) {
35
35
  var block = node[blockProp], previousToken, curlyToken;
36
36
  block = node[blockProp];
37
- if(block && block.type === "BlockStatement") {
37
+ if (block && block.type === "BlockStatement") {
38
38
  previousToken = context.getTokenBefore(block);
39
39
  curlyToken = context.getFirstToken(block);
40
40
 
@@ -127,7 +127,7 @@ module.exports = function(context) {
127
127
  */
128
128
  function checkSwitchStatement(node) {
129
129
  var tokens;
130
- if(node.cases && node.cases.length) {
130
+ if (node.cases && node.cases.length) {
131
131
  tokens = context.getTokensBefore(node.cases[0], 2);
132
132
  if (tokens[0].loc.start.line !== tokens[1].loc.start.line) {
133
133
  context.report(node, OPEN_MESSAGE);
@@ -36,6 +36,10 @@ module.exports = function(context) {
36
36
  return;
37
37
  }
38
38
 
39
+ if (context.options[0] === "allow-null" && isNullCheck(node)) {
40
+ return;
41
+ }
42
+
39
43
  if (operator === "==") {
40
44
  context.report(node, "Expected '===' and instead saw '=='.");
41
45
  } else if (operator === "!=") {
@@ -22,7 +22,7 @@ module.exports = function(context) {
22
22
  constructorName = node.callee.name;
23
23
  }
24
24
 
25
- if (constructorName && constructorName.charAt(0) === constructorName.charAt(0).toLowerCase()) {
25
+ if (constructorName && constructorName.charAt(0) !== constructorName.charAt(0).toUpperCase()) {
26
26
  context.report(node, "A constructor name should start with an uppercase letter.");
27
27
  }
28
28
  }
@@ -22,7 +22,7 @@ module.exports = function(context) {
22
22
  lastItem = items[items.length - 1];
23
23
  // The last token in an object/array literal will always be a closing
24
24
  // curly, so we check the second to last token for a comma.
25
- if(secondToLastToken.value === "," && items.length && lastItem) {
25
+ if (secondToLastToken.value === "," && items.length && lastItem) {
26
26
  context.report(lastItem, secondToLastToken.loc.start, "Trailing comma.");
27
27
  }
28
28
  }
@@ -23,7 +23,7 @@ module.exports = function(context) {
23
23
  * @private
24
24
  */
25
25
  function isConstant(node) {
26
- switch(node.type) {
26
+ switch (node.type) {
27
27
  case "Literal":
28
28
  case "FunctionExpression":
29
29
  case "ObjectExpression":
@@ -38,6 +38,7 @@ module.exports = function(context) {
38
38
  return isConstant(node.right);
39
39
  case "SequenceExpression":
40
40
  return isConstant(node.expressions[node.expressions.length - 1]);
41
+ // no default
41
42
  }
42
43
  return false;
43
44
  }
@@ -30,7 +30,7 @@ module.exports = function(context) {
30
30
 
31
31
  function precedence(node) {
32
32
 
33
- switch(node.type) {
33
+ switch (node.type) {
34
34
  case "SequenceExpression":
35
35
  return 0;
36
36
 
@@ -41,16 +41,17 @@ module.exports = function(context) {
41
41
  return 3;
42
42
 
43
43
  case "LogicalExpression":
44
- switch(node.operator) {
44
+ switch (node.operator) {
45
45
  case "||":
46
46
  return 4;
47
47
  case "&&":
48
48
  return 5;
49
+ // no default
49
50
  }
50
51
 
51
52
  /* falls through */
52
53
  case "BinaryExpression":
53
- switch(node.operator) {
54
+ switch (node.operator) {
54
55
  case "|":
55
56
  return 6;
56
57
  case "^":
@@ -80,6 +81,7 @@ module.exports = function(context) {
80
81
  case "/":
81
82
  case "%":
82
83
  return 13;
84
+ // no default
83
85
  }
84
86
  /* falls through */
85
87
  case "UnaryExpression":
@@ -94,6 +96,7 @@ module.exports = function(context) {
94
96
  return 16;
95
97
  case "NewExpression":
96
98
  return 17;
99
+ // no default
97
100
  }
98
101
  return 18;
99
102
  }
@@ -103,22 +106,22 @@ module.exports = function(context) {
103
106
  }
104
107
 
105
108
  function dryUnaryUpdate(node) {
106
- if(isParenthesised(node.argument) && precedence(node.argument) >= precedence(node)) {
109
+ if (isParenthesised(node.argument) && precedence(node.argument) >= precedence(node)) {
107
110
  report(node.argument);
108
111
  }
109
112
  }
110
113
 
111
114
  function dryCallNew(node) {
112
- if(isParenthesised(node.callee) && precedence(node.callee) >= precedence(node)) {
115
+ if (isParenthesised(node.callee) && precedence(node.callee) >= precedence(node)) {
113
116
  report(node.callee);
114
117
  }
115
- if(node.arguments.length === 1) {
116
- if(isParenthesisedTwice(node.arguments[0]) && precedence(node.arguments[0]) >= precedence({type: "AssignmentExpression"})) {
118
+ if (node.arguments.length === 1) {
119
+ if (isParenthesisedTwice(node.arguments[0]) && precedence(node.arguments[0]) >= precedence({type: "AssignmentExpression"})) {
117
120
  report(node.arguments[0]);
118
121
  }
119
122
  } else {
120
123
  [].forEach.call(node.arguments, function(arg){
121
- if(isParenthesised(arg) && precedence(arg) >= precedence({type: "AssignmentExpression"})) {
124
+ if (isParenthesised(arg) && precedence(arg) >= precedence({type: "AssignmentExpression"})) {
122
125
  report(arg);
123
126
  }
124
127
  });
@@ -127,10 +130,10 @@ module.exports = function(context) {
127
130
 
128
131
  function dryBinaryLogical(node) {
129
132
  var prec = precedence(node);
130
- if(isParenthesised(node.left) && precedence(node.left) >= prec) {
133
+ if (isParenthesised(node.left) && precedence(node.left) >= prec) {
131
134
  report(node.left);
132
135
  }
133
- if(isParenthesised(node.right) && precedence(node.right) > prec) {
136
+ if (isParenthesised(node.right) && precedence(node.right) > prec) {
134
137
  report(node.right);
135
138
  }
136
139
  }
@@ -138,69 +141,69 @@ module.exports = function(context) {
138
141
  return {
139
142
  "ArrayExpression": function(node) {
140
143
  [].forEach.call(node.elements, function(e) {
141
- if(e && isParenthesised(e) && precedence(e) >= precedence({type: "AssignmentExpression"})) {
144
+ if (e && isParenthesised(e) && precedence(e) >= precedence({type: "AssignmentExpression"})) {
142
145
  report(e);
143
146
  }
144
147
  });
145
148
  },
146
149
  "AssignmentExpression": function(node) {
147
- if(isParenthesised(node.right) && precedence(node.right) >= precedence(node)) {
150
+ if (isParenthesised(node.right) && precedence(node.right) >= precedence(node)) {
148
151
  report(node.right);
149
152
  }
150
153
  },
151
154
  "BinaryExpression": dryBinaryLogical,
152
155
  "CallExpression": dryCallNew,
153
156
  "ConditionalExpression": function(node) {
154
- if(isParenthesised(node.test) && precedence(node.test) >= precedence({type: "LogicalExpression", operator: "||"})) {
157
+ if (isParenthesised(node.test) && precedence(node.test) >= precedence({type: "LogicalExpression", operator: "||"})) {
155
158
  report(node.test);
156
159
  }
157
- if(isParenthesised(node.consequent) && precedence(node.consequent) >= precedence({type: "AssignmentExpression"})) {
160
+ if (isParenthesised(node.consequent) && precedence(node.consequent) >= precedence({type: "AssignmentExpression"})) {
158
161
  report(node.consequent);
159
162
  }
160
- if(isParenthesised(node.alternate) && precedence(node.alternate) >= precedence({type: "AssignmentExpression"})) {
163
+ if (isParenthesised(node.alternate) && precedence(node.alternate) >= precedence({type: "AssignmentExpression"})) {
161
164
  report(node.alternate);
162
165
  }
163
166
  },
164
167
  "DoWhileStatement": function(node) {
165
- if(isParenthesisedTwice(node.test)) {
168
+ if (isParenthesisedTwice(node.test)) {
166
169
  report(node.test);
167
170
  }
168
171
  },
169
172
  "ExpressionStatement": function(node) {
170
173
  var firstToken;
171
- if(isParenthesised(node.expression)) {
174
+ if (isParenthesised(node.expression)) {
172
175
  firstToken = context.getFirstToken(node.expression);
173
- if(firstToken.value !== "function" && firstToken.value !== "{") {
176
+ if (firstToken.value !== "function" && firstToken.value !== "{") {
174
177
  report(node.expression);
175
178
  }
176
179
  }
177
180
  },
178
181
  "ForInStatement": function(node) {
179
- if(isParenthesised(node.right)) {
182
+ if (isParenthesised(node.right)) {
180
183
  report(node.right);
181
184
  }
182
185
  },
183
186
  "ForStatement": function(node) {
184
- if(node.init && isParenthesised(node.init)) {
187
+ if (node.init && isParenthesised(node.init)) {
185
188
  report(node.init);
186
189
  }
187
190
 
188
- if(node.test && isParenthesised(node.test)) {
191
+ if (node.test && isParenthesised(node.test)) {
189
192
  report(node.test);
190
193
  }
191
194
 
192
- if(node.update && isParenthesised(node.update)) {
195
+ if (node.update && isParenthesised(node.update)) {
193
196
  report(node.update);
194
197
  }
195
198
  },
196
199
  "IfStatement": function(node) {
197
- if(isParenthesisedTwice(node.test)) {
200
+ if (isParenthesisedTwice(node.test)) {
198
201
  report(node.test);
199
202
  }
200
203
  },
201
204
  "LogicalExpression": dryBinaryLogical,
202
205
  "MemberExpression": function(node) {
203
- if(
206
+ if (
204
207
  isParenthesised(node.object) &&
205
208
  precedence(node.object) >= precedence(node) &&
206
209
  (
@@ -219,52 +222,52 @@ module.exports = function(context) {
219
222
  "ObjectExpression": function(node) {
220
223
  [].forEach.call(node.properties, function(e) {
221
224
  var v = e.value;
222
- if(v && isParenthesised(v) && precedence(v) >= precedence({type: "AssignmentExpression"})) {
225
+ if (v && isParenthesised(v) && precedence(v) >= precedence({type: "AssignmentExpression"})) {
223
226
  report(v);
224
227
  }
225
228
  });
226
229
  },
227
230
  "ReturnStatement": function(node) {
228
- if(node.argument && isParenthesised(node.argument)) {
231
+ if (node.argument && isParenthesised(node.argument)) {
229
232
  report(node.argument);
230
233
  }
231
234
  },
232
235
  "SequenceExpression": function(node) {
233
236
  [].forEach.call(node.expressions, function(e) {
234
- if(isParenthesised(e) && precedence(e) >= precedence(node)) {
237
+ if (isParenthesised(e) && precedence(e) >= precedence(node)) {
235
238
  report(e);
236
239
  }
237
240
  });
238
241
  },
239
242
  "SwitchCase": function(node) {
240
- if(node.test && isParenthesised(node.test)) {
243
+ if (node.test && isParenthesised(node.test)) {
241
244
  report(node.test);
242
245
  }
243
246
  },
244
247
  "SwitchStatement": function(node) {
245
- if(isParenthesisedTwice(node.discriminant)) {
248
+ if (isParenthesisedTwice(node.discriminant)) {
246
249
  report(node.discriminant);
247
250
  }
248
251
  },
249
252
  "ThrowStatement": function(node) {
250
- if(isParenthesised(node.argument)) {
253
+ if (isParenthesised(node.argument)) {
251
254
  report(node.argument);
252
255
  }
253
256
  },
254
257
  "UnaryExpression": dryUnaryUpdate,
255
258
  "UpdateExpression": dryUnaryUpdate,
256
259
  "VariableDeclarator": function(node) {
257
- if(node.init && isParenthesised(node.init) && precedence(node.init) >= precedence({type: "AssignmentExpression"})) {
260
+ if (node.init && isParenthesised(node.init) && precedence(node.init) >= precedence({type: "AssignmentExpression"})) {
258
261
  report(node.init);
259
262
  }
260
263
  },
261
264
  "WhileStatement": function(node) {
262
- if(isParenthesisedTwice(node.test)) {
265
+ if (isParenthesisedTwice(node.test)) {
263
266
  report(node.test);
264
267
  }
265
268
  },
266
269
  "WithStatement": function(node) {
267
- if(isParenthesisedTwice(node.object)) {
270
+ if (isParenthesisedTwice(node.object)) {
268
271
  report(node.object);
269
272
  }
270
273
  }
@@ -37,7 +37,7 @@ module.exports = function(context) {
37
37
  var useStrictDirectives, scope;
38
38
  useStrictDirectives = directives(node).filter(isStrict);
39
39
 
40
- switch(useStrictDirectives.length) {
40
+ switch (useStrictDirectives.length) {
41
41
  case 0:
42
42
  break;
43
43
 
@@ -25,6 +25,14 @@ module.exports = function(context) {
25
25
  comments,
26
26
  comment;
27
27
 
28
+ /*
29
+ * Some developers wrap case bodies in blocks, so if there is just one
30
+ * node and it's a block statement, check inside.
31
+ */
32
+ if (consequent.length === 1 && consequent[0].type === "BlockStatement") {
33
+ consequent = consequent[0];
34
+ }
35
+
28
36
  // checking on previous case
29
37
  if (!switchData.lastCaseClosed) {
30
38
 
@@ -15,9 +15,9 @@ module.exports = function(context) {
15
15
  }
16
16
 
17
17
  function check(node) {
18
- if(node.callee.type === "Identifier" && node.callee.name === "RegExp" && isString(node.arguments[0])) {
18
+ if (node.callee.type === "Identifier" && node.callee.name === "RegExp" && isString(node.arguments[0])) {
19
19
  try {
20
- if(isString(node.arguments[1])) {
20
+ if (isString(node.arguments[1])) {
21
21
  void new RegExp(node.arguments[0].value, node.arguments[1].value);
22
22
  } else {
23
23
  void new RegExp(node.arguments[0].value);
@@ -127,7 +127,7 @@ module.exports = function(context) {
127
127
  var found = {};
128
128
 
129
129
  declarations.forEach(function (declaration) {
130
- if(getDeclarationType(declaration.init) === DECL_REQUIRE) {
130
+ if (getDeclarationType(declaration.init) === DECL_REQUIRE) {
131
131
  found[inferModuleType(declaration.init)] = true;
132
132
  }
133
133
  });
@@ -13,7 +13,7 @@ module.exports = function(context) {
13
13
  var RESTRICTED = ["undefined", "NaN", "Infinity", "arguments", "eval"];
14
14
 
15
15
  function checkForViolation(id) {
16
- if(RESTRICTED.indexOf(id.name) > -1) {
16
+ if (RESTRICTED.indexOf(id.name) > -1) {
17
17
  context.report(id, "Shadowing of global property \"" + id.name + "\".");
18
18
  }
19
19
  }
@@ -23,7 +23,7 @@ module.exports = function(context) {
23
23
  checkForViolation(node.id);
24
24
  },
25
25
  "FunctionExpression": function(node) {
26
- if(node.id) {
26
+ if (node.id) {
27
27
  checkForViolation(node.id);
28
28
  }
29
29
  [].map.call(node.params, checkForViolation);
@@ -39,7 +39,7 @@ module.exports = function(context) {
39
39
  });
40
40
  }
41
41
 
42
- while(upper) {
42
+ while (upper) {
43
43
  findDups(variables);
44
44
  upper = upper.upper;
45
45
  }
@@ -15,7 +15,7 @@ module.exports = function(context) {
15
15
  var i, token, hasArgumentList = false, numOpen = 0;
16
16
 
17
17
  // start at the end of the token stream; skip over argument list contents
18
- for(i = tokens.length - 1; i >= 0; --i) {
18
+ for (i = tokens.length - 1; i >= 0; --i) {
19
19
  token = tokens[i];
20
20
  if (token.value === "(") {
21
21
  --numOpen;
@@ -14,7 +14,7 @@ module.exports = function(context) {
14
14
  return {
15
15
  "VariableDeclaration": function(node) {
16
16
  node.declarations.reduce(function(memo, decl) {
17
- if(decl.id.name < memo.id.name) {
17
+ if (decl.id.name < memo.id.name) {
18
18
  context.report(decl, "Variables within the same declaration block should be sorted alphabetically");
19
19
  return memo;
20
20
  } else {
@@ -19,9 +19,9 @@ module.exports = function(context) {
19
19
 
20
20
  function isSpaced(left, right) {
21
21
  var op, tokens = context.getTokens({range: [left.range[1], right.range[0]]}, 1, 1);
22
- for(var i = 1, l = tokens.length - 1; i < l; ++i) {
22
+ for (var i = 1, l = tokens.length - 1; i < l; ++i) {
23
23
  op = tokens[i];
24
- if(
24
+ if (
25
25
  op.type === "Punctuator" &&
26
26
  OPERATORS.indexOf(op.value) >= 0 &&
27
27
  (tokens[i - 1].range[1] >= op.range[0] || op.range[1] >= tokens[i + 1].range[0])
@@ -34,9 +34,9 @@ module.exports = function(context) {
34
34
 
35
35
  function isRightSpaced(left, right) {
36
36
  var op, tokens = context.getTokens({range: [left.range[1], right.range[0]]}, 1, 1);
37
- for(var i = 1, l = tokens.length - 1; i < l; ++i) {
37
+ for (var i = 1, l = tokens.length - 1; i < l; ++i) {
38
38
  op = tokens[i];
39
- if(
39
+ if (
40
40
  op.type === "Punctuator" &&
41
41
  OPERATORS.indexOf(op.value) >= 0 &&
42
42
  op.range[1] >= tokens[i + 1].range[0]
@@ -52,14 +52,14 @@ module.exports = function(context) {
52
52
  }
53
53
 
54
54
  function checkBinary(node) {
55
- if(!isSpaced(node.left, node.right)) {
55
+ if (!isSpaced(node.left, node.right)) {
56
56
  report(node);
57
57
  }
58
58
  }
59
59
 
60
60
  function checkSequence(node) {
61
- for(var i = 0, l = node.expressions.length - 1; i < l; ++i) {
62
- if(!isRightSpaced(node.expressions[i], node.expressions[i + 1])) {
61
+ for (var i = 0, l = node.expressions.length - 1; i < l; ++i) {
62
+ if (!isRightSpaced(node.expressions[i], node.expressions[i + 1])) {
63
63
  report(node);
64
64
  break;
65
65
  }
@@ -67,13 +67,13 @@ module.exports = function(context) {
67
67
  }
68
68
 
69
69
  function checkConditional(node) {
70
- if(!isSpaced(node.test, node.consequent) || !isSpaced(node.consequent, node.alternate)) {
70
+ if (!isSpaced(node.test, node.consequent) || !isSpaced(node.consequent, node.alternate)) {
71
71
  report(node);
72
72
  }
73
73
  }
74
74
 
75
75
  function checkVar(node) {
76
- if(node.init && !isSpaced(node.id, node.init)) {
76
+ if (node.init && !isSpaced(node.id, node.init)) {
77
77
  report(node);
78
78
  }
79
79
  }
@@ -14,19 +14,19 @@ module.exports = function(context) {
14
14
  var tokens = context.getFirstTokens(node, 2),
15
15
  value = tokens[0].value;
16
16
 
17
- if(tokens[0].range[1] >= tokens[1].range[0]) {
17
+ if (tokens[0].range[1] >= tokens[1].range[0]) {
18
18
  context.report(node, "Keyword \"" + value + "\" must be followed by whitespace.");
19
19
  }
20
20
  }
21
21
 
22
22
  return {
23
23
  "ReturnStatement": function(node) {
24
- if(node.argument) {
24
+ if (node.argument) {
25
25
  check(node);
26
26
  }
27
27
  },
28
28
  "SwitchCase": function(node) {
29
- if(node.test) {
29
+ if (node.test) {
30
30
  check(node);
31
31
  }
32
32
  },
@@ -13,14 +13,15 @@ module.exports = function(context) {
13
13
  function check(node) {
14
14
  var tokens;
15
15
  tokens = context.getFirstTokens(node, 2);
16
- if(tokens[0].range[1] >= tokens[1].range[0]) {
17
- switch(tokens[0].value) {
16
+ if (tokens[0].range[1] >= tokens[1].range[0]) {
17
+ switch (tokens[0].value) {
18
18
  case "delete":
19
19
  case "new":
20
20
  case "typeof":
21
21
  case "void":
22
22
  context.report(node, "Unary word operator \"" + tokens[0].value + "\" must be followed by whitespace.");
23
23
  break;
24
+ // no default
24
25
  }
25
26
  }
26
27
  }
@@ -129,6 +129,7 @@ module.exports = function(context) {
129
129
  hasConstructor = true;
130
130
  break;
131
131
 
132
+ // no default
132
133
  }
133
134
 
134
135
  // check tag preferences
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An Esprima-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -55,7 +55,7 @@
55
55
  "browserify": "~3.20.0",
56
56
  "mocha-phantomjs": "~3.3.1",
57
57
  "phantomjs": "~1.9.2-6",
58
- "eslint-tester": "latest",
58
+ "eslint-tester": "^0.1.0",
59
59
  "brfs": "0.0.9",
60
60
  "through": "~2.3.4",
61
61
  "beefy": "~1.0.0",