eslint 7.26.0 → 7.27.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 (54) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +7 -2
  3. package/bin/eslint.js +2 -12
  4. package/lib/cli-engine/file-enumerator.js +1 -1
  5. package/lib/cli-engine/formatters/html.js +193 -9
  6. package/lib/init/autoconfig.js +2 -2
  7. package/lib/linter/apply-disable-directives.js +15 -3
  8. package/lib/linter/linter.js +6 -4
  9. package/lib/linter/node-event-generator.js +43 -6
  10. package/lib/rule-tester/rule-tester.js +14 -10
  11. package/lib/rules/comma-dangle.js +16 -7
  12. package/lib/rules/comma-spacing.js +1 -1
  13. package/lib/rules/complexity.js +2 -3
  14. package/lib/rules/consistent-return.js +2 -2
  15. package/lib/rules/eol-last.js +2 -7
  16. package/lib/rules/indent.js +8 -9
  17. package/lib/rules/max-lines-per-function.js +2 -3
  18. package/lib/rules/max-lines.js +32 -7
  19. package/lib/rules/max-params.js +2 -3
  20. package/lib/rules/max-statements.js +2 -3
  21. package/lib/rules/no-fallthrough.js +2 -8
  22. package/lib/rules/no-restricted-imports.js +61 -24
  23. package/lib/rules/no-unused-vars.js +27 -3
  24. package/lib/rules/no-useless-backreference.js +1 -2
  25. package/lib/rules/no-useless-computed-key.js +8 -2
  26. package/lib/rules/no-warning-comments.js +1 -1
  27. package/lib/rules/object-curly-newline.js +19 -4
  28. package/lib/rules/spaced-comment.js +2 -2
  29. package/lib/rules/utils/ast-utils.js +2 -2
  30. package/lib/shared/deprecation-warnings.js +12 -3
  31. package/lib/shared/string-utils.js +22 -0
  32. package/lib/source-code/source-code.js +6 -5
  33. package/lib/source-code/token-store/utils.js +4 -12
  34. package/messages/{all-files-ignored.txt → all-files-ignored.js} +10 -2
  35. package/messages/extend-config-missing.js +13 -0
  36. package/messages/failed-to-read-json.js +11 -0
  37. package/messages/file-not-found.js +10 -0
  38. package/messages/{no-config-found.txt → no-config-found.js} +9 -1
  39. package/messages/plugin-conflict.js +22 -0
  40. package/messages/plugin-invalid.js +16 -0
  41. package/messages/plugin-missing.js +19 -0
  42. package/messages/{print-config-with-directory-path.txt → print-config-with-directory-path.js} +6 -0
  43. package/messages/whitespace-found.js +11 -0
  44. package/package.json +5 -4
  45. package/lib/cli-engine/formatters/html-template-message.html +0 -8
  46. package/lib/cli-engine/formatters/html-template-page.html +0 -115
  47. package/lib/cli-engine/formatters/html-template-result.html +0 -6
  48. package/messages/extend-config-missing.txt +0 -5
  49. package/messages/failed-to-read-json.txt +0 -3
  50. package/messages/file-not-found.txt +0 -2
  51. package/messages/plugin-conflict.txt +0 -7
  52. package/messages/plugin-invalid.txt +0 -8
  53. package/messages/plugin-missing.txt +0 -11
  54. package/messages/whitespace-found.txt +0 -3
@@ -8,8 +8,8 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const lodash = require("lodash");
12
11
  const astUtils = require("./utils/ast-utils");
12
+ const { upperCaseFirst } = require("../shared/string-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -164,7 +164,7 @@ module.exports = {
164
164
  funcInfo.data = {
165
165
  name: funcInfo.node.type === "Program"
166
166
  ? "Program"
167
- : lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node))
167
+ : upperCaseFirst(astUtils.getFunctionNameWithKind(funcInfo.node))
168
168
  };
