eslint 1.7.1 → 1.9.0

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.
Files changed (38) hide show
  1. package/README.md +1 -0
  2. package/conf/eslint.json +3 -0
  3. package/lib/cli-engine.js +74 -74
  4. package/lib/cli.js +12 -10
  5. package/lib/eslint.js +15 -26
  6. package/lib/logging.js +25 -0
  7. package/lib/options.js +7 -2
  8. package/lib/rules/array-bracket-spacing.js +2 -2
  9. package/lib/rules/arrow-body-style.js +71 -0
  10. package/lib/rules/comma-dangle.js +26 -10
  11. package/lib/rules/comma-spacing.js +72 -36
  12. package/lib/rules/eol-last.js +10 -4
  13. package/lib/rules/indent.js +8 -7
  14. package/lib/rules/key-spacing.js +13 -25
  15. package/lib/rules/linebreak-style.js +45 -10
  16. package/lib/rules/max-nested-callbacks.js +1 -1
  17. package/lib/rules/no-arrow-condition.js +88 -0
  18. package/lib/rules/no-case-declarations.js +47 -0
  19. package/lib/rules/no-extend-native.js +3 -3
  20. package/lib/rules/no-magic-numbers.js +22 -5
  21. package/lib/rules/no-mixed-spaces-and-tabs.js +23 -19
  22. package/lib/rules/no-multiple-empty-lines.js +39 -13
  23. package/lib/rules/no-plusplus.js +22 -1
  24. package/lib/rules/no-shadow.js +22 -4
  25. package/lib/rules/no-use-before-define.js +1 -1
  26. package/lib/rules/no-warning-comments.js +1 -1
  27. package/lib/rules/radix.js +36 -6
  28. package/lib/rules/space-in-parens.js +148 -199
  29. package/lib/rules/spaced-comment.js +3 -3
  30. package/lib/rules/valid-jsdoc.js +36 -19
  31. package/lib/rules.js +13 -9
  32. package/lib/testers/rule-tester.js +62 -7
  33. package/lib/util/estraverse.js +54 -0
  34. package/lib/util/glob-util.js +149 -0
  35. package/lib/util/source-code-fixer.js +1 -1
  36. package/lib/util/source-code.js +11 -1
  37. package/lib/util.js +15 -9
  38. package/package.json +21 -21
@@ -41,42 +41,6 @@ module.exports = function(context) {
41
41
  return !!token && (token.type === "Punctuator") && (token.value === ",");
42
42
  }
43
43
 
