eslint 3.13.1 → 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 (137) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +1 -1
  3. package/conf/{eslint.json → eslint-recommended.js} +88 -71
  4. package/lib/ast-utils.js +247 -28
  5. package/lib/cli.js +2 -2
  6. package/lib/code-path-analysis/code-path-state.js +2 -2
  7. package/lib/config/autoconfig.js +24 -20
  8. package/lib/config/config-file.js +31 -24
  9. package/lib/config/config-initializer.js +2 -2
  10. package/lib/config/config-rule.js +15 -16
  11. package/lib/config/config-validator.js +6 -6
  12. package/lib/config.js +3 -2
  13. package/lib/eslint.js +18 -18
  14. package/lib/formatters/checkstyle.js +2 -2
  15. package/lib/formatters/codeframe.js +1 -1
  16. package/lib/formatters/compact.js +2 -2
  17. package/lib/formatters/junit.js +2 -2
  18. package/lib/formatters/tap.js +2 -2
  19. package/lib/formatters/unix.js +2 -2
  20. package/lib/formatters/visualstudio.js +2 -2
  21. package/lib/internal-rules/internal-consistent-docs-description.js +1 -1
  22. package/lib/rule-context.js +2 -2
  23. package/lib/rules/arrow-body-style.js +7 -4
  24. package/lib/rules/arrow-spacing.js +7 -6
  25. package/lib/rules/block-spacing.js +2 -2
  26. package/lib/rules/brace-style.js +93 -202
  27. package/lib/rules/capitalized-comments.js +6 -6
  28. package/lib/rules/comma-dangle.js +6 -6
  29. package/lib/rules/comma-spacing.js +16 -16
  30. package/lib/rules/comma-style.js +1 -1
  31. package/lib/rules/consistent-return.js +1 -1
  32. package/lib/rules/constructor-super.js +3 -3
  33. package/lib/rules/curly.js +11 -7
  34. package/lib/rules/default-case.js +3 -3
  35. package/lib/rules/eqeqeq.js +15 -6
  36. package/lib/rules/func-call-spacing.js +12 -15
  37. package/lib/rules/func-name-matching.js +1 -1
  38. package/lib/rules/generator-star-spacing.js +18 -19
  39. package/lib/rules/global-require.js +2 -2
  40. package/lib/rules/id-blacklist.js +2 -2
  41. package/lib/rules/id-length.js +3 -3
  42. package/lib/rules/id-match.js +2 -2
  43. package/lib/rules/indent.js +21 -20
  44. package/lib/rules/key-spacing.js +20 -23
  45. package/lib/rules/keyword-spacing.js +2 -13
  46. package/lib/rules/line-comment-position.js +1 -1
  47. package/lib/rules/linebreak-style.js +7 -1
  48. package/lib/rules/lines-around-comment.js +4 -4
  49. package/lib/rules/lines-around-directive.js +4 -4
  50. package/lib/rules/max-lines.js +3 -3
  51. package/lib/rules/max-statements-per-line.js +8 -7
  52. package/lib/rules/new-cap.js +2 -2
  53. package/lib/rules/newline-after-var.js +7 -2
  54. package/lib/rules/newline-before-return.js +2 -2
  55. package/lib/rules/newline-per-chained-call.js +3 -1
  56. package/lib/rules/no-await-in-loop.js +5 -5
  57. package/lib/rules/no-cond-assign.js +3 -3
  58. package/lib/rules/no-dupe-keys.js +1 -1
  59. package/lib/rules/no-else-return.js +88 -25
  60. package/lib/rules/no-extend-native.js +3 -3
  61. package/lib/rules/no-extra-bind.js +3 -4
  62. package/lib/rules/no-extra-boolean-cast.js +22 -1
  63. package/lib/rules/no-extra-parens.js +57 -9
  64. package/lib/rules/no-inner-declarations.js +4 -4
  65. package/lib/rules/no-irregular-whitespace.js +7 -1
  66. package/lib/rules/no-lone-blocks.js +10 -10
  67. package/lib/rules/no-mixed-operators.js +1 -7
  68. package/lib/rules/no-mixed-requires.js +4 -4
  69. package/lib/rules/no-multi-assign.js +41 -0
  70. package/lib/rules/no-multi-spaces.js +4 -1
  71. package/lib/rules/no-multi-str.js +7 -3
  72. package/lib/rules/no-redeclare.js +7 -7
  73. package/lib/rules/no-return-assign.js +7 -14
  74. package/lib/rules/no-return-await.js +2 -2
  75. package/lib/rules/no-sequences.js +7 -6
  76. package/lib/rules/no-throw-literal.js +2 -39
  77. package/lib/rules/no-trailing-spaces.js +8 -2
  78. package/lib/rules/no-undefined.js +45 -6
  79. package/lib/rules/no-unexpected-multiline.js +9 -8
  80. package/lib/rules/no-unneeded-ternary.js +5 -1
  81. package/lib/rules/no-unused-labels.js +17 -2
  82. package/lib/rules/no-unused-vars.js +34 -19
  83. package/lib/rules/no-use-before-define.js +33 -29
  84. package/lib/rules/no-useless-computed-key.js +9 -4
  85. package/lib/rules/no-useless-concat.js +10 -7
  86. package/lib/rules/no-useless-escape.js +1 -1
  87. package/lib/rules/no-useless-return.js +5 -11
  88. package/lib/rules/no-var.js +69 -3
  89. package/lib/rules/no-whitespace-before-property.js +5 -16
  90. package/lib/rules/object-curly-newline.js +2 -2
  91. package/lib/rules/object-curly-spacing.js +7 -25
  92. package/lib/rules/object-property-newline.js +3 -3
  93. package/lib/rules/object-shorthand.js +10 -10
  94. package/lib/rules/operator-assignment.js +2 -2
  95. package/lib/rules/operator-linebreak.js +8 -10
  96. package/lib/rules/padded-blocks.js +4 -4
  97. package/lib/rules/prefer-promise-reject-errors.js +124 -0
  98. package/lib/rules/prefer-spread.js +1 -1
  99. package/lib/rules/prefer-template.js +1 -1
  100. package/lib/rules/quotes.js +11 -7
  101. package/lib/rules/require-await.js +1 -1
  102. package/lib/rules/semi-spacing.js +4 -0
  103. package/lib/rules/sort-imports.js +4 -4
  104. package/lib/rules/sort-keys.js +2 -2
  105. package/lib/rules/sort-vars.js +2 -2
  106. package/lib/rules/space-before-function-paren.js +9 -6
  107. package/lib/rules/space-in-parens.js +8 -8
  108. package/lib/rules/spaced-comment.js +10 -10
  109. package/lib/rules/strict.js +2 -2
  110. package/lib/rules/template-tag-spacing.js +77 -0
  111. package/lib/rules/unicode-bom.js +1 -1
  112. package/lib/rules/wrap-iife.js +5 -5
  113. package/lib/rules/yoda.js +2 -7
  114. package/lib/rules.js +2 -2
  115. package/lib/testers/rule-tester.js +28 -21
  116. package/lib/token-store/backward-token-comment-cursor.js +57 -0
  117. package/lib/token-store/backward-token-cursor.js +56 -0
  118. package/lib/token-store/cursor.js +76 -0
  119. package/lib/token-store/cursors.js +92 -0
  120. package/lib/token-store/decorative-cursor.js +39 -0
  121. package/lib/token-store/filter-cursor.js +43 -0
  122. package/lib/token-store/forward-token-comment-cursor.js +57 -0
  123. package/lib/token-store/forward-token-cursor.js +61 -0
  124. package/lib/token-store/index.js +604 -0
  125. package/lib/token-store/limit-cursor.js +40 -0
  126. package/lib/token-store/padded-token-cursor.js +38 -0
  127. package/lib/token-store/skip-cursor.js +42 -0
  128. package/lib/token-store/utils.js +100 -0
  129. package/lib/util/comment-event-generator.js +17 -16
  130. package/lib/util/glob-util.js +1 -1
  131. package/lib/util/glob.js +1 -1
  132. package/lib/util/rule-fixer.js +3 -8
  133. package/lib/util/source-code-fixer.js +41 -45
  134. package/lib/util/source-code.js +35 -19
  135. package/messages/extend-config-missing.txt +3 -0
  136. package/package.json +3 -3
  137. package/lib/token-store.js +0 -203
