eslint 3.9.0 → 3.10.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +60 -1
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/bin/eslint.js +5 -5
  5. package/conf/eslint.json +1 -0
  6. package/lib/ast-utils.js +1 -3
  7. package/lib/cli-engine.js +9 -11
  8. package/lib/code-path-analysis/debug-helpers.js +4 -4
  9. package/lib/config/autoconfig.js +23 -35
  10. package/lib/config/config-file.js +1 -1
  11. package/lib/config/config-initializer.js +12 -20
  12. package/lib/config/config-ops.js +7 -9
  13. package/lib/config/config-rule.js +14 -18
  14. package/lib/config/config-validator.js +3 -3
  15. package/lib/config/environments.js +1 -1
  16. package/lib/config.js +2 -2
  17. package/lib/eslint.js +21 -23
  18. package/lib/file-finder.js +1 -1
  19. package/lib/formatters/checkstyle.js +2 -2
  20. package/lib/formatters/compact.js +2 -2
  21. package/lib/formatters/html.js +9 -11
  22. package/lib/formatters/jslint-xml.js +2 -2
  23. package/lib/formatters/junit.js +2 -2
  24. package/lib/formatters/stylish.js +3 -7
  25. package/lib/formatters/table.js +4 -6
  26. package/lib/formatters/tap.js +2 -2
  27. package/lib/formatters/unix.js +2 -2
  28. package/lib/formatters/visualstudio.js +2 -2
  29. package/lib/load-rules.js +1 -1
  30. package/lib/rules/arrow-body-style.js +1 -1
  31. package/lib/rules/arrow-parens.js +9 -2
  32. package/lib/rules/brace-style.js +2 -2
  33. package/lib/rules/comma-spacing.js +2 -2
  34. package/lib/rules/comma-style.js +51 -4
  35. package/lib/rules/consistent-this.js +5 -9
  36. package/lib/rules/constructor-super.js +1 -1
  37. package/lib/rules/curly.js +10 -7
  38. package/lib/rules/default-case.js +1 -3
  39. package/lib/rules/eqeqeq.js +19 -7
  40. package/lib/rules/func-names.js +23 -4
  41. package/lib/rules/global-require.js +3 -7
  42. package/lib/rules/handle-callback-err.js +1 -3
  43. package/lib/rules/id-length.js +1 -1
  44. package/lib/rules/indent.js +10 -25
  45. package/lib/rules/key-spacing.js +4 -4
  46. package/lib/rules/keyword-spacing.js +1 -1
  47. package/lib/rules/lines-around-comment.js +5 -11
  48. package/lib/rules/lines-around-directive.js +23 -4
  49. package/lib/rules/max-len.js +5 -11
  50. package/lib/rules/max-lines.js +4 -12
  51. package/lib/rules/max-statements.js +11 -2
  52. package/lib/rules/newline-after-var.js +1 -1
  53. package/lib/rules/newline-before-return.js +2 -4
  54. package/lib/rules/no-alert.js +2 -4
  55. package/lib/rules/no-class-assign.js +1 -1
  56. package/lib/rules/no-const-assign.js +1 -1
  57. package/lib/rules/no-control-regex.js +2 -2
  58. package/lib/rules/no-duplicate-case.js +1 -1
  59. package/lib/rules/no-ex-assign.js +1 -1
  60. package/lib/rules/no-extend-native.js +3 -7
  61. package/lib/rules/no-extra-boolean-cast.js +14 -3
  62. package/lib/rules/no-extra-parens.js +4 -4
  63. package/lib/rules/no-func-assign.js +1 -1
  64. package/lib/rules/no-implicit-globals.js +4 -4
  65. package/lib/rules/no-irregular-whitespace.js +3 -3
  66. package/lib/rules/no-mixed-operators.js +1 -3
  67. package/lib/rules/no-mixed-requires.js +2 -2
  68. package/lib/rules/no-mixed-spaces-and-tabs.js +3 -3
  69. package/lib/rules/no-multi-spaces.js +1 -1
  70. package/lib/rules/no-new-symbol.js +1 -1
  71. package/lib/rules/no-redeclare.js +2 -4
  72. package/lib/rules/no-restricted-globals.js +2 -2
  73. package/lib/rules/no-restricted-imports.js +45 -11
  74. package/lib/rules/no-restricted-modules.js +53 -36
  75. package/lib/rules/no-restricted-syntax.js +2 -4
  76. package/lib/rules/no-return-await.js +77 -0
  77. package/lib/rules/no-tabs.js +1 -1
  78. package/lib/rules/no-this-before-super.js +2 -2
  79. package/lib/rules/no-undef.js +1 -1
  80. package/lib/rules/no-underscore-dangle.js +1 -3
  81. package/lib/rules/no-unused-vars.js +2 -6
  82. package/lib/rules/no-use-before-define.js +1 -1
  83. package/lib/rules/no-useless-escape.js +8 -54
  84. package/lib/rules/no-useless-return.js +6 -0
  85. package/lib/rules/no-warning-comments.js +2 -2
  86. package/lib/rules/object-shorthand.js +21 -10
  87. package/lib/rules/one-var-declaration-per-line.js +1 -1
  88. package/lib/rules/prefer-const.js +1 -3
  89. package/lib/rules/prefer-reflect.js +2 -1
  90. package/lib/rules/quote-props.js +1 -1
  91. package/lib/rules/quotes.js +1 -1
  92. package/lib/rules/radix.js +2 -2
  93. package/lib/rules/require-jsdoc.js +8 -0
  94. package/lib/rules/sort-vars.js +1 -1
  95. package/lib/rules/space-in-parens.js +1 -1
  96. package/lib/rules/space-infix-ops.js +1 -1
  97. package/lib/rules/spaced-comment.js +1 -1
  98. package/lib/rules/symbol-description.js +1 -1
  99. package/lib/rules/valid-jsdoc.js +3 -3
  100. package/lib/rules.js +2 -2
  101. package/lib/testers/event-generator-tester.js +5 -5
  102. package/lib/testers/rule-tester.js +11 -13
  103. package/lib/timing.js +11 -13
  104. package/lib/util/comment-event-generator.js +1 -1
  105. package/lib/util/glob-util.js +3 -5
  106. package/lib/util/npm-util.js +1 -1
  107. package/lib/util/source-code-fixer.js +3 -5
  108. package/lib/util/source-code-util.js +4 -4
  109. package/lib/util/source-code.js +3 -3
  110. package/lib/util/traverser.js +1 -3
  111. package/lib/util/xml-escape.js +1 -1
  112. package/package.json +3 -3
