eslint 3.15.0 → 3.17.1

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 (118) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/conf/{eslint.json → eslint-recommended.js} +87 -71
  3. package/lib/ast-utils.js +182 -80
  4. package/lib/code-path-analysis/code-path-state.js +2 -2
  5. package/lib/config/autoconfig.js +3 -3
  6. package/lib/config/config-file.js +14 -7
  7. package/lib/config/config-initializer.js +1 -1
  8. package/lib/config.js +3 -2
  9. package/lib/eslint.js +4 -4
  10. package/lib/internal-rules/internal-no-invalid-meta.js +2 -40
  11. package/lib/rules/array-callback-return.js +15 -5
  12. package/lib/rules/arrow-body-style.js +7 -4
  13. package/lib/rules/arrow-spacing.js +7 -6
  14. package/lib/rules/block-spacing.js +2 -2
  15. package/lib/rules/brace-style.js +2 -6
  16. package/lib/rules/capitalized-comments.js +8 -7
  17. package/lib/rules/comma-spacing.js +3 -3
  18. package/lib/rules/complexity.js +14 -8
  19. package/lib/rules/consistent-return.js +18 -11
  20. package/lib/rules/constructor-super.js +3 -3
  21. package/lib/rules/curly.js +11 -7
  22. package/lib/rules/default-case.js +3 -3
  23. package/lib/rules/eqeqeq.js +15 -6
  24. package/lib/rules/func-call-spacing.js +10 -13
  25. package/lib/rules/func-names.js +20 -5
  26. package/lib/rules/generator-star-spacing.js +18 -19
  27. package/lib/rules/id-blacklist.js +2 -2
  28. package/lib/rules/id-length.js +3 -3
  29. package/lib/rules/id-match.js +2 -2
  30. package/lib/rules/indent.js +7 -6
  31. package/lib/rules/key-spacing.js +12 -16
  32. package/lib/rules/keyword-spacing.js +21 -17
  33. package/lib/rules/line-comment-position.js +16 -6
  34. package/lib/rules/linebreak-style.js +7 -1
  35. package/lib/rules/lines-around-comment.js +23 -4
  36. package/lib/rules/lines-around-directive.js +3 -3
  37. package/lib/rules/max-lines.js +2 -2
  38. package/lib/rules/max-params.js +17 -4
  39. package/lib/rules/max-statements-per-line.js +7 -6
  40. package/lib/rules/max-statements.js +11 -10
  41. package/lib/rules/newline-after-var.js +7 -2
  42. package/lib/rules/newline-per-chained-call.js +3 -1
  43. package/lib/rules/no-compare-neg-zero.js +53 -0
  44. package/lib/rules/no-cond-assign.js +3 -3
  45. package/lib/rules/no-else-return.js +13 -1
  46. package/lib/rules/no-empty-function.js +9 -16
  47. package/lib/rules/no-extend-native.js +3 -3
  48. package/lib/rules/no-extra-bind.js +3 -4
  49. package/lib/rules/no-extra-boolean-cast.js +8 -0
  50. package/lib/rules/no-extra-parens.js +1 -2
  51. package/lib/rules/no-extra-semi.js +13 -1
  52. package/lib/rules/no-inner-declarations.js +4 -4
  53. package/lib/rules/no-invalid-regexp.js +2 -1
  54. package/lib/rules/no-irregular-whitespace.js +7 -1
  55. package/lib/rules/no-lone-blocks.js +10 -10
  56. package/lib/rules/no-mixed-operators.js +1 -7
  57. package/lib/rules/no-multi-spaces.js +4 -1
  58. package/lib/rules/no-multi-str.js +7 -3
  59. package/lib/rules/no-multiple-empty-lines.js +2 -4
  60. package/lib/rules/no-param-reassign.js +29 -6
  61. package/lib/rules/no-restricted-properties.js +2 -0
  62. package/lib/rules/no-return-assign.js +7 -14
  63. package/lib/rules/no-return-await.js +1 -1
  64. package/lib/rules/no-sequences.js +7 -6
  65. package/lib/rules/no-trailing-spaces.js +8 -2
  66. package/lib/rules/no-undefined.js +45 -6
  67. package/lib/rules/no-unexpected-multiline.js +9 -8
  68. package/lib/rules/no-unneeded-ternary.js +5 -1
  69. package/lib/rules/no-unused-labels.js +17 -2
  70. package/lib/rules/no-unused-vars.js +13 -27
  71. package/lib/rules/no-use-before-define.js +1 -1
  72. package/lib/rules/no-useless-computed-key.js +8 -3
  73. package/lib/rules/no-useless-concat.js +10 -7
  74. package/lib/rules/no-useless-escape.js +2 -2
  75. package/lib/rules/no-useless-return.js +14 -9
  76. package/lib/rules/no-var.js +1 -3
  77. package/lib/rules/no-whitespace-before-property.js +5 -16
  78. package/lib/rules/nonblock-statement-body-position.js +114 -0
  79. package/lib/rules/object-curly-newline.js +2 -2
  80. package/lib/rules/object-curly-spacing.js +7 -25
  81. package/lib/rules/object-property-newline.js +3 -3
  82. package/lib/rules/object-shorthand.js +4 -3
  83. package/lib/rules/operator-assignment.js +2 -2
  84. package/lib/rules/operator-linebreak.js +8 -10
  85. package/lib/rules/padded-blocks.js +39 -30
  86. package/lib/rules/prefer-destructuring.js +1 -1
  87. package/lib/rules/prefer-spread.js +1 -1
  88. package/lib/rules/prefer-template.js +1 -1
  89. package/lib/rules/quotes.js +10 -6
  90. package/lib/rules/semi-spacing.js +4 -0
  91. package/lib/rules/semi.js +13 -1
  92. package/lib/rules/space-before-function-paren.js +8 -5
  93. package/lib/rules/space-unary-ops.js +19 -1
  94. package/lib/rules/spaced-comment.js +2 -2
  95. package/lib/rules/strict.js +10 -4
  96. package/lib/rules/unicode-bom.js +1 -1
  97. package/lib/rules/wrap-iife.js +5 -5
  98. package/lib/rules/yoda.js +4 -9
  99. package/lib/testers/rule-tester.js +46 -9
  100. package/lib/token-store/backward-token-comment-cursor.js +57 -0
  101. package/lib/token-store/backward-token-cursor.js +56 -0
  102. package/lib/token-store/cursor.js +76 -0
  103. package/lib/token-store/cursors.js +92 -0
  104. package/lib/token-store/decorative-cursor.js +39 -0
  105. package/lib/token-store/filter-cursor.js +43 -0
  106. package/lib/token-store/forward-token-comment-cursor.js +57 -0
  107. package/lib/token-store/forward-token-cursor.js +61 -0
  108. package/lib/token-store/index.js +604 -0
  109. package/lib/token-store/limit-cursor.js +40 -0
  110. package/lib/token-store/padded-token-cursor.js +38 -0
  111. package/lib/token-store/skip-cursor.js +42 -0
  112. package/lib/token-store/utils.js +100 -0
  113. package/lib/util/fix-tracker.js +121 -0
  114. package/lib/util/source-code-fixer.js +35 -39
  115. package/lib/util/source-code.js +129 -16
  116. package/messages/extend-config-missing.txt +3 -0
  117. package/package.json +5 -6
  118. package/lib/token-store.js +0 -203