@@ -176,22 +176,21 @@ function combinePropertyObjects(objArr1, objArr2) {
176
176
  *
177
177
  * ruleConfigSet.ruleConfigs // -> [[2], [2, "always"], [2, "never"]]
178
178
  *
179
- * @param {ruleConfig[]} configs Valid rule configurations
180
- * @constructor
179
+ * Rule configuration set class
181
180
  */
182
- function RuleConfigSet(configs) {
181
+ class RuleConfigSet {
183
182
 
184
183
  /**
185
- * Stored valid rule configurations for this instance
186
- * @type {array}
187
- */
188
- this.ruleConfigs = configs || [];
189
-
190
- }
191
-
192
- RuleConfigSet.prototype = {
193
-
194
- constructor: RuleConfigSet,
184
+ * @param {ruleConfig[]} configs Valid rule configurations
185
+ */
186
+ constructor(configs) {
187
+
188
+ /**
189
+ * Stored valid rule configurations for this instance
190
+ * @type {array}
191
+ */
192
+ this.ruleConfigs = configs || [];
193
+ }
195
194
 
196
195
  /**
197
196
  * Add a severity level to the front of all configs in the instance.
@@ -210,7 +209,7 @@ RuleConfigSet.prototype = {
210
209
 
211
210
  // Add a single config at the beginning consisting of only the severity
212
211
  this.ruleConfigs.unshift(severity);
213
- },
212
+ }
214
213
 
215
214
  /**
216
215
  * Add rule configs from an array of strings (schema enums)
@@ -219,7 +218,7 @@ RuleConfigSet.prototype = {
219
218
  */
220
219
  addEnums(enums) {
221
220
  this.ruleConfigs = this.ruleConfigs.concat(combineArrays(this.ruleConfigs, enums));
222
- },
221
+ }
223
222
 
224
223
  /**
225
224
  * Add rule configurations from a schema object
@@ -261,7 +260,7 @@ RuleConfigSet.prototype = {
261
260
  this.ruleConfigs = this.ruleConfigs.concat(combineArrays(this.ruleConfigs, objectConfigSet.objectConfigs));
262
261
  }
263
262
  }
264
- };
263
+ }
265
264
 
266
265
  /**
267
266
  * Generate valid rule configurations based on a schema object
@@ -40,13 +40,13 @@ function getRuleOptionsSchema(id) {
40
40
  minItems: 0,
41
41
  maxItems: schema.length
42
42
  };
43
- } else {
44
- return {
45
- type: "array",
46
- minItems: 0,
47
- maxItems: 0
48
- };
49
43
  }
44
+ return {
45
+ type: "array",
46
+ minItems: 0,
47
+ maxItems: 0
48
+ };
49
+
50
50
  }
51
51
 
52
52
  // Given a full schema, leave it alone
package/lib/config.js CHANGED
@@ -234,8 +234,9 @@ class Config {
234
234
  }
235
235
 
236
236
  /**
237
- * Build a config object merging the base config (conf/eslint.json), the
238
- * environments config (conf/environments.js) and eventually the user config.
237
+ * Build a config object merging the base config (conf/eslint-recommended),
238
+ * the environments config (conf/environments.js) and eventually the user
239
+ * config.
239
240
  * @param {string} filePath a file in whose directory we start looking for a local config
240
241
  * @returns {Object} config object
241
242
  */
package/lib/eslint.js CHANGED
@@ -14,7 +14,7 @@ const assert = require("assert"),
14
14
  escope = require("escope"),
15
15
  levn = require("levn"),
16
16
  blankScriptAST = require("../conf/blank-script.json"),
17
- DEFAULT_PARSER = require("../conf/eslint.json").parser,
17
+ DEFAULT_PARSER = require("../conf/eslint-recommended").parser,
18
18
  replacements = require("../conf/replacements.json"),
19
19
  CodePathAnalyzer = require("./code-path-analysis/code-path-analyzer"),
20
20
  ConfigOps = require("./config/config-ops"),
@@ -528,9 +528,9 @@ function createStubRule(message) {
528
528
 
529
529
  if (message) {
530
530
  return createRuleModule;
531
- } else {
532
- throw new Error("No message passed to stub rule");
533
531
  }
532
+ throw new Error("No message passed to stub rule");
533
+
534
534
  }
535
535
 
536
536
  /**
@@ -660,9 +660,9 @@ module.exports = (function() {
660
660
  try {
661
661
  if (typeof parser.parseForESLint === "function") {
662
662
  return parser.parseForESLint(text, parserOptions);
663
- } else {
664
- return parser.parse(text, parserOptions);
665
663
  }
664
+ return parser.parse(text, parserOptions);
665
+
666
666
  } catch (ex) {
667
667
 
668
668
  // If the message includes a leading line number, strip it:
@@ -695,9 +695,9 @@ module.exports = (function() {
695
695
  return ruleConfig;
696
696
  } else if (Array.isArray(ruleConfig)) {
697
697
  return ruleConfig[0];
698
- } else {
699
- return 0;
700
698
  }
699
+ return 0;
700
+
701
701
  }
702
702
 
703
703
  /**
@@ -708,9 +708,9 @@ module.exports = (function() {
708
708
  function getRuleOptions(ruleConfig) {
709
709
  if (Array.isArray(ruleConfig)) {
710
710
  return ruleConfig.slice(1);
711
- } else {
712
- return [];
713
711
  }
712
+ return [];
713
+
714
714
  }
715
715
 
716
716
  // set unlimited listeners (see https://github.com/eslint/eslint/issues/524)
@@ -864,8 +864,8 @@ module.exports = (function() {
864
864
  (parseResult && parseResult.services ? parseResult.services : {})
865
865
  );
866
866
 
867
- const rule = ruleCreator.create ? ruleCreator.create(ruleContext) :
868
- ruleCreator(ruleContext);
867
+ const rule = ruleCreator.create ? ruleCreator.create(ruleContext)
868
+ : ruleCreator(ruleContext);
869
869
 
870
870
  // add all the node types as listeners
871
871
  Object.keys(rule).forEach(nodeType => {
@@ -939,9 +939,9 @@ module.exports = (function() {
939
939
 
940
940
  if (lineDiff === 0) {
941
941
  return a.column - b.column;
942
- } else {
943
- return lineDiff;
944
942
  }
943
+ return lineDiff;
944
+
945
945
  });
946
946
 
947
947
  return messages;
@@ -1109,9 +1109,9 @@ module.exports = (function() {
1109
1109
  if (scope) {
1110
1110
  if (scope.type === "function-expression-name") {
1111
1111
  return scope.childScopes[0];
1112
- } else {
1113
- return scope;
1114
1112
  }
1113
+ return scope;
1114
+
1115
1115
  }
1116
1116
 
1117
1117
  }
@@ -1161,9 +1161,9 @@ module.exports = (function() {
1161
1161
  api.getFilename = function() {
1162
1162
  if (typeof currentFilename === "string") {
1163
1163
  return currentFilename;
1164
- } else {
1165
- return "<input>";
1166
1164
  }
1165
+ return "<input>";
1166
+
1167
1167
  };
1168
1168
 
1169
1169
  /**
@@ -1192,7 +1192,7 @@ module.exports = (function() {
1192
1192
  * @returns {Object} Object mapping rule IDs to their default configurations
1193
1193
  */
1194
1194
  api.defaults = function() {
1195
- return require("../conf/eslint.json");
1195
+ return require("../conf/eslint-recommended");
1196
1196
  };
1197
1197
 
1198
1198
  /**
@@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
19
19
  function getMessageType(message) {
20
20
  if (message.fatal || message.severity === 2) {
21
21
  return "error";
22
- } else {
23
- return "warning";
24
22
  }
23
+ return "warning";
24
+
25
25
  }
26
26
 
27
27
  //------------------------------------------------------------------------------
@@ -56,7 +56,7 @@ function formatMessage(message, parentResult) {
56
56
  `${type}:`,
57
57
  `${msg}`,
58
58
  ruleId ? `${ruleId}` : "",
59
- sourceCode ? `at ${filePath}:` : `at ${filePath}`,
59
+ sourceCode ? `at ${filePath}:` : `at ${filePath}`
60
60
  ].filter(String).join(" ");
61
61
 
62
62
  const result = [firstLine];
@@ -17,9 +17,9 @@
17
17
  function getMessageType(message) {
18
18
  if (message.fatal || message.severity === 2) {
19
19
  return "Error";
20
- } else {
21
- return "Warning";
22
20
  }
21
+ return "Warning";
22
+
23
23
  }
24
24
 
25
25
 
@@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
19
19
  function getMessageType(message) {
20
20
  if (message.fatal || message.severity === 2) {
21
21
  return "Error";
22
- } else {
23
- return "Warning";
24
22
  }
23
+ return "Warning";
24
+
25
25
  }
26
26
 
27
27
  //------------------------------------------------------------------------------
@@ -18,9 +18,9 @@ const yaml = require("js-yaml");
18
18
  function getMessageType(message) {
19
19
  if (message.fatal || message.severity === 2) {
20
20
  return "error";
21
- } else {
22
- return "warning";
23
21
  }
22
+ return "warning";
23
+
24
24
  }
25
25
 
26
26
  /**
@@ -16,9 +16,9 @@
16
16
  function getMessageType(message) {
17
17
  if (message.fatal || message.severity === 2) {
18
18
  return "Error";
19
- } else {
20
- return "Warning";
21
19
  }
20
+ return "Warning";
21
+
22
22
  }
23
23
 
24
24
 
@@ -18,9 +18,9 @@
18
18
  function getMessageType(message) {
19
19
  if (message.fatal || message.severity === 2) {
20
20
  return "error";
21
- } else {
22
- return "warning";
23
21
  }
22
+ return "warning";
23
+
24
24
  }
25
25
 
26
26
 
@@ -71,7 +71,7 @@ function checkMetaDocsDescription(context, exportsNode) {
71
71
  if (description === "") {
72
72
  context.report({
73
73
  node: metaDocsDescription.value,
74
- message: "`meta.docs.description` should not be empty.",
74
+ message: "`meta.docs.description` should not be empty."
75
75
  });
76
76
  return;
77
77
  }
@@ -8,7 +8,7 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const RuleFixer = require("./util/rule-fixer");
11
+ const ruleFixer = require("./util/rule-fixer");
12
12
 
13
13
  //------------------------------------------------------------------------------
14
14
  // Constants
@@ -124,7 +124,7 @@ class RuleContext {
124
124
 
125
125
  // if there's a fix specified, get it
126
126
  if (typeof descriptor.fix === "function") {
127
- fix = descriptor.fix(new RuleFixer());
127
+ fix = descriptor.fix(ruleFixer);
128
128
  }
129
129
 
130
130
  this.eslint.report(
@@ -4,6 +4,12 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const astUtils = require("../ast-utils");
12
+
7
13
  //------------------------------------------------------------------------------
8
14
  // Rule Definition
9
15
  //------------------------------------------------------------------------------
@@ -136,10 +142,7 @@ module.exports = {
136
142
  loc: arrowBody.loc.start,
137
143
  message: "Expected block statement surrounding arrow body.",
138
144
  fix(fixer) {
139
- const lastTokenBeforeBody = sourceCode.getTokensBetween(sourceCode.getFirstToken(node), arrowBody)
140
- .reverse()
141
- .find(token => token.value !== "(");
142
-
145
+ const lastTokenBeforeBody = sourceCode.getLastTokenBetween(sourceCode.getFirstToken(node), arrowBody, astUtils.isNotOpeningParenToken);
143
146
  const firstBodyToken = sourceCode.getTokenAfter(lastTokenBeforeBody);
144
147
 
145
148
  return fixer.replaceTextRange(
@@ -4,6 +4,12 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const astUtils = require("../ast-utils");
12
+
7
13
  //------------------------------------------------------------------------------
8
14
  // Rule Definition
9
15
  //------------------------------------------------------------------------------
@@ -51,12 +57,7 @@ module.exports = {
51
57
  * @returns {Object} Tokens of arrow and before/after arrow.
52
58
  */
53
59
  function getTokens(node) {
54
- let arrow = sourceCode.getTokenBefore(node.body);
55
-
56
- // skip '(' tokens.
57
- while (arrow.value !== "=>") {
58
- arrow = sourceCode.getTokenBefore(arrow);
59
- }
60
+ const arrow = sourceCode.getTokenBefore(node.body, astUtils.isArrowToken);
60
61
 
61
62
  return {
62
63
  before: sourceCode.getTokenBefore(arrow),
@@ -74,8 +74,8 @@ module.exports = {
74
74
  // Gets braces and the first/last token of content.
75
75
  const openBrace = getOpenBrace(node);
76
76
  const closeBrace = sourceCode.getLastToken(node);
77
- const firstToken = sourceCode.getTokenOrCommentAfter(openBrace);
78
- const lastToken = sourceCode.getTokenOrCommentBefore(closeBrace);
77
+ const firstToken = sourceCode.getTokenAfter(openBrace, { includeComments: true });
78
+ const lastToken = sourceCode.getTokenBefore(closeBrace, { includeComments: true });
79
79
 
80
80
  // Skip if the node is invalid or empty.
81
81
  if (openBrace.type !== "Punctuator" ||