@@ -23,7 +23,7 @@ const rules = require("../rules"),
23
23
  * @returns {Array[]} An array of arrays.
24
24
  */
25
25
  function explodeArray(xs) {
26
- return xs.reduce(function(accumulator, x) {
26
+ return xs.reduce((accumulator, x) => {
27
27
  accumulator.push([x]);
28
28
  return accumulator;
29
29
  }, []);
@@ -49,8 +49,8 @@ function combineArrays(arr1, arr2) {
49
49
  if (arr2.length === 0) {
50
50
  return explodeArray(arr1);
51
51
  }
52
- arr1.forEach(function(x1) {
53
- arr2.forEach(function(x2) {
52
+ arr1.forEach(x1 => {
53
+ arr2.forEach(x2 => {
54
54
  res.push([].concat(x1, x2));
55
55
  });
56
56
  });
@@ -78,16 +78,14 @@ function combineArrays(arr1, arr2) {
78
78
  * @returns {Array[]} Array of arrays of objects grouped by property
79
79
  */
80
80
  function groupByProperty(objects) {
81
- const groupedObj = objects.reduce(function(accumulator, obj) {
81
+ const groupedObj = objects.reduce((accumulator, obj) => {
82
82
  const prop = Object.keys(obj)[0];
83
83
 
84
84
  accumulator[prop] = accumulator[prop] ? accumulator[prop].concat(obj) : [obj];
85
85
  return accumulator;
86
86
  }, {});
87
87
 
88
- return Object.keys(groupedObj).map(function(prop) {
89
- return groupedObj[prop];
90
- });
88
+ return Object.keys(groupedObj).map(prop => groupedObj[prop]);
91
89
  }
92
90
 
93
91
 
@@ -152,16 +150,16 @@ function combinePropertyObjects(objArr1, objArr2) {
152
150
  if (objArr2.length === 0) {
153
151
  return objArr1;
154
152
  }
155
- objArr1.forEach(function(obj1) {
156
- objArr2.forEach(function(obj2) {
153
+ objArr1.forEach(obj1 => {
154
+ objArr2.forEach(obj2 => {
157
155
  const combinedObj = {};
158
156
  const obj1Props = Object.keys(obj1);
159
157
  const obj2Props = Object.keys(obj2);
160
158
 
161
- obj1Props.forEach(function(prop1) {
159
+ obj1Props.forEach(prop1 => {
162
160
  combinedObj[prop1] = obj1[prop1];
163
161
  });
164
- obj2Props.forEach(function(prop2) {
162
+ obj2Props.forEach(prop2 => {
165
163
  combinedObj[prop2] = obj2[prop2];
166
164
  });
167
165
  res.push(combinedObj);
@@ -205,7 +203,7 @@ RuleConfigSet.prototype = {
205
203
  addErrorSeverity(severity) {
206
204
  severity = severity || 2;
207
205
 
208
- this.ruleConfigs = this.ruleConfigs.map(function(config) {
206
+ this.ruleConfigs = this.ruleConfigs.map(config => {
209
207
  config.unshift(severity);
210
208
  return config;
211
209
  });
@@ -241,9 +239,7 @@ RuleConfigSet.prototype = {
241
239
  },
242
240
 
243
241
  combine() {
244
- this.objectConfigs = groupByProperty(this.objectConfigs).reduce(function(accumulator, objArr) {
245
- return combinePropertyObjects(accumulator, objArr);
246
- }, []);
242
+ this.objectConfigs = groupByProperty(this.objectConfigs).reduce((accumulator, objArr) => combinePropertyObjects(accumulator, objArr), []);
247
243
  }
248
244
  };
249
245
 
@@ -251,7 +247,7 @@ RuleConfigSet.prototype = {
251
247
  * The object schema could have multiple independent properties.
252
248
  * If any contain enums or booleans, they can be added and then combined
253
249
  */
254
- Object.keys(obj.properties).forEach(function(prop) {
250
+ Object.keys(obj.properties).forEach(prop => {
255
251
  if (obj.properties[prop].enum) {
256
252
  objectConfigSet.add(prop, obj.properties[prop].enum);
257
253
  }
@@ -276,7 +272,7 @@ function generateConfigsFromSchema(schema) {
276
272
  const configSet = new RuleConfigSet();
277
273
 
278
274
  if (Array.isArray(schema)) {
279
- schema.forEach(function(opt) {
275
+ schema.forEach(opt => {
280
276
  if (opt.enum) {
281
277
  configSet.addEnums(opt.enum);
282
278
  }
@@ -302,7 +298,7 @@ function generateConfigsFromSchema(schema) {
302
298
  function createCoreRuleConfigs() {
303
299
  const ruleList = loadRules();
304
300
 
305
- return Object.keys(ruleList).reduce(function(accumulator, id) {
301
+ return Object.keys(ruleList).reduce((accumulator, id) => {
306
302
  const rule = rules.get(id);
307
303
  const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema;
308
304
 
@@ -105,7 +105,7 @@ function validateRuleOptions(id, options, source) {
105
105
  }
106
106
 
107
107
  if (validateRule && validateRule.errors) {
108
- validateRule.errors.forEach(function(error) {
108
+ validateRule.errors.forEach(error => {
109
109
  message.push(
110
110
  "\tValue \"", error.value, "\" ", error.message, ".\n"
111
111
  );
@@ -134,7 +134,7 @@ function validateEnvironment(environment, source) {
134
134
  }
135
135
 
136
136
  if (typeof environment === "object") {
137
- Object.keys(environment).forEach(function(env) {
137
+ Object.keys(environment).forEach(env => {
138
138
  if (!Environments.get(env)) {
139
139
  const message = [
140
140
  source, ":\n",
@@ -158,7 +158,7 @@ function validateEnvironment(environment, source) {
158
158
  function validate(config, source) {
159
159
 
160
160
  if (typeof config.rules === "object") {
161
- Object.keys(config.rules).forEach(function(id) {
161
+ Object.keys(config.rules).forEach(id => {
162
162
  validateRuleOptions(id, config.rules[id], source);
163
163
  });
164
164
  }
@@ -22,7 +22,7 @@ let environments = new Map();
22
22
  * @private
23
23
  */
24
24
  function load() {
25
- Object.keys(envs).forEach(function(envName) {
25
+ Object.keys(envs).forEach(envName => {
26
26
  environments.set(envName, envs[envName]);
27
27
  });
28
28
  }
package/lib/config.js CHANGED
@@ -197,7 +197,7 @@ function Config(options) {
197
197
 
198
198
  this.useEslintrc = (options.useEslintrc !== false);
199
199
 
200
- this.env = (options.envs || []).reduce(function(envs, name) {
200
+ this.env = (options.envs || []).reduce((envs, name) => {
201
201
  envs[name] = true;
202
202
  return envs;
203
203
  }, {});
@@ -208,7 +208,7 @@ function Config(options) {
208
208
  * whether global is writable.
209
209
  * If user declares "foo", convert to "foo:false".
210
210
  */
211
- this.globals = (options.globals || []).reduce(function(globals, def) {
211
+ this.globals = (options.globals || []).reduce((globals, def) => {
212
212
  const parts = def.split(":");
213
213
 
214
214
  globals[parts[0]] = (parts.length > 1 && parts[1] === "true");
package/lib/eslint.js CHANGED
@@ -57,7 +57,7 @@ function parseBooleanConfig(string, comment) {
57
57
  // Collapse whitespace around `:` and `,` to make parsing easier
58
58
  string = string.replace(/\s*([:,])\s*/g, "$1");
59
59
 
60
- string.split(/\s|,+/).forEach(function(name) {
60
+ string.split(/\s|,+/).forEach(name => {
61
61
  if (!name) {
62
62
  return;
63
63
  }
@@ -138,7 +138,7 @@ function parseListConfig(string) {
138
138
  // Collapse whitespace around ,
139
139
  string = string.replace(/\s*,\s*/g, ",");
140
140
 
141
- string.split(/,+/).forEach(function(name) {
141
+ string.split(/,+/).forEach(name => {
142
142
  name = name.trim();
143
143
  if (!name) {
144
144
  return;
@@ -165,7 +165,7 @@ function addDeclaredGlobals(program, globalScope, config) {
165
165
 
166
166
  Object.assign(declaredGlobals, builtin);
167
167
 
168
- Object.keys(config.env).forEach(function(name) {
168
+ Object.keys(config.env).forEach(name => {
169
169
  if (config.env[name]) {
170
170
  const env = Environments.get(name),
171
171
  environmentGlobals = env && env.globals;
@@ -180,7 +180,7 @@ function addDeclaredGlobals(program, globalScope, config) {
180
180
  Object.assign(declaredGlobals, config.globals);
181
181
  Object.assign(explicitGlobals, config.astGlobals);
182
182
 
183
- Object.keys(declaredGlobals).forEach(function(name) {
183
+ Object.keys(declaredGlobals).forEach(name => {
184
184
  let variable = globalScope.set.get(name);
185
185
 
186
186
  if (!variable) {
@@ -192,7 +192,7 @@ function addDeclaredGlobals(program, globalScope, config) {
192
192
  variable.writeable = declaredGlobals[name];
193
193
  });
194
194
 
195
- Object.keys(explicitGlobals).forEach(function(name) {
195
+ Object.keys(explicitGlobals).forEach(name => {
196
196
  let variable = globalScope.set.get(name);
197
197
 
198
198
  if (!variable) {
@@ -206,7 +206,7 @@ function addDeclaredGlobals(program, globalScope, config) {
206
206
  });
207
207
 
208
208
  // mark all exported variables as such
209
- Object.keys(exportedGlobals).forEach(function(name) {
209
+ Object.keys(exportedGlobals).forEach(name => {
210
210
  const variable = globalScope.set.get(name);
211
211
 
212
212
  if (variable) {
@@ -219,7 +219,7 @@ function addDeclaredGlobals(program, globalScope, config) {
219
219
  * Since we augment the global scope using configuration, we need to update
220
220
  * references and remove the ones that were added by configuration.
221
221
  */
222
- globalScope.through = globalScope.through.filter(function(reference) {
222
+ globalScope.through = globalScope.through.filter(reference => {
223
223
  const name = reference.identifier.name;
224
224
  const variable = globalScope.set.get(name);
225
225
 
@@ -250,7 +250,7 @@ function addDeclaredGlobals(program, globalScope, config) {
250
250
  function disableReporting(reportingConfig, start, rulesToDisable) {
251
251
 
252
252
  if (rulesToDisable.length) {
253
- rulesToDisable.forEach(function(rule) {
253
+ rulesToDisable.forEach(rule => {
254
254
  reportingConfig.push({
255
255
  start,
256
256
  end: null,
@@ -278,7 +278,7 @@ function enableReporting(reportingConfig, start, rulesToEnable) {
278
278
  let i;
279
279
 
280
280
  if (rulesToEnable.length) {
281
- rulesToEnable.forEach(function(rule) {
281
+ rulesToEnable.forEach(rule => {
282
282
  for (i = reportingConfig.length - 1; i >= 0; i--) {
283
283
  if (!reportingConfig[i].end && reportingConfig[i].rule === rule) {
284
284
  reportingConfig[i].end = start;
@@ -325,7 +325,7 @@ function modifyConfigsFromComments(filename, ast, config, reportingConfig, messa
325
325
  };
326
326
  const commentRules = {};
327
327
 
328
- ast.comments.forEach(function(comment) {
328
+ ast.comments.forEach(comment => {
329
329
 
330
330
  let value = comment.value.trim();
331
331
  const match = /^(eslint(-\w+){0,3}|exported|globals?)(\s|$)/.exec(value);
@@ -359,7 +359,7 @@ function modifyConfigsFromComments(filename, ast, config, reportingConfig, messa
359
359
  case "eslint": {
360
360
  const items = parseJsonConfig(value, comment.loc, messages);
361
361
 
362
- Object.keys(items).forEach(function(name) {
362
+ Object.keys(items).forEach(name => {
363
363
  const ruleValue = items[name];
364
364
 
365
365
  validator.validateRuleOptions(name, ruleValue, `${filename} line ${comment.loc.start.line}`);
@@ -383,7 +383,7 @@ function modifyConfigsFromComments(filename, ast, config, reportingConfig, messa
383
383
  });
384
384
 
385
385
  // apply environment configs
386
- Object.keys(commentConfig.env).forEach(function(name) {
386
+ Object.keys(commentConfig.env).forEach(name => {
387
387
  const env = Environments.get(name);
388
388
 
389
389
  if (env) {
@@ -454,7 +454,7 @@ function prepareConfig(config) {
454
454
  let parserOptions = {};
455
455
 
456
456
  if (typeof config.rules === "object") {
457
- Object.keys(config.rules).forEach(function(k) {
457
+ Object.keys(config.rules).forEach(k => {
458
458
  const rule = config.rules[k];
459
459
 
460
460
  if (rule === null) {
@@ -470,7 +470,7 @@ function prepareConfig(config) {
470
470
 
471
471
  // merge in environment parserOptions
472
472
  if (typeof config.env === "object") {
473
- Object.keys(config.env).forEach(function(envName) {
473
+ Object.keys(config.env).forEach(envName => {
474
474
  const env = Environments.get(envName);
475
475
 
476
476
  if (config.env[envName] && env && env.parserOptions) {
@@ -797,7 +797,7 @@ module.exports = (function() {
797
797
  }
798
798
 
799
799
  parseResult = parse(
800
- stripUnicodeBOM(text).replace(/^#!([^\r\n]+)/, function(match, captured) {
800
+ stripUnicodeBOM(text).replace(/^#!([^\r\n]+)/, (match, captured) => {
801
801
  shebang = captured;
802
802
  return `//${captured}`;
803
803
  }),
@@ -834,9 +834,7 @@ module.exports = (function() {
834
834
  ConfigOps.normalize(config);
835
835
 
836
836
  // enable appropriate rules
837
- Object.keys(config.rules).filter(function(key) {
838
- return getRuleSeverity(config.rules[key]) > 0;
839
- }).forEach(function(key) {
837
+ Object.keys(config.rules).filter(key => getRuleSeverity(config.rules[key]) > 0).forEach(key => {
840
838
  let ruleCreator;
841
839
 
842
840
  ruleCreator = rules.get(key);
@@ -867,7 +865,7 @@ module.exports = (function() {
867
865
  ruleCreator(ruleContext);
868
866
 
869
867
  // add all the node types as listeners
870
- Object.keys(rule).forEach(function(nodeType) {
868
+ Object.keys(rule).forEach(nodeType => {
871
869
  api.on(nodeType, timing.enabled
872
870
  ? timing.time(key, rule[nodeType])
873
871
  : rule[nodeType]
@@ -933,7 +931,7 @@ module.exports = (function() {
933
931
  }
934
932
 
935
933
  // sort by line and column
936
- messages.sort(function(a, b) {
934
+ messages.sort((a, b) => {
937
935
  const lineDiff = a.line - b.line;
938
936
 
939
937
  if (lineDiff === 0) {
@@ -986,7 +984,7 @@ module.exports = (function() {
986
984
  }
987
985
 
988
986
  if (opts) {
989
- message = message.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, function(fullMatch, term) {
987
+ message = message.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, (fullMatch, term) => {
990
988
  if (term in opts) {
991
989
  return opts[term];
992
990
  }
@@ -1056,7 +1054,7 @@ module.exports = (function() {
1056
1054
  };
1057
1055
 
1058
1056
  // copy over methods
1059
- Object.keys(externalMethods).forEach(function(methodName) {
1057
+ Object.keys(externalMethods).forEach(methodName => {
1060
1058
  const exMethodName = externalMethods[methodName];
1061
1059
 
1062
1060
  // All functions expected to have less arguments than 5.
@@ -1181,7 +1179,7 @@ module.exports = (function() {
1181
1179
  * @returns {void}
1182
1180
  */
1183
1181
  api.defineRules = function(rulesToDefine) {
1184
- Object.getOwnPropertyNames(rulesToDefine).forEach(function(ruleId) {
1182
+ Object.getOwnPropertyNames(rulesToDefine).forEach(ruleId => {
1185
1183
  defineRule(ruleId, rulesToDefine[ruleId]);
1186
1184
  });
1187
1185
  };
@@ -57,7 +57,7 @@ function FileFinder(files, cwd) {
57
57
  function normalizeDirectoryEntries(entries, directory, supportedConfigs) {
58
58
  const fileHash = {};
59
59
 
60
- entries.forEach(function(entry) {
60
+ entries.forEach(entry => {
61
61
  if (supportedConfigs.indexOf(entry) >= 0) {
62
62
  const resolvedEntry = path.resolve(directory, entry);
63
63
 
@@ -35,12 +35,12 @@ module.exports = function(results) {
35
35
  output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
36
36
  output += "<checkstyle version=\"4.3\">";
37
37
 
38
- results.forEach(function(result) {
38
+ results.forEach(result => {
39
39
  const messages = result.messages;
40
40
 
41
41
  output += `<file name="${xmlEscape(result.filePath)}">`;
42
42
 
43
- messages.forEach(function(message) {
43
+ messages.forEach(message => {
44
44
  output += [
45
45
  `<error line="${xmlEscape(message.line)}"`,
46
46
  `column="${xmlEscape(message.column)}"`,
@@ -32,13 +32,13 @@ module.exports = function(results) {
32
32
  let output = "",
33
33
  total = 0;
34
34
 
35
- results.forEach(function(result) {
35
+ results.forEach(result => {
36
36
 
37
37
  const messages = result.messages;
38
38
 
39
39
  total += messages.length;
40
40
 
41
- messages.forEach(function(message) {
41
+ messages.forEach(message => {
42
42
 
43
43
  output += `${result.filePath}: `;
44
44
  output += `line ${message.line || 0}`;
@@ -70,7 +70,7 @@ function renderMessages(messages, parentIndex) {
70
70
  * @param {Object} message Message.
71
71
  * @returns {string} HTML (table row) describing a message.
72
72
  */
73
- return lodash.map(messages, function(message) {
73
+ return lodash.map(messages, message => {
74
74
  const lineNumber = message.line || 0;
75
75
  const columnNumber = message.column || 0;
76
76
 
@@ -91,15 +91,13 @@ function renderMessages(messages, parentIndex) {
91
91
  * @returns {string} HTML string describing the results.
92
92
  */
93
93
  function renderResults(results) {
94
- return lodash.map(results, function(result, index) {
95
- return resultTemplate({
96
- index,
97
- color: renderColor(result.errorCount, result.warningCount),
98
- filePath: result.filePath,
99
- summary: renderSummary(result.errorCount, result.warningCount)
100
-
101
- }) + renderMessages(result.messages, index);
102
- }).join("\n");
94
+ return lodash.map(results, (result, index) => resultTemplate({
95
+ index,
96
+ color: renderColor(result.errorCount, result.warningCount),
97
+ filePath: result.filePath,
98
+ summary: renderSummary(result.errorCount, result.warningCount)
99
+
100
+ }) + renderMessages(result.messages, index)).join("\n");
103
101
  }
104
102
 
105
103
  //------------------------------------------------------------------------------
@@ -114,7 +112,7 @@ module.exports = function(results) {
114
112
  totalWarnings = 0;
115
113
 
116
114
  // Iterate over results to get totals
117
- results.forEach(function(result) {
115
+ results.forEach(result => {
118
116
  totalErrors += result.errorCount;
119
117
  totalWarnings += result.warningCount;
120
118
  });
@@ -17,12 +17,12 @@ module.exports = function(results) {
17
17
  output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
18
18
  output += "<jslint>";
19
19
 
20
- results.forEach(function(result) {
20
+ results.forEach(result => {
21
21
  const messages = result.messages;
22
22
 
23
23
  output += `<file name="${result.filePath}">`;
24
24
 
25
- messages.forEach(function(message) {
25
+ messages.forEach(message => {
26
26
  output += [
27
27
  `<issue line="${message.line}"`,
28
28
  `char="${message.column}"`,
@@ -35,7 +35,7 @@ module.exports = function(results) {
35
35
  output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
36
36
  output += "<testsuites>\n";
37
37
 
38
- results.forEach(function(result) {
38
+ results.forEach(result => {
39
39
 
40
40
  const messages = result.messages;
41
41
 
@@ -43,7 +43,7 @@ module.exports = function(results) {
43
43
  output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
44
44
  }
45
45
 
46
- messages.forEach(function(message) {
46
+ messages.forEach(message => {
47
47
  const type = message.fatal ? "error" : "failure";
48
48
 
49
49
  output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}">`;
@@ -33,7 +33,7 @@ module.exports = function(results) {
33
33
  warnings = 0,
34
34
  summaryColor = "yellow";
35
35
 
36
- results.forEach(function(result) {
36
+ results.forEach(result => {
37
37
  const messages = result.messages;
38
38
 
39
39
  if (messages.length === 0) {
@@ -44,7 +44,7 @@ module.exports = function(results) {
44
44
  output += `${chalk.underline(result.filePath)}\n`;
45
45
 
46
46
  output += `${table(
47
- messages.map(function(message) {
47
+ messages.map(message => {
48
48
  let messageType;
49
49
 
50
50
  if (message.fatal || message.severity === 2) {
@@ -71,11 +71,7 @@ module.exports = function(results) {
71
71
  return chalk.stripColor(str).length;
72
72
  }
73
73
  }
74
- ).split("\n").map(function(el) {
75
- return el.replace(/(\d+)\s+(\d+)/, function(m, p1, p2) {
76
- return chalk.dim(`${p1}:${p2}`);
77
- });
78
- }).join("\n")}\n\n`;
74
+ ).split("\n").map(el => el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.dim(`${p1}:${p2}`))).join("\n")}\n\n`;
79
75
  });
80
76
 
81
77
  if (total > 0) {
@@ -36,7 +36,7 @@ function drawTable(messages) {
36
36
  chalk.bold("Rule ID")
37
37
  ]);
38
38
 
39
- messages.forEach(function(message) {
39
+ messages.forEach(message => {
40
40
  let messageType;
41
41
 
42
42
  if (message.fatal || message.severity === 2) {
@@ -92,7 +92,7 @@ function drawTable(messages) {
92
92
  function drawReport(results) {
93
93
  let files;
94
94
 
95
- files = results.map(function(result) {
95
+ files = results.map(result => {
96
96
  if (!result.messages.length) {
97
97
  return "";
98
98
  }
@@ -100,9 +100,7 @@ function drawReport(results) {
100
100
  return `\n${result.filePath}\n\n${drawTable(result.messages)}`;
101
101
  });
102
102
 
103
- files = files.filter(function(content) {
104
- return content.trim();
105
- });
103
+ files = files.filter(content => content.trim());
106
104
 
107
105
  return files.join("");
108
106
  }
@@ -120,7 +118,7 @@ module.exports = function(report) {
120
118
  errorCount = 0;
121
119
  warningCount = 0;
122
120
 
123
- report.forEach(function(fileReport) {
121
+ report.forEach(fileReport => {
124
122
  errorCount += fileReport.errorCount;
125
123
  warningCount += fileReport.warningCount;
126
124
  });
@@ -44,7 +44,7 @@ function outputDiagnostics(diagnostic) {
44
44
  module.exports = function(results) {
45
45
  let output = `TAP version 13\n1..${results.length}\n`;
46
46
 
47
- results.forEach(function(result, id) {
47
+ results.forEach((result, id) => {
48
48
  const messages = result.messages;
49
49
  let testResult = "ok";
50
50
  let diagnostics = {};
@@ -52,7 +52,7 @@ module.exports = function(results) {
52
52
  if (messages.length > 0) {
53
53
  testResult = "not ok";
54
54
 
55
- messages.forEach(function(message) {
55
+ messages.forEach(message => {
56
56
  const diagnostic = {
57
57
  message: message.message,
58
58
  severity: getMessageType(message),
@@ -31,13 +31,13 @@ module.exports = function(results) {
31
31
  let output = "",
32
32
  total = 0;
33
33
 
34
- results.forEach(function(result) {
34
+ results.forEach(result => {
35
35
 
36
36
  const messages = result.messages;
37
37
 
38
38
  total += messages.length;
39
39
 
40
- messages.forEach(function(message) {
40
+ messages.forEach(message => {
41
41
 
42
42
  output += `${result.filePath}:`;
43
43
  output += `${message.line || 0}:`;
@@ -33,13 +33,13 @@ module.exports = function(results) {
33
33
  let output = "",
34
34
  total = 0;
35
35
 
36
- results.forEach(function(result) {
36
+ results.forEach(result => {
37
37
 
38
38
  const messages = result.messages;
39
39
 
40
40
  total += messages.length;
41
41
 
42
- messages.forEach(function(message) {
42
+ messages.forEach(message => {
43
43
 
44
44
  output += result.filePath;
45
45
  output += `(${message.line || 0}`;
package/lib/load-rules.js CHANGED
@@ -31,7 +31,7 @@ module.exports = function(rulesDir, cwd) {
31
31
 
32
32
  const rules = Object.create(null);
33
33
 
34
- fs.readdirSync(rulesDir).forEach(function(file) {
34
+ fs.readdirSync(rulesDir).forEach(file => {
35
35
  if (path.extname(file) !== ".js") {
36
36
  return;
37
37
  }
@@ -124,7 +124,7 @@ module.exports = {
124
124
  */
125
125
  return fixer.replaceText(
126
126
  arrowBody,
127
- (textBeforeReturn + textBetweenReturnAndValue).replace(/^ *$/, "") + returnValueText + (textAfterValue + textAfterReturnStatement).replace(/^ *$/, "")
127
+ (textBeforeReturn + textBetweenReturnAndValue).replace(/^\s*$/, "") + returnValueText + (textAfterValue + textAfterReturnStatement).replace(/^\s*$/, "")
128
128
  );
129
129
  }
130
130
  });
@@ -58,7 +58,9 @@ module.exports = {
58
58
  requireForBlockBody &&
59
59
  node.params.length === 1 &&
60
60
  node.params[0].type === "Identifier" &&
61
- node.body.type !== "BlockStatement"
61
+ !node.params[0].typeAnnotation &&
62
+ node.body.type !== "BlockStatement" &&
63
+ !node.returnType
62
64
  ) {
63
65
  if (token.type === "Punctuator" && token.value === "(") {
64
66
  context.report({
@@ -95,7 +97,12 @@ module.exports = {
95
97
  }
96
98
 
97
99
  // "as-needed": x => x
98
- if (asNeeded && node.params.length === 1 && node.params[0].type === "Identifier") {
100
+ if (asNeeded &&
101
+ node.params.length === 1 &&
102
+ node.params[0].type === "Identifier" &&
103
+ !node.params[0].typeAnnotation &&
104
+ !node.returnType
105
+ ) {
99
106
  if (token.type === "Punctuator" && token.value === "(") {
100
107
  context.report({
101
108
  node,
@@ -105,7 +105,7 @@ module.exports = {
105
105
  const blockProperties = arguments;
106
106
 
107
107
  return function(node) {
108
- Array.prototype.forEach.call(blockProperties, function(blockProp) {
108
+ Array.prototype.forEach.call(blockProperties, blockProp => {
109
109
  const block = node[blockProp];
110
110
 
111
111
  if (!isBlock(block)) {
@@ -143,7 +143,7 @@ module.exports = {
143
143
  });
144
144
  }
145
145
 
146
- if (curlyTokenEnd.loc.start.line === block.body[block.body.length - 1].loc.start.line) {
146
+ if (curlyTokenEnd.loc.start.line === block.body[block.body.length - 1].loc.end.line) {
147
147
  context.report({
148
148
  node: block.body[block.body.length - 1],
149
149
  message: CLOSE_MESSAGE_SINGLE,