44
- /**
45
- * Reports a spacing error with an appropriate message.
46
- * @param {ASTNode} node The binary expression node to report.
47
- * @param {string} dir Is the error "before" or "after" the comma?
48
- * @returns {void}
49
- * @private
50
- */
51
- function report(node, dir) {
52
- context.report(node, options[dir] ?
53
- "A space is required " + dir + " ','." :
54
- "There should be no space " + dir + " ','.");
55
- }
56
-
57
- /**
58
- * Validates the spacing around a comma token.
59
- * @param {Object} tokens - The tokens to be validated.
60
- * @param {Token} tokens.comma The token representing the comma.
61
- * @param {Token} [tokens.left] The last token before the comma.
62
- * @param {Token} [tokens.right] The first token after the comma.
63
- * @param {Token|ASTNode} reportItem The item to use when reporting an error.
64
- * @returns {void}
65
- * @private
66
- */
67
- function validateCommaItemSpacing(tokens, reportItem) {
68
- if (tokens.left && astUtils.isTokenOnSameLine(tokens.left, tokens.comma) &&
69
- (options.before !== sourceCode.isSpaceBetweenTokens(tokens.left, tokens.comma))
70
- ) {
71
- report(reportItem, "before");
72
- }
73
- if (tokens.right && astUtils.isTokenOnSameLine(tokens.comma, tokens.right) &&
74
- (options.after !== sourceCode.isSpaceBetweenTokens(tokens.comma, tokens.right))
75
- ) {
76
- report(reportItem, "after");
77
- }
78
- }
79
-
80
44
  /**
81
45
  * Determines if a given source index is in a comment or not by checking
82
46
  * the index against the comment range. Since the check goes straight
@@ -90,6 +54,7 @@ module.exports = function(context) {
90
54
  function isIndexInComment(index, comments) {
91
55
 
92
56
  var comment;
57
+ lastCommentIndex = 0;
93
58
 
94
59
  while (lastCommentIndex < comments.length) {
95
60
 
@@ -108,6 +73,77 @@ module.exports = function(context) {
108
73
  return false;
109
74
  }
110
75
 
76
+
77
+ /**
78
+ * Reports a spacing error with an appropriate message.
79
+ * @param {ASTNode} node The binary expression node to report.
80
+ * @param {string} dir Is the error "before" or "after" the comma?
81
+ * @param {ASTNode} otherNode The node at the left or right of `node`
82
+ * @returns {void}
83
+ * @private
84
+ */
85
+ function report(node, dir, otherNode) {
86
+ context.report({
87
+ node: node,
88
+ fix: function(fixer) {
89
+ if (options[dir]) {
90
+ if (dir === "before") {
91
+ return fixer.insertTextBefore(node, " ");
92
+ } else {
93
+ return fixer.insertTextAfter(node, " ");
94
+ }
95
+ } else {
96
+ /*
97
+ * Comments handling
98
+ */
99
+ var start, end;
100
+ var newText = "";
101
+
102
+ if (dir === "before") {
103
+ start = otherNode.range[1];
104
+ end = node.range[0];
105
+ } else {
106
+ start = node.range[1];
107
+ end = otherNode.range[0];
108
+ }
109
+
110
+ for (var i = start; i < end; i++) {
111
+ if (isIndexInComment(i, allComments)) {
112
+ newText += context.getSource()[i];
113
+ }
114
+ }
115
+ return fixer.replaceTextRange([start, end], newText);
116
+ }
117
+ },
118
+ message: options[dir] ?
119
+ "A space is required " + dir + " ','." :
120
+ "There should be no space " + dir + " ','."
121
+ });
122
+ }
123
+
124
+ /**
125
+ * Validates the spacing around a comma token.
126
+ * @param {Object} tokens - The tokens to be validated.
127
+ * @param {Token} tokens.comma The token representing the comma.
128
+ * @param {Token} [tokens.left] The last token before the comma.
129
+ * @param {Token} [tokens.right] The first token after the comma.
130
+ * @param {Token|ASTNode} reportItem The item to use when reporting an error.
131
+ * @returns {void}
132
+ * @private
133
+ */
134
+ function validateCommaItemSpacing(tokens, reportItem) {
135
+ if (tokens.left && astUtils.isTokenOnSameLine(tokens.left, tokens.comma) &&
136
+ (options.before !== sourceCode.isSpaceBetweenTokens(tokens.left, tokens.comma))
137
+ ) {
138
+ report(reportItem, "before", tokens.left);
139
+ }
140
+ if (tokens.right && astUtils.isTokenOnSameLine(tokens.comma, tokens.right) &&
141
+ (options.after !== sourceCode.isSpaceBetweenTokens(tokens.comma, tokens.right))
142
+ ) {
143
+ report(reportItem, "after", tokens.right);
144
+ }
145
+ }
146
+
111
147
  /**
112
148
  * Adds null elements of the given ArrayExpression or ArrayPattern node to the ignore list.
113
149
  * @param {ASTNode} node An ArrayExpression or ArrayPattern node.
@@ -18,8 +18,10 @@ module.exports = function(context) {
18
18
 
19
19
  "Program": function checkBadEOF(node) {
20
20
  // Get the whole source code, not for node only.
21
- var src = context.getSource(), location = {column: 1};
22
-
21
+ var src = context.getSource(),
22
+ location = {column: 1},
23
+ linebreakStyle = context.options[0] || "unix",
24
+ linebreak = linebreakStyle === "unix" ? "\n" : "\r\n";
23
25
  if (src.length === 0) {
24
26
  return;
25
27
  }
@@ -32,7 +34,7 @@ module.exports = function(context) {
32
34
  loc: location,
33
35
  message: "Newline required at end of file but not found.",
34
36
  fix: function(fixer) {
35
- return fixer.insertTextAfterRange([0, src.length], "\n");
37
+ return fixer.insertTextAfterRange([0, src.length], linebreak);
36
38
  }
37
39
  });
38
40
  }
@@ -42,4 +44,8 @@ module.exports = function(context) {
42
44
 
43
45
  };
44
46
 
45
- module.exports.schema = [];
47
+ module.exports.schema = [
48
+ {
49
+ "enum": ["unix", "windows"]
50
+ }
51
+ ];
@@ -284,15 +284,16 @@ module.exports = function(context) {
284
284
  }
285
285
 
286
286
  /**
287
- * Check to see if the node arguments are spread across multiple lines
287
+ * Check to see if the argument before the callee node is multi-line and
288
+ * there should only be 1 argument before the callee node
288
289
  * @param {ASTNode} node node to check
289
290
  * @returns {boolean} True if arguments are multi-line
290
291
  */