@@ -1,203 +0,0 @@
1
- /**
2
- * @fileoverview Object to handle access and retrieval of tokens.
3
- * @author Brandon Mills
4
- */
5
- "use strict";
6
-
7
- //------------------------------------------------------------------------------
8
- // Implementation
9
- //------------------------------------------------------------------------------
10
-
11
- module.exports = function(tokens) {
12
- const api = {},
13
- starts = Object.create(null),
14
- ends = Object.create(null),
15
- length = tokens.length;
16
-
17
- /**
18
- * Gets tokens in a given interval.
19
- * @param {int} start Inclusive index of the first token. 0 if negative.
20
- * @param {int} end Exclusive index of the last token.
21
- * @returns {Token[]} Tokens in the interval.
22
- */
23
- function get(start, end) {
24
- const result = [];
25
-
26
- for (let i = Math.max(0, start); i < end && i < length; i++) {
27
- result.push(tokens[i]);
28
- }
29
-
30
- return result;
31
- }
32
-
33
- /**
34
- * Gets the index in the tokens array of the last token belonging to a node.
35
- * Usually a node ends exactly at a token, but due to ASI, sometimes a
36
- * node's range extends beyond its last token.
37
- * @param {ASTNode} node The node for which to find the last token's index.
38
- * @returns {int} Index in the tokens array of the node's last token.
39
- */
40
- function lastTokenIndex(node) {
41
- const end = node.range[1];
42
- let cursor = ends[end];
43
-
44
- // If the node extends beyond its last token, get the token before the
45
- // next token
46
- if (typeof cursor === "undefined") {
47
- cursor = starts[end] - 1;
48
- }
49
-
50
- // If there isn't a next token, the desired token is the last one in the
51
- // array
52
- if (isNaN(cursor)) {
53
- cursor = length - 1;
54
- }
55
-
56
- return cursor;
57
- }
58
-
59
- // Map tokens' start and end range to the index in the tokens array
60
- for (let i = 0; i < length; i++) {
61
- const range = tokens[i].range;
62
-
63
- starts[range[0]] = i;
64
- ends[range[1]] = i;
65
- }
66
-
67
- /**
68
- * Gets a number of tokens that precede a given node or token in the token
69
- * stream.
70
- * @param {(ASTNode|Token)} node The AST node or token.
71
- * @param {int} [beforeCount=0] The number of tokens before the node or
72
- * token to retrieve.
73
- * @returns {Token[]} Array of objects representing tokens.
74
- */
75
- api.getTokensBefore = function(node, beforeCount) {
76
- const first = starts[node.range[0]];
77
-
78
- return get(first - (beforeCount || 0), first);
79
- };
80
-
81
- /**
82
- * Gets the token that precedes a given node or token in the token stream.
83
- * @param {(ASTNode|Token)} node The AST node or token.
84
- * @param {int} [skip=0] A number of tokens to skip before the given node or
85
- * token.
86
- * @returns {Token} An object representing the token.
87
- */
88
- api.getTokenBefore = function(node, skip) {
89
- return tokens[starts[node.range[0]] - (skip || 0) - 1];
90
- };
91
-
92
- /**
93
- * Gets a number of tokens that follow a given node or token in the token
94
- * stream.
95
- * @param {(ASTNode|Token)} node The AST node or token.
96
- * @param {int} [afterCount=0] The number of tokens after the node or token
97
- * to retrieve.
98
- * @returns {Token[]} Array of objects representing tokens.
99
- */
100
- api.getTokensAfter = function(node, afterCount) {
101
- const start = lastTokenIndex(node) + 1;
102
-
103
- return get(start, start + (afterCount || 0));
104
- };
105
-
106
- /**
107
- * Gets the token that follows a given node or token in the token stream.
108
- * @param {(ASTNode|Token)} node The AST node or token.
109
- * @param {int} [skip=0] A number of tokens to skip after the given node or
110
- * token.
111
- * @returns {Token} An object representing the token.
112
- */
113
- api.getTokenAfter = function(node, skip) {
114
- return tokens[lastTokenIndex(node) + (skip || 0) + 1];
115
- };
116
-
117
- /**
118
- * Gets all tokens that are related to the given node.
119
- * @param {ASTNode} node The AST node.
120
- * @param {int} [beforeCount=0] The number of tokens before the node to retrieve.
121
- * @param {int} [afterCount=0] The number of tokens after the node to retrieve.
122
- * @returns {Token[]} Array of objects representing tokens.
123
- */
124
- api.getTokens = function(node, beforeCount, afterCount) {
125
- return get(
126
- starts[node.range[0]] - (beforeCount || 0),
127
- lastTokenIndex(node) + (afterCount || 0) + 1
128
- );
129
- };
130
-
131
- /**
132
- * Gets the first `count` tokens of the given node's token stream.
133
- * @param {ASTNode} node The AST node.
134
- * @param {int} [count=0] The number of tokens of the node to retrieve.
135
- * @returns {Token[]} Array of objects representing tokens.
136
- */
137
- api.getFirstTokens = function(node, count) {
138
- const first = starts[node.range[0]];
139
-
140
- return get(
141
- first,
142
- Math.min(lastTokenIndex(node) + 1, first + (count || 0))
143
- );
144
- };
145
-
146
- /**
147
- * Gets the first token of the given node's token stream.
148
- * @param {ASTNode} node The AST node.
149
- * @param {int} [skip=0] A number of tokens to skip.
150
- * @returns {Token} An object representing the token.
151
- */
152
- api.getFirstToken = function(node, skip) {
153
- return tokens[starts[node.range[0]] + (skip || 0)];
154
- };
155
-
156
- /**
157
- * Gets the last `count` tokens of the given node.
158
- * @param {ASTNode} node The AST node.
159
- * @param {int} [count=0] The number of tokens of the node to retrieve.
160
- * @returns {Token[]} Array of objects representing tokens.
161
- */
162
- api.getLastTokens = function(node, count) {
163
- const last = lastTokenIndex(node) + 1;
164
-
165
- return get(Math.max(starts[node.range[0]], last - (count || 0)), last);
166
- };
167
-
168
- /**
169
- * Gets the last token of the given node's token stream.
170
- * @param {ASTNode} node The AST node.
171
- * @param {int} [skip=0] A number of tokens to skip.
172
- * @returns {Token} An object representing the token.
173
- */
174
- api.getLastToken = function(node, skip) {
175
- return tokens[lastTokenIndex(node) - (skip || 0)];
176
- };
177
-
178
- /**
179
- * Gets all of the tokens between two non-overlapping nodes.
180
- * @param {ASTNode} left Node before the desired token range.
181
- * @param {ASTNode} right Node after the desired token range.
182
- * @param {int} [padding=0] Number of extra tokens on either side of center.
183
- * @returns {Token[]} Tokens between left and right plus padding.
184
- */
185
- api.getTokensBetween = function(left, right, padding) {
186
- padding = padding || 0;
187
- return get(
188
- lastTokenIndex(left) + 1 - padding,
189
- starts[right.range[0]] + padding
190
- );
191
- };
192
-
193
- /**
194
- * Gets the token starting at the specified index.
195
- * @param {int} startIndex Index of the start of the token's range.
196
- * @returns {Token} The token starting at index, or null if no such token.
197
- */
198
- api.getTokenByRangeStart = function(startIndex) {
199
- return (tokens[starts[startIndex]] || null);
200
- };
201
-
202
- return api;
203
- };