eslint 7.4.0 → 7.5.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 (59) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +3 -1
  3. package/lib/linter/code-path-analysis/code-path-analyzer.js +38 -0
  4. package/lib/linter/code-path-analysis/code-path-segment.js +0 -1
  5. package/lib/linter/code-path-analysis/code-path-state.js +59 -0
  6. package/lib/linter/code-path-analysis/debug-helpers.js +26 -19
  7. package/lib/rules/accessor-pairs.js +1 -14
  8. package/lib/rules/array-callback-return.js +5 -7
  9. package/lib/rules/arrow-body-style.js +41 -6
  10. package/lib/rules/consistent-return.js +1 -12
  11. package/lib/rules/constructor-super.js +1 -0
  12. package/lib/rules/dot-location.js +20 -14
  13. package/lib/rules/dot-notation.js +36 -33
  14. package/lib/rules/func-call-spacing.js +42 -6
  15. package/lib/rules/func-name-matching.js +1 -4
  16. package/lib/rules/global-require.js +2 -1
  17. package/lib/rules/id-blacklist.js +233 -0
  18. package/lib/rules/indent.js +19 -0
  19. package/lib/rules/index.js +1 -3
  20. package/lib/rules/keyword-spacing.js +2 -2
  21. package/lib/rules/max-len.js +13 -2
  22. package/lib/rules/new-cap.js +10 -14
  23. package/lib/rules/newline-per-chained-call.js +15 -5
  24. package/lib/rules/no-alert.js +10 -3
  25. package/lib/rules/no-eval.js +8 -38
  26. package/lib/rules/no-extend-native.js +37 -40
  27. package/lib/rules/no-extra-bind.js +57 -17
  28. package/lib/rules/no-extra-boolean-cast.js +7 -0
  29. package/lib/rules/no-extra-parens.js +27 -7
  30. package/lib/rules/no-implicit-coercion.js +11 -6
  31. package/lib/rules/no-implied-eval.js +7 -28
  32. package/lib/rules/no-import-assign.js +33 -32
  33. package/lib/rules/no-irregular-whitespace.js +22 -12
  34. package/lib/rules/no-magic-numbers.js +4 -8
  35. package/lib/rules/no-obj-calls.js +7 -4
  36. package/lib/rules/no-prototype-builtins.js +13 -3
  37. package/lib/rules/no-self-assign.js +3 -53
  38. package/lib/rules/no-setter-return.js +5 -8
  39. package/lib/rules/no-unexpected-multiline.js +2 -2
  40. package/lib/rules/no-unneeded-ternary.js +0 -2
  41. package/lib/rules/no-unused-expressions.js +55 -23
  42. package/lib/rules/no-useless-call.js +10 -7
  43. package/lib/rules/no-whitespace-before-property.js +16 -4
  44. package/lib/rules/object-curly-newline.js +4 -4
  45. package/lib/rules/operator-assignment.js +3 -42
  46. package/lib/rules/padding-line-between-statements.js +2 -2
  47. package/lib/rules/prefer-arrow-callback.js +90 -25
  48. package/lib/rules/prefer-exponentiation-operator.js +1 -1
  49. package/lib/rules/prefer-numeric-literals.js +4 -13
  50. package/lib/rules/prefer-promise-reject-errors.js +1 -3
  51. package/lib/rules/prefer-regex-literals.js +2 -5
  52. package/lib/rules/prefer-spread.js +2 -6
  53. package/lib/rules/radix.js +5 -2
  54. package/lib/rules/sort-imports.js +28 -0
  55. package/lib/rules/use-isnan.js +1 -1
  56. package/lib/rules/utils/ast-utils.js +317 -153
  57. package/lib/rules/wrap-iife.js +9 -2
  58. package/lib/rules/yoda.js +2 -55
  59. package/package.json +6 -6