169
169
  } else if (funcInfo.hasReturnValue !== hasReturnValue) {
170
170
  context.report({
@@ -4,12 +4,6 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- //------------------------------------------------------------------------------
8
- // Requirements
9
- //------------------------------------------------------------------------------
10
-
11
- const lodash = require("lodash");
12
-
13
7
  //------------------------------------------------------------------------------
14
8
  // Rule Definition
15
9
  //------------------------------------------------------------------------------
@@ -48,8 +42,9 @@ module.exports = {
48
42
  Program: function checkBadEOF(node) {
49
43
  const sourceCode = context.getSourceCode(),
50
44
  src = sourceCode.getText(),
45
+ lastLine = sourceCode.lines[sourceCode.lines.length - 1],
51
46
  location = {
52
- column: lodash.last(sourceCode.lines).length,
47
+ column: lastLine.length,
53
48
  line: sourceCode.lines.length
54
49
  },
55
50
  LF = "\n",
@@ -12,10 +12,10 @@
12
12
  // Requirements
13
13
  //------------------------------------------------------------------------------
14
14
 
15
- const lodash = require("lodash");
16
- const astUtils = require("./utils/ast-utils");
17
15
  const createTree = require("functional-red-black-tree");
18
16
 
17
+ const astUtils = require("./utils/ast-utils");
18
+
19
19
  //------------------------------------------------------------------------------
20
20
  // Rule Definition
21
21
  //------------------------------------------------------------------------------
@@ -1068,7 +1068,7 @@ module.exports = {
1068
1068
  const baseOffsetListeners = {
1069
1069
  "ArrayExpression, ArrayPattern"(node) {
1070
1070
  const openingBracket = sourceCode.getFirstToken(node);
1071
- const closingBracket = sourceCode.getTokenAfter(lodash.findLast(node.elements) || openingBracket, astUtils.isClosingBracketToken);
1071
+ const closingBracket = sourceCode.getTokenAfter([...node.elements].reverse().find(_ => _) || openingBracket, astUtils.isClosingBracketToken);
1072
1072
 
1073
1073
  addElementListIndent(node.elements, openingBracket, closingBracket, options.ArrayExpression);
1074
1074
  },
@@ -1560,8 +1560,9 @@ module.exports = {
1560
1560
  * 2. Don't set any offsets against the first token of the node.
1561
1561
  * 3. Call `ignoreNode` on the node sometime after exiting it and before validating offsets.
1562
1562
  */
1563
- const offsetListeners = lodash.mapValues(
1564
- baseOffsetListeners,
1563
+ const offsetListeners = {};
1564
+
1565
+ for (const [selector, listener] of Object.entries(baseOffsetListeners)) {
1565
1566
 
1566
1567
  /*
1567
1568
  * Offset listener calls are deferred until traversal is finished, and are called as
@@ -1579,10 +1580,8 @@ module.exports = {
1579
1580
  * To avoid this, the `Identifier` listener isn't called until traversal finishes and all
1580
1581
  * ignored nodes are known.
1581
1582
  */
1582
- listener =>
1583
- node =>
1584
- listenerCallQueue.push({ listener, node })
1585
- );
1583
+ offsetListeners[selector] = node => listenerCallQueue.push({ listener, node });
1584
+ }
1586
1585
 
1587
1586
  // For each ignored node selector, set up a listener to collect it into the `ignoredNodes` set.
1588
1587
  const ignoredNodes = new Set();
@@ -9,8 +9,7 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const astUtils = require("./utils/ast-utils");
12
-
13
- const lodash = require("lodash");
12
+ const { upperCaseFirst } = require("../shared/string-utils");
14
13
 
15
14
  //------------------------------------------------------------------------------
16
15
  // Constants
@@ -191,7 +190,7 @@ module.exports = {
191
190
  }
192
191
 
193
192
  if (lineCount > maxLines) {
194
- const name = lodash.upperFirst(astUtils.getFunctionNameWithKind(funcNode));
193
+ const name = upperCaseFirst(astUtils.getFunctionNameWithKind(funcNode));
195
194
 
196
195
  context.report({
197
196
  node,
@@ -8,9 +8,22 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const lodash = require("lodash");
12
11
  const astUtils = require("./utils/ast-utils");
13
12
 
13
+ //------------------------------------------------------------------------------
14
+ // Helpers
15
+ //------------------------------------------------------------------------------
16
+
17
+ /**
18
+ * Creates an array of numbers from `start` up to, but not including, `end`
19
+ * @param {number} start The start of the range
20
+ * @param {number} end The end of the range
21
+ * @returns {number[]} The range of numbers
22
+ */
23
+ function range(start, end) {
24
+ return [...Array(end - start).keys()].map(x => x + start);
25
+ }
26
+
14
27
  //------------------------------------------------------------------------------
15
28
  // Rule Definition
16
29
  //------------------------------------------------------------------------------
@@ -119,11 +132,25 @@ module.exports = {
119
132
  }
120
133
 
121
134
  if (start <= end) {
122
- return lodash.range(start, end + 1);
135
+ return range(start, end + 1);
123
136
  }
124
137
  return [];
125
138
  }
126
139
 
140
+ /**
141
+ * Returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level.
142
+ * TODO(stephenwade): Replace this with array.flatMap when we drop support for Node v10
143
+ * @param {any[]} array The array to process
144
+ * @param {Function} fn The function to use
145
+ * @returns {any[]} The result array
146
+ */
147
+ function flatMap(array, fn) {
148
+ const mapped = array.map(fn);
149
+ const flattened = [].concat(...mapped);
150
+
151
+ return flattened;
152
+ }
153
+
127
154
  return {
128
155
  "Program:exit"() {
129
156
  let lines = sourceCode.lines.map((text, i) => ({
@@ -135,7 +162,7 @@ module.exports = {
135
162
  * If file ends with a linebreak, `sourceCode.lines` will have one extra empty line at the end.
136
163
  * That isn't a real line, so we shouldn't count it.
137
164
  */
138
- if (lines.length > 1 && lodash.last(lines).text === "") {
165
+ if (lines.length > 1 && lines[lines.length - 1].text === "") {
139
166
  lines.pop();
140
167
  }
141
168
 
@@ -146,9 +173,7 @@ module.exports = {
146
173
  if (skipComments) {
147
174
  const comments = sourceCode.getAllComments();
148
175
 
149
- const commentLines = lodash.flatten(
150
- comments.map(comment => getLinesWithoutCode(comment))
151
- );
176
+ const commentLines = flatMap(comments, comment => getLinesWithoutCode(comment));
152
177
 
153
178
  lines = lines.filter(
154
179
  l => !commentLines.includes(l.lineNumber)
@@ -163,7 +188,7 @@ module.exports = {
163
188
  },
164
189
  end: {
165
190
  line: sourceCode.lines.length,
166
- column: lodash.last(sourceCode.lines).length
191
+ column: sourceCode.lines[sourceCode.lines.length - 1].length
167
192
  }
168
193
  };
169
194
 
@@ -9,9 +9,8 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const lodash = require("lodash");
13
-
14
12
  const astUtils = require("./utils/ast-utils");
13
+ const { upperCaseFirst } = require("../shared/string-utils");
15
14
 
16
15
  //------------------------------------------------------------------------------
17
16
  // Rule Definition
@@ -85,7 +84,7 @@ module.exports = {
85
84
  node,
86
85
  messageId: "exceed",
87
86
  data: {
88
- name: lodash.upperFirst(astUtils.getFunctionNameWithKind(node)),
87
+ name: upperCaseFirst(astUtils.getFunctionNameWithKind(node)),
89
88
  count: node.params.length,
90
89
  max: numParams
91
90
  }
@@ -9,9 +9,8 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const lodash = require("lodash");
13
-
14
12
  const astUtils = require("./utils/ast-utils");
13
+ const { upperCaseFirst } = require("../shared/string-utils");
15
14
 
16
15
  //------------------------------------------------------------------------------
17
16
  // Rule Definition
@@ -97,7 +96,7 @@ module.exports = {
97
96
  */
98
97
  function reportIfTooManyStatements(node, count, max) {
99
98
  if (count > max) {
100
- const name = lodash.upperFirst(astUtils.getFunctionNameWithKind(node));
99
+ const name = upperCaseFirst(astUtils.getFunctionNameWithKind(node));
101
100
 
102
101
  context.report({
103
102
  node,
@@ -4,12 +4,6 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- //------------------------------------------------------------------------------
8
- // Requirements
9
- //------------------------------------------------------------------------------
10
-
11
- const lodash = require("lodash");
12
-
13
7
  //------------------------------------------------------------------------------
14
8
  // Helpers
15
9
  //------------------------------------------------------------------------------
@@ -25,7 +19,7 @@ const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
25
19
  */
26
20
  function hasFallthroughComment(node, context, fallthroughCommentPattern) {
27
21
  const sourceCode = context.getSourceCode();
28
- const comment = lodash.last(sourceCode.getCommentsBefore(node));
22
+ const comment = sourceCode.getCommentsBefore(node).pop();
29
23
 
30
24
  return Boolean(comment && fallthroughCommentPattern.test(comment.value));
31
25
  }
@@ -133,7 +127,7 @@ module.exports = {
133
127
  */
134
128
  if (currentCodePath.currentSegments.some(isReachable) &&
135
129
  (node.consequent.length > 0 || hasBlankLinesBetween(node, nextToken)) &&
136
- lodash.last(node.parent.cases) !== node) {
130
+ node.parent.cases[node.parent.cases.length - 1] !== node) {
137
131
  fallthroughCase = node;
138
132
  }
139
133
  }
@@ -10,12 +10,6 @@
10
10
 
11
11
  const ignore = require("ignore");
12
12
 
13
- const arrayOfStrings = {
14
- type: "array",
15
- items: { type: "string" },
16
- uniqueItems: true
17
- };
18
-
19
13
  const arrayOfStringsOrObjects = {
20
14
  type: "array",
21
15
  items: {
@@ -44,6 +38,41 @@ const arrayOfStringsOrObjects = {
44
38
  uniqueItems: true
45
39
  };
46
40
 
41
+ const arrayOfStringsOrObjectPatterns = {
42
+ anyOf: [
43
+ {
44
+ type: "array",
45
+ items: {
46
+ type: "string"
47
+ },
48
+ uniqueItems: true
49
+ },
50
+ {
51
+ type: "array",
52
+ items: {
53
+ type: "object",
54
+ properties: {
55
+ group: {
56
+ type: "array",
57
+ items: {
58
+ type: "string"
59
+ },
60
+ minItems: 1,
61
+ uniqueItems: true
62
+ },
63
+ message: {
64
+ type: "string",
65
+ minLength: 1
66
+ }
67
+ },
68
+ additionalProperties: false,
69
+ required: ["group"]
70
+ },
71
+ uniqueItems: true
72
+ }
73
+ ]
74
+ };
75
+
47
76
  module.exports = {
48
77
  meta: {
49
78
  type: "suggestion",
@@ -61,6 +90,8 @@ module.exports = {
61
90
  pathWithCustomMessage: "'{{importSource}}' import is restricted from being used. {{customMessage}}",
62
91
 
63
92
  patterns: "'{{importSource}}' import is restricted from being used by a pattern.",
93
+ // eslint-disable-next-line eslint-plugin/report-message-format
94
+ patternWithCustomMessage: "'{{importSource}}' import is restricted from being used by a pattern. {{customMessage}}",
64
95
 
65
96
  everything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted.",
66
97
  // eslint-disable-next-line eslint-plugin/report-message-format
@@ -80,7 +111,7 @@ module.exports = {
80
111
  type: "object",
81
112
  properties: {
82
113
  paths: arrayOfStringsOrObjects,
83
- patterns: arrayOfStrings
114
+ patterns: arrayOfStringsOrObjectPatterns
84
115
  },
85
116
  additionalProperties: false
86
117
  }],
@@ -98,13 +129,6 @@ module.exports = {
98
129
  (Object.prototype.hasOwnProperty.call(options[0], "paths") || Object.prototype.hasOwnProperty.call(options[0], "patterns"));
99
130
 
100
131
  const restrictedPaths = (isPathAndPatternsObject ? options[0].paths : context.options) || [];
101
- const restrictedPatterns = (isPathAndPatternsObject ? options[0].patterns : []) || [];
102
-
103
- // if no imports are restricted we don"t need to check
104
- if (Object.keys(restrictedPaths).length === 0 && restrictedPatterns.length === 0) {
105
- return {};
106
- }
107
-
108
132
  const restrictedPathMessages = restrictedPaths.reduce((memo, importSource) => {
109
133
  if (typeof importSource === "string") {
110
134
  memo[importSource] = { message: null };
@@ -117,7 +141,16 @@ module.exports = {
117
141
  return memo;
118
142
  }, {});
119
143
 
120
- const restrictedPatternsMatcher = ignore().add(restrictedPatterns);
144
+ // Handle patterns too, either as strings or groups
145
+ const restrictedPatterns = (isPathAndPatternsObject ? options[0].patterns : []) || [];
146
+ const restrictedPatternGroups = restrictedPatterns.length > 0 && typeof restrictedPatterns[0] === "string"
147
+ ? [{ matcher: ignore().add(restrictedPatterns) }]
148
+ : restrictedPatterns.map(({ group, message }) => ({ matcher: ignore().add(group), customMessage: message }));
149
+
150
+ // if no imports are restricted we don"t need to check
151
+ if (Object.keys(restrictedPaths).length === 0 && restrictedPatternGroups.length === 0) {
152
+ return {};
153
+ }
121
154
 
122
155
  /**
123
156
  * Report a restricted path.
@@ -184,17 +217,19 @@ module.exports = {
184
217
  /**
185
218
  * Report a restricted path specifically for patterns.
186
219
  * @param {node} node representing the restricted path reference
220
+ * @param {Object} group contains a Ignore instance for paths, and the customMessage to show if it fails
187
221
  * @returns {void}
188
222
  * @private
189
223
  */
190
- function reportPathForPatterns(node) {
224
+ function reportPathForPatterns(node, group) {
191
225
  const importSource = node.source.value.trim();
192
226
 
193
227
  context.report({
194
228
  node,
195
- messageId: "patterns",
229
+ messageId: group.customMessage ? "patternWithCustomMessage" : "patterns",
196
230
  data: {
197
- importSource
231
+ importSource,
232
+ customMessage: group.customMessage
198
233
  }
199
234
  });
200
235
  }
@@ -202,11 +237,12 @@ module.exports = {
202
237
  /**
203
238
  * Check if the given importSource is restricted by a pattern.
204
239
  * @param {string} importSource path of the import
240
+ * @param {Object} group contains a Ignore instance for paths, and the customMessage to show if it fails
205
241
  * @returns {boolean} whether the variable is a restricted pattern or not
206
242
  * @private
207
243
  */
208
- function isRestrictedPattern(importSource) {
209
- return restrictedPatterns.length > 0 && restrictedPatternsMatcher.ignores(importSource);
244
+ function isRestrictedPattern(importSource, group) {
245
+ return group.matcher.ignores(importSource);
210
246
  }
211
247
 
212
248
  /**
@@ -249,10 +285,11 @@ module.exports = {
249
285
  }
250
286
 
251
287
  checkRestrictedPathAndReport(importSource, importNames, node);
252
-
253
- if (isRestrictedPattern(importSource)) {
254
- reportPathForPatterns(node);
255
- }
288
+ restrictedPatternGroups.forEach(group => {
289
+ if (isRestrictedPattern(importSource, group)) {
290
+ reportPathForPatterns(node, group);
291
+ }
292
+ });
256
293
  }
257
294
 
258
295
  return {
@@ -410,6 +410,31 @@ module.exports = {
410
410
  );
411
411
  }
412
412
 
413
+ /**
414
+ * Checks whether a given node is unused expression or not.
415
+ * @param {ASTNode} node The node itself
416
+ * @returns {boolean} The node is an unused expression.
417
+ * @private
418
+ */
419
+ function isUnusedExpression(node) {
420
+ const parent = node.parent;
421
+
422
+ if (parent.type === "ExpressionStatement") {
423
+ return true;
424
+ }
425
+
426
+ if (parent.type === "SequenceExpression") {
427
+ const isLastExpression = parent.expressions[parent.expressions.length - 1] === node;
428
+
429
+ if (!isLastExpression) {
430
+ return true;
431
+ }
432
+ return isUnusedExpression(parent);
433
+ }
434
+
435
+ return false;
436
+ }
437
+
413
438
  /**
414
439
  * Checks whether a given reference is a read to update itself or not.
415
440
  * @param {eslint-scope.Reference} ref A reference to check.
@@ -420,7 +445,6 @@ module.exports = {
420
445
  function isReadForItself(ref, rhsNode) {
421
446
  const id = ref.identifier;
422
447
  const parent = id.parent;
423
- const grandparent = parent.parent;
424
448
 
425
449
  return ref.isRead() && (
426
450
 
@@ -428,12 +452,12 @@ module.exports = {
428
452
  (// in RHS of an assignment for itself. e.g. `a = a + 1`
429
453
  ((
430
454
  parent.type === "AssignmentExpression" &&
431
- grandparent.type === "ExpressionStatement" &&
455
+ isUnusedExpression(parent) &&
432
456
  parent.left === id
433
457
  ) ||
434
458
  (
435
459
  parent.type === "UpdateExpression" &&
436
- grandparent.type === "ExpressionStatement"
460
+ isUnusedExpression(parent)
437
461
  ) || rhsNode &&
438
462
  isInside(id, rhsNode) &&
439
463
  !isInsideOfStorableFunction(id, rhsNode)))
@@ -11,7 +11,6 @@
11
11
 
12
12
  const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("eslint-utils");
13
13
  const { RegExpParser, visitRegExpAST } = require("regexpp");
14
- const lodash = require("lodash");
15
14
 
16
15
  //------------------------------------------------------------------------------
17
16
  // Helpers
@@ -137,7 +136,7 @@ module.exports = {
137
136
 
138
137
  // the opposite of the previous when the regex is matching backward in a lookbehind context.
139
138
  messageId = "backward";
140
- } else if (lodash.last(groupCut).type === "Alternative") {
139
+ } else if (groupCut[groupCut.length - 1].type === "Alternative") {
141
140
 
142
141
  // group's and bref's ancestor nodes below the lowest common ancestor are sibling alternatives => they're disjunctive.
143
142
  messageId = "disjunctive";
@@ -8,7 +8,6 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const lodash = require("lodash");
12
11
  const astUtils = require("./utils/ast-utils");
13
12
 
14
13
  //------------------------------------------------------------------------------
@@ -95,9 +94,16 @@ module.exports = {
95
94
  }
96
95
  }
97
96
 
97
+ /**
98
+ * A no-op function to act as placeholder for checking a node when the `enforceForClassMembers` option is `false`.
99
+ * @returns {void}
100
+ * @private
101
+ */
102
+ function noop() {}
103
+
98
104
  return {
99
105
  Property: check,
100
- MethodDefinition: enforceForClassMembers ? check : lodash.noop
106
+ MethodDefinition: enforceForClassMembers ? check : noop
101
107
  };
102
108
  }
103
109
  };
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { escapeRegExp } = require("lodash");
8
+ const escapeRegExp = require("escape-string-regexp");
9
9
  const astUtils = require("./utils/ast-utils");
10
10
 
11
11
  const CHAR_LIMIT = 40;
@@ -10,7 +10,6 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  const astUtils = require("./utils/ast-utils");
13
- const lodash = require("lodash");
14
13
 
15
14
  //------------------------------------------------------------------------------
16
15
  // Helpers
@@ -69,6 +68,24 @@ function normalizeOptionValue(value) {
69
68
  return { multiline, minProperties, consistent };
70
69
  }
71
70
 
71
+ /**
72
+ * Checks if a value is an object.
73
+ * @param {any} value The value to check
74
+ * @returns {boolean} `true` if the value is an object, otherwise `false`
75
+ */
76
+ function isObject(value) {
77
+ return typeof value === "object" && value !== null;
78
+ }
79
+
80
+ /**
81
+ * Checks if an option is a node-specific option
82
+ * @param {any} option The option to check
83
+ * @returns {boolean} `true` if the option is node-specific, otherwise `false`
84
+ */
85
+ function isNodeSpecificOption(option) {
86
+ return isObject(option) || typeof option === "string";
87
+ }
88
+
72
89
  /**
73
90
  * Normalizes a given option value.
74
91
  * @param {string|Object|undefined} options An option value to parse.
@@ -80,9 +97,7 @@ function normalizeOptionValue(value) {
80
97
  * }} Normalized option object.
81
98
  */
82
99
  function normalizeOptions(options) {
83
- const isNodeSpecificOption = lodash.overSome([lodash.isPlainObject, lodash.isString]);
84
-
85
- if (lodash.isPlainObject(options) && Object.values(options).some(isNodeSpecificOption)) {
100
+ if (isObject(options) && Object.values(options).some(isNodeSpecificOption)) {
86
101
  return {
87
102
  ObjectExpression: normalizeOptionValue(options.ObjectExpression),
88
103
  ObjectPattern: normalizeOptionValue(options.ObjectPattern),
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const lodash = require("lodash");
7
+ const escapeRegExp = require("escape-string-regexp");
8
8
  const astUtils = require("./utils/ast-utils");
9
9
 
10
10
  //------------------------------------------------------------------------------
@@ -17,7 +17,7 @@ const astUtils = require("./utils/ast-utils");
17
17
  * @returns {string} An escaped string.
18
18
  */
19
19
  function escape(s) {
20
- return `(?:${lodash.escapeRegExp(s)})`;
20
+ return `(?:${escapeRegExp(s)})`;
21
21
  }
22
22
 
23
23
  /**
@@ -11,7 +11,7 @@
11
11
 
12
12
  const esutils = require("esutils");
13
13
  const espree = require("espree");
14
- const lodash = require("lodash");
14
+ const escapeRegExp = require("escape-string-regexp");
15
15
  const {
16
16
  breakableTypePattern,
17
17
  createGlobalLinebreakMatcher,
@@ -1756,7 +1756,7 @@ module.exports = {
1756
1756
  * @returns {SourceLocation} The `loc` object.
1757
1757
  */
1758
1758
  getNameLocationInGlobalDirectiveComment(sourceCode, comment, name) {
1759
- const namePattern = new RegExp(`[\\s,]${lodash.escapeRegExp(name)}(?:$|[\\s,:])`, "gu");
1759
+ const namePattern = new RegExp(`[\\s,]${escapeRegExp(name)}(?:$|[\\s,:])`, "gu");
1760
1760
 
1761
1761
  // To ignore the first text "global".
1762
1762
  namePattern.lastIndex = comment.value.indexOf("global") + 6;
@@ -9,7 +9,6 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const path = require("path");
12
- const lodash = require("lodash");
13
12
 
14
13
  //------------------------------------------------------------------------------
15
14
  // Private
@@ -28,6 +27,8 @@ const deprecationWarningMessages = {
28
27
  "projects in order to avoid loading '~/.eslintrc.*' accidentally."
29
28
  };
30
29
 
30
+ const sourceFileErrorCache = new Set();
31
+
31
32
  /**
32
33
  * Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
33
34
  * for each unique file path, but repeated invocations with the same file path have no effect.
@@ -36,7 +37,15 @@ const deprecationWarningMessages = {
36
37
  * @param {string} errorCode The warning message to show.
37
38
  * @returns {void}
38
39
  */
39
- const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
40
+ function emitDeprecationWarning(source, errorCode) {
41
+ const cacheKey = JSON.stringify({ source, errorCode });
42
+
43
+ if (sourceFileErrorCache.has(cacheKey)) {
44
+ return;
45
+ }
46
+
47
+ sourceFileErrorCache.add(cacheKey);
48
+
40
49
  const rel = path.relative(process.cwd(), source);
41
50
  const message = deprecationWarningMessages[errorCode];
42
51
 
@@ -45,7 +54,7 @@ const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
45
54
  "DeprecationWarning",
46
55
  errorCode
47
56
  );
48
- }, (...args) => JSON.stringify(args));
57
+ }
49
58
 
50
59
  //------------------------------------------------------------------------------
51
60
  // Public Interface
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Utilities to operate on strings.
3
+ * @author Stephen Wade
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * Converts the first letter of a string to uppercase.
10
+ * @param {string} string The string to operate on
11
+ * @returns {string} The converted string
12
+ */
13
+ function upperCaseFirst(string) {
14
+ if (string.length <= 1) {
15
+ return string.toUpperCase();
16
+ }
17
+ return string[0].toUpperCase() + string.slice(1);
18
+ }
19
+
20
+ module.exports = {
21
+ upperCaseFirst
22
+ };