eslint 3.15.0 → 3.16.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 (97) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/conf/{eslint.json → eslint-recommended.js} +85 -71
  3. package/lib/ast-utils.js +185 -19
  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/rules/arrow-body-style.js +7 -4
  11. package/lib/rules/arrow-spacing.js +7 -6
  12. package/lib/rules/block-spacing.js +2 -2
  13. package/lib/rules/brace-style.js +2 -6
  14. package/lib/rules/capitalized-comments.js +6 -6
  15. package/lib/rules/comma-spacing.js +3 -3
  16. package/lib/rules/consistent-return.js +1 -1
  17. package/lib/rules/constructor-super.js +3 -3
  18. package/lib/rules/curly.js +11 -7
  19. package/lib/rules/default-case.js +3 -3
  20. package/lib/rules/eqeqeq.js +15 -6
  21. package/lib/rules/func-call-spacing.js +10 -13
  22. package/lib/rules/generator-star-spacing.js +18 -19
  23. package/lib/rules/id-blacklist.js +2 -2
  24. package/lib/rules/id-length.js +3 -3
  25. package/lib/rules/id-match.js +2 -2
  26. package/lib/rules/indent.js +7 -6
  27. package/lib/rules/key-spacing.js +12 -16
  28. package/lib/rules/keyword-spacing.js +2 -13
  29. package/lib/rules/line-comment-position.js +1 -1
  30. package/lib/rules/linebreak-style.js +7 -1
  31. package/lib/rules/lines-around-comment.js +4 -4
  32. package/lib/rules/lines-around-directive.js +3 -3
  33. package/lib/rules/max-lines.js +2 -2
  34. package/lib/rules/max-statements-per-line.js +7 -6
  35. package/lib/rules/newline-after-var.js +7 -2
  36. package/lib/rules/newline-per-chained-call.js +3 -1
  37. package/lib/rules/no-cond-assign.js +3 -3
  38. package/lib/rules/no-extend-native.js +3 -3
  39. package/lib/rules/no-extra-bind.js +3 -4
  40. package/lib/rules/no-extra-boolean-cast.js +8 -0
  41. package/lib/rules/no-extra-parens.js +1 -2
  42. package/lib/rules/no-inner-declarations.js +4 -4
  43. package/lib/rules/no-irregular-whitespace.js +7 -1
  44. package/lib/rules/no-lone-blocks.js +10 -10
  45. package/lib/rules/no-mixed-operators.js +1 -7
  46. package/lib/rules/no-multi-spaces.js +4 -1
  47. package/lib/rules/no-multi-str.js +7 -3
  48. package/lib/rules/no-return-assign.js +7 -14
  49. package/lib/rules/no-sequences.js +7 -6
  50. package/lib/rules/no-trailing-spaces.js +8 -2
  51. package/lib/rules/no-undefined.js +45 -6
  52. package/lib/rules/no-unexpected-multiline.js +9 -8
  53. package/lib/rules/no-unneeded-ternary.js +5 -1
  54. package/lib/rules/no-unused-labels.js +17 -2
  55. package/lib/rules/no-unused-vars.js +2 -16
  56. package/lib/rules/no-useless-computed-key.js +8 -3
  57. package/lib/rules/no-useless-concat.js +10 -7
  58. package/lib/rules/no-useless-escape.js +1 -1
  59. package/lib/rules/no-useless-return.js +1 -7
  60. package/lib/rules/no-var.js +1 -3
  61. package/lib/rules/no-whitespace-before-property.js +5 -16
  62. package/lib/rules/object-curly-newline.js +2 -2
  63. package/lib/rules/object-curly-spacing.js +7 -25
  64. package/lib/rules/object-property-newline.js +3 -3
  65. package/lib/rules/object-shorthand.js +2 -2
  66. package/lib/rules/operator-assignment.js +1 -1
  67. package/lib/rules/operator-linebreak.js +8 -10
  68. package/lib/rules/padded-blocks.js +4 -4
  69. package/lib/rules/prefer-spread.js +1 -1
  70. package/lib/rules/prefer-template.js +1 -1
  71. package/lib/rules/quotes.js +10 -6
  72. package/lib/rules/semi-spacing.js +4 -0
  73. package/lib/rules/space-before-function-paren.js +8 -5
  74. package/lib/rules/spaced-comment.js +2 -2
  75. package/lib/rules/strict.js +2 -2
  76. package/lib/rules/unicode-bom.js +1 -1
  77. package/lib/rules/wrap-iife.js +5 -5
  78. package/lib/rules/yoda.js +2 -7
  79. package/lib/testers/rule-tester.js +13 -6
  80. package/lib/token-store/backward-token-comment-cursor.js +57 -0
  81. package/lib/token-store/backward-token-cursor.js +56 -0
  82. package/lib/token-store/cursor.js +76 -0
  83. package/lib/token-store/cursors.js +92 -0
  84. package/lib/token-store/decorative-cursor.js +39 -0
  85. package/lib/token-store/filter-cursor.js +43 -0
  86. package/lib/token-store/forward-token-comment-cursor.js +57 -0
  87. package/lib/token-store/forward-token-cursor.js +61 -0
  88. package/lib/token-store/index.js +604 -0
  89. package/lib/token-store/limit-cursor.js +40 -0
  90. package/lib/token-store/padded-token-cursor.js +38 -0
  91. package/lib/token-store/skip-cursor.js +42 -0
  92. package/lib/token-store/utils.js +100 -0
  93. package/lib/util/source-code-fixer.js +35 -39
  94. package/lib/util/source-code.js +31 -15
  95. package/messages/extend-config-missing.txt +3 -0
  96. package/package.json +2 -2
  97. package/lib/token-store.js +0 -203
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Define 2 token factories; forward and backward.
3
+ * @author Toru Nagashima
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const BackwardTokenCommentCursor = require("./backward-token-comment-cursor");
12
+ const BackwardTokenCursor = require("./backward-token-cursor");
13
+ const FilterCursor = require("./filter-cursor");
14
+ const ForwardTokenCommentCursor = require("./forward-token-comment-cursor");
15
+ const ForwardTokenCursor = require("./forward-token-cursor");
16
+ const LimitCursor = require("./limit-cursor");
17
+ const SkipCursor = require("./skip-cursor");
18
+
19
+ //------------------------------------------------------------------------------
20
+ // Helpers
21
+ //------------------------------------------------------------------------------
22
+
23
+ /**
24
+ * The cursor factory.
25
+ * @private
26
+ */
27
+ class CursorFactory {
28
+
29
+ /**
30
+ * Initializes this cursor.
31
+ * @param {Function} TokenCursor - The class of the cursor which iterates tokens only.
32
+ * @param {Function} TokenCommentCursor - The class of the cursor which iterates the mix of tokens and comments.
33
+ */
34
+ constructor(TokenCursor, TokenCommentCursor) {
35
+ this.TokenCursor = TokenCursor;
36
+ this.TokenCommentCursor = TokenCommentCursor;
37
+ }
38
+
39
+ /**
40
+ * Creates a base cursor instance that can be decorated by createCursor.
41
+ *
42
+ * @param {Token[]} tokens - The array of tokens.
43
+ * @param {Comment[]} comments - The array of comments.
44
+ * @param {Object} indexMap - The map from locations to indices in `tokens`.
45
+ * @param {number} startLoc - The start location of the iteration range.
46
+ * @param {number} endLoc - The end location of the iteration range.
47
+ * @param {boolean} includeComments - The flag to iterate comments as well.
48
+ * @returns {Cursor} The created base cursor.
49
+ */
50
+ createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments) {
51
+ const Cursor = includeComments ? this.TokenCommentCursor : this.TokenCursor;
52
+
53
+ return new Cursor(tokens, comments, indexMap, startLoc, endLoc);
54
+ }
55
+
56
+ /**
57
+ * Creates a cursor that iterates tokens with normalized options.
58
+ *
59
+ * @param {Token[]} tokens - The array of tokens.
60
+ * @param {Comment[]} comments - The array of comments.
61
+ * @param {Object} indexMap - The map from locations to indices in `tokens`.
62
+ * @param {number} startLoc - The start location of the iteration range.
63
+ * @param {number} endLoc - The end location of the iteration range.
64
+ * @param {boolean} includeComments - The flag to iterate comments as well.
65
+ * @param {Function|null} filter - The predicate function to choose tokens.
66
+ * @param {number} skip - The count of tokens the cursor skips.
67
+ * @param {number} count - The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
68
+ * @returns {Cursor} The created cursor.
69
+ */
70
+ createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, count) {
71
+ let cursor = this.createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments);
72
+
73
+ if (filter) {
74
+ cursor = new FilterCursor(cursor, filter);
75
+ }
76
+ if (skip >= 1) {
77
+ cursor = new SkipCursor(cursor, skip);
78
+ }
79
+ if (count >= 0) {
80
+ cursor = new LimitCursor(cursor, count);
81
+ }
82
+
83
+ return cursor;
84
+ }
85
+ }
86
+
87
+ //------------------------------------------------------------------------------
88
+ // Exports
89
+ //------------------------------------------------------------------------------
90
+
91
+ exports.forward = new CursorFactory(ForwardTokenCursor, ForwardTokenCommentCursor);
92
+ exports.backward = new CursorFactory(BackwardTokenCursor, BackwardTokenCommentCursor);
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Define the abstract class about cursors which manipulate another cursor.
3
+ * @author Toru Nagashima
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const Cursor = require("./cursor");
12
+
13
+ //------------------------------------------------------------------------------
14
+ // Exports
15
+ //------------------------------------------------------------------------------
16
+
17
+ /**
18
+ * The abstract class about cursors which manipulate another cursor.
19
+ */
20
+ module.exports = class DecorativeCursor extends Cursor {
21
+
22
+ /**
23
+ * Initializes this cursor.
24
+ * @param {Cursor} cursor - The cursor to be decorated.
25
+ */
26
+ constructor(cursor) {
27
+ super();
28
+ this.cursor = cursor;
29
+ }
30
+
31
+ /** @inheritdoc */
32
+ moveNext() {
33
+ const retv = this.cursor.moveNext();
34
+
35
+ this.current = this.cursor.current;
36
+
37
+ return retv;
38
+ }
39
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @fileoverview Define the cursor which ignores specified tokens.
3
+ * @author Toru Nagashima
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const DecorativeCursor = require("./decorative-cursor");
12
+
13
+ //------------------------------------------------------------------------------
14
+ // Exports
15
+ //------------------------------------------------------------------------------
16
+
17
+ /**
18
+ * The decorative cursor which ignores specified tokens.
19
+ */
20
+ module.exports = class FilterCursor extends DecorativeCursor {
21
+
22
+ /**
23
+ * Initializes this cursor.
24
+ * @param {Cursor} cursor - The cursor to be decorated.
25
+ * @param {Function} predicate - The predicate function to decide tokens this cursor iterates.
26
+ */
27
+ constructor(cursor, predicate) {
28
+ super(cursor);
29
+ this.predicate = predicate;
30
+ }
31
+
32
+ /** @inheritdoc */
33
+ moveNext() {
34
+ const predicate = this.predicate;
35
+
36
+ while (super.moveNext()) {
37
+ if (predicate(this.current)) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @fileoverview Define the cursor which iterates tokens and comments.
3
+ * @author Toru Nagashima
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const Cursor = require("./cursor");
12
+ const utils = require("./utils");
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Exports
16
+ //------------------------------------------------------------------------------
17
+
18
+ /**
19
+ * The cursor which iterates tokens and comments.
20
+ */
21
+ module.exports = class ForwardTokenCommentCursor extends Cursor {
22
+
23
+ /**
24
+ * Initializes this cursor.
25
+ * @param {Token[]} tokens - The array of tokens.
26
+ * @param {Comment[]} comments - The array of comments.
27
+ * @param {Object} indexMap - The map from locations to indices in `tokens`.
28
+ * @param {number} startLoc - The start location of the iteration range.
29
+ * @param {number} endLoc - The end location of the iteration range.
30
+ */
31
+ constructor(tokens, comments, indexMap, startLoc, endLoc) {
32
+ super();
33
+ this.tokens = tokens;
34
+ this.comments = comments;
35
+ this.tokenIndex = utils.getFirstIndex(tokens, indexMap, startLoc);
36
+ this.commentIndex = utils.search(comments, startLoc);
37
+ this.border = endLoc;
38
+ }
39
+
40
+ /** @inheritdoc */
41
+ moveNext() {
42
+ const token = (this.tokenIndex < this.tokens.length) ? this.tokens[this.tokenIndex] : null;
43
+ const comment = (this.commentIndex < this.comments.length) ? this.comments[this.commentIndex] : null;
44
+
45
+ if (token && (!comment || token.range[0] < comment.range[0])) {
46
+ this.current = token;
47
+ this.tokenIndex += 1;
48
+ } else if (comment) {
49
+ this.current = comment;
50
+ this.commentIndex += 1;
51
+ } else {
52
+ this.current = null;
53
+ }
54
+
55
+ return Boolean(this.current) && (this.border === -1 || this.current.range[1] <= this.border);
56
+ }
57
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @fileoverview Define the cursor which iterates tokens only.
3
+ * @author Toru Nagashima
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const Cursor = require("./cursor");
12
+ const utils = require("./utils");
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Exports
16
+ //------------------------------------------------------------------------------
17
+
18
+ /**
19
+ * The cursor which iterates tokens only.
20
+ */
21
+ module.exports = class ForwardTokenCursor extends Cursor {
22
+
23
+ /**
24
+ * Initializes this cursor.
25
+ * @param {Token[]} tokens - The array of tokens.
26
+ * @param {Comment[]} comments - The array of comments.
27
+ * @param {Object} indexMap - The map from locations to indices in `tokens`.
28
+ * @param {number} startLoc - The start location of the iteration range.
29
+ * @param {number} endLoc - The end location of the iteration range.
30
+ */
31
+ constructor(tokens, comments, indexMap, startLoc, endLoc) {
32
+ super();
33
+ this.tokens = tokens;
34
+ this.index = utils.getFirstIndex(tokens, indexMap, startLoc);
35
+ this.indexEnd = utils.getLastIndex(tokens, indexMap, endLoc);
36
+ }
37
+
38
+ /** @inheritdoc */
39
+ moveNext() {
40
+ if (this.index <= this.indexEnd) {
41
+ this.current = this.tokens[this.index];
42
+ this.index += 1;
43
+ return true;
44
+ }
45
+ return false;
46
+ }
47
+
48
+ //
49
+ // Shorthand for performance.
50
+ //
51
+
52
+ /** @inheritdoc */
53
+ getOneToken() {
54
+ return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
55
+ }
56
+
57
+ /** @inheritdoc */
58
+ getAllTokens() {
59
+ return this.tokens.slice(this.index, this.indexEnd + 1);
60
+ }
61
+ };