291
- function isCallArgsMultiline(node) {
292
- var lastArg = node.arguments.length > 0 ? node.arguments[node.arguments.length - 1] : null;
292
+ function isArgBeforeCalleeNodeMultiline(node) {
293
+ var parent = node.parent;
293
294
 
294
- if (lastArg) {
295
- return lastArg.loc.end.line > node.loc.start.line;
295
+ if (parent.arguments.length >= 2 && parent.arguments[1] === node) {
296
+ return parent.arguments[0].loc.end.line > parent.arguments[0].loc.start.line;
296
297
  }
297
298
 
298
299
  return false;
@@ -337,7 +338,7 @@ module.exports = function(context) {
337
338
  indent = getNodeIndent(calleeParent);
338
339
  }
339
340
  } else {
340
- if (isCallArgsMultiline(calleeParent) &&
341
+ if (isArgBeforeCalleeNodeMultiline(calleeNode) &&
341
342
  calleeParent.callee.loc.start.line === calleeParent.callee.loc.end.line &&
342
343
  !isNodeFirstInLine(calleeNode)) {
343
344
  indent = getNodeIndent(calleeParent);
@@ -435,7 +436,7 @@ module.exports = function(context) {
435
436
  } else if (parent.loc.start.line !== node.loc.start.line && parentVarNode === parentVarNode.parent.declarations[0]) {
436
437
  nodeIndent = nodeIndent + indentSize;
437
438
  }
438
- } else if (!parentVarNode && !isFirstArrayElementOnSameLine(parent) && effectiveParent.type !== "ExpressionStatement" && effectiveParent.type !== "AssignmentExpression" && effectiveParent.type !== "Property") {
439
+ } else if (!parentVarNode && !isFirstArrayElementOnSameLine(parent) && effectiveParent.type !== "MemberExpression" && effectiveParent.type !== "ExpressionStatement" && effectiveParent.type !== "AssignmentExpression" && effectiveParent.type !== "Property") {
439
440
  nodeIndent = nodeIndent + indentSize;
440
441
  }
441
442
 
@@ -98,31 +98,13 @@ module.exports = function(context) {
98
98
  beforeColon = +!!options.beforeColon, // Defaults to false
99
99
  afterColon = +!(options.afterColon === false); // Defaults to true
100
100
 
101
- /**
102
- * Gets the first node on the same line with the provided node.
103
- * @param {ASTNode} node The node to check find from
104
- * @returns {ASTNode} the first node on the given node's line
105
- */
106
- function getFirstNodeInLine(node) {
107
- var startLine, endLine, firstToken = node;
108
-
109
- do {
110
- node = firstToken;
111
- firstToken = context.getTokenBefore(node);
112
- startLine = node.loc.start.line;
113
- endLine = firstToken ? firstToken.loc.end.line : -1;
114
- } while (startLine === endLine);
115
-
116
- return node;
117
- }
118
-
119
101
  /**
120
102
  * Starting from the given a node (a property.key node here) looks forward
121
- * until it finds the first node before a colon punctuator and returns it.
122
- * @param {ASTNode} node The node to start looking from
123
- * @returns {ASTNode} the first node before a colon punctuator
103
+ * until it finds the last token before a colon punctuator and returns it.
104
+ * @param {ASTNode} node The node to start looking from.
105
+ * @returns {ASTNode} The last token before a colon punctuator.
124
106
  */
125
- function getFirstNodeBeforeColon(node) {
107
+ function getLastTokenBeforeColon(node) {
126
108
  var prevNode;
127
109
 
128
110
  while (node && (node.type !== "Punctuator" || node.value !== ":")) {
@@ -181,9 +163,15 @@ module.exports = function(context) {
181
163
  * @returns {int} Width of the key.
182
164
  */
183
165
  function getKeyWidth(property) {
184
- var key = property.key;
185
- var startToken = getFirstNodeInLine(key);
186
- var endToken = getFirstNodeBeforeColon(key);
166
+ var startToken, endToken;
167
+
168
+ // Ignore shorthand methods and properties, as they have no colon
169
+ if (property.method || property.shorthand) {
170
+ return 0;
171
+ }
172
+
173
+ startToken = context.getFirstToken(property);
174
+ endToken = getLastTokenBeforeColon(property.key);
187
175
 
188
176
  return endToken.range[1] - startToken.range[0];
189
177
  }
@@ -13,25 +13,60 @@
13
13
  //------------------------------------------------------------------------------
14
14
 
15
15
  module.exports = function(context) {
16
+
16
17
  var EXPECTED_LF_MSG = "Expected linebreaks to be 'LF' but found 'CRLF'.",
17
18
  EXPECTED_CRLF_MSG = "Expected linebreaks to be 'CRLF' but found 'LF'.";
18
19
 
20
+ //--------------------------------------------------------------------------
21
+ // Helpers
22
+ //--------------------------------------------------------------------------
23
+
24
+ /**
25
+ * Builds a fix function that replaces text at the specified range in the source text.
26
+ * @param {int[]} range The range to replace
27
+ * @param {string} text The text to insert.
28
+ * @returns {function} Fixer function
29
+ * @private
30
+ */
31
+ function createFix(range, text) {
32
+ return function(fixer) {
33
+ return fixer.replaceTextRange(range, text);
34
+ };
35
+ }
36
+
37
+ //--------------------------------------------------------------------------
38
+ // Public
39
+ //--------------------------------------------------------------------------
40
+
19
41
  return {
20
42
  "Program": function checkForlinebreakStyle(node) {
21
43
  var linebreakStyle = context.options[0] || "unix",
22
44
  expectedLF = linebreakStyle === "unix",
23
- linebreaks = context.getSource().match(/\r\n|\r|\n|\u2028|\u2029/g),
24
- lineOfError = -1;
45
+ expectedLFChars = expectedLF ? "\n" : "\r\n",
46
+ source = context.getSource(),
47
+ pattern = /\r\n|\r|\n|\u2028|\u2029/g,
48
+ match,
49
+ index,
50
+ range;
25
51
 
26
- if (linebreaks !== null) {
27
- lineOfError = linebreaks.indexOf(expectedLF ? "\r\n" : "\n");
28
- }
52
+ var i = 0;
53
+ while ((match = pattern.exec(source)) !== null) {
54
+ i++;
55
+ if (match[0] === expectedLFChars) {
56
+ continue;
57
+ }
29
58
 
30
- if (lineOfError !== -1) {
31
- context.report(node, {
32
- line: lineOfError + 1,
33
- column: context.getSourceLines()[lineOfError].length
34
- }, expectedLF ? EXPECTED_LF_MSG : EXPECTED_CRLF_MSG);
59
+ index = match.index;
60
+ range = [index, index + match[0].length];
61
+ context.report({
62
+ node: node,
63
+ loc: {
64
+ line: i,
65
+ column: context.getSourceLines()[i - 1].length
66
+ },
67
+ message: expectedLF ? EXPECTED_LF_MSG : EXPECTED_CRLF_MSG,
68
+ fix: createFix(range, expectedLFChars)
69
+ });
35
70
  }
36
71
  }
37
72
  };
@@ -16,7 +16,7 @@ module.exports = function(context) {
16
16
  // Constants
17
17
  //--------------------------------------------------------------------------
18
18
 
19
- var THRESHOLD = context.options[0];
19
+ var THRESHOLD = context.options[0] || 10;
20
20
 
21
21
  //--------------------------------------------------------------------------
22
22
  // Helpers
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @fileoverview A rule to warn against using arrow functions in conditions.
3
+ * @author Jxck <https://github.com/Jxck>
4
+ * @copyright 2015 Luke Karrys. All rights reserved.
5
+ * The MIT License (MIT)
6
+
7
+ * Copyright (c) 2015 Jxck
8
+
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ "use strict";
29
+
30
+ //------------------------------------------------------------------------------
31
+ // Helpers
32
+ //------------------------------------------------------------------------------
33
+
34
+ /**
35
+ * Checks whether or not a node is an arrow function expression.
36
+ * @param {ASTNode} node - node to test
37
+ * @returns {boolean} `true` if the node is an arrow function expression.
38
+ */
39
+ function isArrowFunction(node) {
40
+ return node.test && node.test.type === "ArrowFunctionExpression";
41
+ }
42
+
43
+ /**
44
+ * Checks whether or not a node is a conditional expression.
45
+ * @param {ASTNode} node - node to test
46
+ * @returns {boolean} `true` if the node is a conditional expression.
47
+ */
48
+ function isConditional(node) {
49
+ return node.body && node.body.type === "ConditionalExpression";
50
+ }
51
+
52
+ //------------------------------------------------------------------------------
53
+ // Rule Definition
54
+ //------------------------------------------------------------------------------
55
+
56
+ module.exports = function(context) {
57
+ /**
58
+ * Reports if a conditional statement is an arrow function.
59
+ * @param {ASTNode} node - A node to check and report.
60
+ * @returns {void}
61
+ */
62
+ function checkCondition(node) {
63
+ if (isArrowFunction(node)) {
64
+ context.report(node, "Arrow function `=>` used inside {{statementType}} instead of comparison operator.", {statementType: node.type});
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Reports if an arrow function contains an ambiguous conditional.
70
+ * @param {ASTNode} node - A node to check and report.
71
+ * @returns {void}
72
+ */
73
+ function checkArrowFunc(node) {
74
+ if (isConditional(node)) {
75
+ context.report(node, "Arrow function used ambiguously with a conditional expression.");
76
+ }
77
+ }
78
+
79
+ return {
80
+ "IfStatement": checkCondition,
81
+ "WhileStatement": checkCondition,
82
+ "ForStatement": checkCondition,
83
+ "ConditionalExpression": checkCondition,
84
+ "ArrowFunctionExpression": checkArrowFunc
85
+ };
86
+ };
87
+
88
+ module.exports.schema = [];
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @fileoverview Rule to flag use of an lexical declarations inside a case clause
3
+ * @author Erik Arvidsson
4
+ * @copyright 2015 Erik Arvidsson. All rights reserved.
5
+ */
6
+ "use strict";
7
+
8
+ //------------------------------------------------------------------------------
9
+ // Rule Definition
10
+ //------------------------------------------------------------------------------
11
+
12
+ module.exports = function(context) {
13
+
14
+ /**
15
+ * Checks whether or not a node is a lexical declaration.
16
+ * @param {ASTNode} node A direct child statement of a switch case.
17
+ * @returns {boolean} Whether or not the node is a lexical declaration.
18
+ */
19
+ function isLexicalDeclaration(node) {
20
+ switch (node.type) {
21
+ case "FunctionDeclaration":
22
+ case "ClassDeclaration":
23
+ return true;
24
+ case "VariableDeclaration":
25
+ return node.kind !== "var";
26
+ default:
27
+ return false;
28
+ }
29
+ }
30
+
31
+ return {
32
+ "SwitchCase": function(node) {
33
+ for (var i = 0; i < node.consequent.length; i++) {
34
+ var statement = node.consequent[i];
35
+ if (isLexicalDeclaration(statement)) {
36
+ context.report({
37
+ node: node,
38
+ message: "Unexpected lexical declaration in case block."
39
+ });
40
+ }
41
+ }
42
+ }
43
+ };
44
+
45
+ };
46
+
47
+ module.exports.schema = [];
@@ -54,17 +54,17 @@ module.exports = function(context) {
54
54
  });
55
55
  },
56
56
 
57
- // handle the Object.defineProperty(Array.prototype) case
57
+ // handle the Object.definePropert[y|ies](Array.prototype) case
58
58
  "CallExpression": function(node) {
59
59
 
60
60
  var callee = node.callee,
61
61
  subject,
62
62
  object;
63
63
 
64
- // only worry about Object.defineProperty
64
+ // only worry about Object.definePropert[y|ies]
65
65
  if (callee.type === "MemberExpression" &&
66
66
  callee.object.name === "Object" &&
67
- callee.property.name === "defineProperty") {
67
+ (callee.property.name === "defineProperty" || callee.property.name === "defineProperties")) {
68
68
 
69
69
  // verify the object being added to is a native prototype
70
70
  subject = node.arguments[0];
@@ -63,15 +63,32 @@ module.exports = function(context) {
63
63
  return {
64
64
  "Literal": function(node) {
65
65
  var parent = node.parent,
66
+ value = node.value,
67
+ raw = node.raw,
66
68
  okTypes = detectObjects ? [] : ["ObjectExpression", "Property", "AssignmentExpression"];
67
69
 
68
- // don't warn on parseInt() radix
69
- if (node.parent.type === "CallExpression" && node === node.parent.arguments[1] &&
70
- node.parent.callee.name === "parseInt") {
70
+ if (!isNumber(node)) {
71
71
  return;
72
72
  }
73
73
 
74
- if (!isNumber(node) || shouldIgnoreNumber(node.value)) {
74
+ if (parent.type === "UnaryExpression" && parent.operator === "-") {
75
+ node = parent;
76
+ parent = node.parent;
77
+ value = -value;
78
+ raw = "-" + raw;
79
+ }
80
+
81
+ if (shouldIgnoreNumber(value)) {
82
+ return;
83
+ }
84
+
85
+ // don't warn on parseInt() or Number.parseInt() radix
86
+ if (parent.type === "CallExpression" && node === parent.arguments[1] &&
87
+ (parent.callee.name === "parseInt" ||
88
+ parent.callee.type === "MemberExpression" &&
89
+ parent.callee.object.name === "Number" &&
90
+ parent.callee.property.name === "parseInt")
91
+ ) {
75
92
  return;
76
93
  }
77
94
 
@@ -85,7 +102,7 @@ module.exports = function(context) {
85
102
  } else if (okTypes.indexOf(parent.type) === -1) {
86
103
  context.report({
87
104
  node: node,
88
- message: "No magic number: " + node.raw
105
+ message: "No magic number: " + raw
89
106
  });
90
107
  }
91
108
  }
@@ -14,9 +14,7 @@
14
14
  module.exports = function(context) {
15
15
 
16
16
  var smartTabs,
17
- templateLocs = [],
18
- lastTemplateLocIndex = 0,
19
- lastCommentLocIndex = 0;
17
+ ignoredLocs = [];
20
18
 
21
19
  switch (context.options[0]) {
22
20
  case true: // Support old syntax, maybe add deprecation warning here
@@ -64,7 +62,7 @@ module.exports = function(context) {
64
62
  return {
65
63
 
66
64
  "TemplateElement": function(node) {
67
- templateLocs.push(node.loc);
65
+ ignoredLocs.push(node.loc);
68
66
  },
69
67
 
70
68
  "Program:exit": function(node) {
@@ -78,6 +76,22 @@ module.exports = function(context) {
78
76
  lines = context.getSourceLines(),
79
77
  comments = context.getAllComments();
80
78
 
79
+ comments.forEach(function(comment) {
80
+ ignoredLocs.push(comment.loc);
81
+ });
82
+
83
+ ignoredLocs.sort(function(first, second) {
84
+ if (beforeLoc(first, second.start.line, second.start.column)) {
85
+ return 1;
86
+ }
87
+
88
+ if (beforeLoc(second, first.start.line, second.start.column)) {
89
+ return -1;
90
+ }
91
+
92
+ return 0;
93
+ });
94
+
81
95
  if (smartTabs) {
82
96
  /*
83
97
  * At least one space followed by a tab
@@ -93,28 +107,18 @@ module.exports = function(context) {
93
107
  var lineNumber = i + 1,
94
108
  column = match.index + 1;
95
109
 
96
- for (; lastCommentLocIndex < comments.length; lastCommentLocIndex++) {
97
- if (beforeLoc(comments[lastCommentLocIndex].loc, lineNumber, column)) {
110
+ for (var j = 0; j < ignoredLocs.length; j++) {
111
+ if (beforeLoc(ignoredLocs[j], lineNumber, column)) {
98
112
  continue;
99
113
  }
100
- if (afterLoc(comments[lastCommentLocIndex].loc, lineNumber, column)) {
101
- break;
102
- }
103
- return;
104
- }
105
-
106
- // make sure this isn't inside of a template element
107
- for (; lastTemplateLocIndex < templateLocs.length; lastTemplateLocIndex++) {
108
- if (beforeLoc(templateLocs[lastTemplateLocIndex], lineNumber, column)) {
114
+ if (afterLoc(ignoredLocs[j], lineNumber, column)) {
109
115
  continue;
110
116
  }
111
- if (afterLoc(templateLocs[lastTemplateLocIndex], lineNumber, column)) {
112
- break;
113
- }
117
+
114
118
  return;
115
119
  }
116
120
 
117
- context.report(node, { line: i + 1, column: column }, "Mixed spaces and tabs.");
121
+ context.report(node, { line: lineNumber, column: column }, "Mixed spaces and tabs.");
118
122
  }
119
123
  });
120
124
  }