@@ -102,11 +102,8 @@ module.exports = {
102
102
  */
103
103
  function isStringRawTaggedStaticTemplateLiteral(node) {
104
104
  return node.type === "TaggedTemplateExpression" &&
105
- node.tag.type === "MemberExpression" &&
106
- node.tag.object.type === "Identifier" &&
107
- node.tag.object.name === "String" &&
108
- isGlobalReference(node.tag.object) &&
109
- astUtils.getStaticPropertyName(node.tag) === "raw" &&
105
+ astUtils.isSpecificMemberAccess(node.tag, "String", "raw") &&
106
+ isGlobalReference(astUtils.skipChainExpression(node.tag).object) &&
110
107
  isStaticTemplateLiteral(node.quasi);
111
108
  }
112
109
 
@@ -18,17 +18,13 @@ const astUtils = require("./utils/ast-utils");
18
18
  */
19
19
  function isVariadicApplyCalling(node) {
20
20
  return (
21
- node.callee.type === "MemberExpression" &&
22
- node.callee.property.type === "Identifier" &&
23
- node.callee.property.name === "apply" &&
24
- node.callee.computed === false &&
21
+ astUtils.isSpecificMemberAccess(node.callee, null, "apply") &&
25
22
  node.arguments.length === 2 &&
26
23
  node.arguments[1].type !== "ArrayExpression" &&
27
24
  node.arguments[1].type !== "SpreadElement"
28
25
  );
29
26
  }
30
27
 
31
-
32
28
  /**
33
29
  * Checks whether or not `thisArg` is not changed by `.apply()`.
34
30
  * @param {ASTNode|null} expectedThis The node that is the owner of the applied function.
@@ -75,7 +71,7 @@ module.exports = {
75
71
  return;
76
72
  }
77
73
 
78
- const applied = node.callee.object;
74
+ const applied = astUtils.skipChainExpression(astUtils.skipChainExpression(node.callee).object);
79
75
  const expectedThis = (applied.type === "MemberExpression") ? applied.object : null;
80
76
  const thisArg = node.arguments[0];
81
77
 
@@ -166,9 +166,12 @@ module.exports = {
166
166
  if (variable && !isShadowed(variable)) {
167
167
  variable.references.forEach(reference => {
168
168
  const node = reference.identifier.parent;
169
+ const maybeCallee = node.parent.type === "ChainExpression"
170
+ ? node.parent
171
+ : node;
169
172
 
170
- if (isParseIntMethod(node) && astUtils.isCallee(node)) {
171
- checkArguments(node.parent);
173
+ if (isParseIntMethod(node) && astUtils.isCallee(maybeCallee)) {
174
+ checkArguments(maybeCallee.parent);
172
175
  }
173
176
  });
174
177
  }
@@ -44,6 +44,10 @@ module.exports = {
44
44
  ignoreMemberSort: {
45
45
  type: "boolean",
46
46
  default: false
47
+ },
48
+ allowSeparatedGroups: {
49
+ type: "boolean",
50
+ default: false
47
51
  }
48
52
  },
49
53
  additionalProperties: false
@@ -66,6 +70,7 @@ module.exports = {
66
70
  ignoreDeclarationSort = configuration.ignoreDeclarationSort || false,
67
71
  ignoreMemberSort = configuration.ignoreMemberSort || false,
68
72
  memberSyntaxSortOrder = configuration.memberSyntaxSortOrder || ["none", "all", "multiple", "single"],
73
+ allowSeparatedGroups = configuration.allowSeparatedGroups || false,
69
74
  sourceCode = context.getSourceCode();
70
75
  let previousDeclaration = null;
71
76
 
@@ -115,9 +120,32 @@ module.exports = {
115
120
 
116
121
  }
117
122
 
123
+ /**
124
+ * Calculates number of lines between two nodes. It is assumed that the given `left` node appears before
125
+ * the given `right` node in the source code. Lines are counted from the end of the `left` node till the
126
+ * start of the `right` node. If the given nodes are on the same line, it returns `0`, same as if they were
127
+ * on two consecutive lines.
128
+ * @param {ASTNode} left node that appears before the given `right` node.
129
+ * @param {ASTNode} right node that appears after the given `left` node.
130
+ * @returns {number} number of lines between nodes.
131
+ */
132
+ function getNumberOfLinesBetween(left, right) {
133
+ return Math.max(right.loc.start.line - left.loc.end.line - 1, 0);
134
+ }
135
+
118
136
  return {
119
137
  ImportDeclaration(node) {
120
138
  if (!ignoreDeclarationSort) {
139
+ if (
140
+ previousDeclaration &&
141
+ allowSeparatedGroups &&
142
+ getNumberOfLinesBetween(previousDeclaration, node) > 0
143
+ ) {
144
+
145
+ // reset declaration sort
146
+ previousDeclaration = null;
147
+ }
148
+
121
149
  if (previousDeclaration) {
122
150
  const currentMemberSyntaxGroupIndex = getMemberParameterGroupIndex(node),
123
151
  previousMemberSyntaxGroupIndex = getMemberParameterGroupIndex(previousDeclaration);
@@ -106,7 +106,7 @@ module.exports = {
106
106
  * @returns {void}
107
107
  */
108
108
  function checkCallExpression(node) {
109
- const callee = node.callee;
109
+ const callee = astUtils.skipChainExpression(node.callee);
110
110
 
111
111
  if (callee.type === "MemberExpression") {
112
112
  const methodName = astUtils.getStaticPropertyName(callee);