eslint 5.5.0 → 5.6.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ v5.6.0 - September 14, 2018
2
+
3
+ * c5b688e Update: Added generators option to func-names (fixes #9511) (#10697) (Oscar Barrett)
4
+ * 7da36d5 Fix: respect generator function expressions in no-constant-condition (#10827) (Julian Rosse)
5
+ * 0a65844 Chore: quote enable avoidEscape option in eslint-config-eslint (#10626) (薛定谔的猫)
6
+ * 32f41bd Chore: Add configuration wrapper markdown for the bug report template (#10669) (Iulian Onofrei)
7
+
1
8
  v5.5.0 - August 31, 2018
2
9
 
3
10
  * 6e110e6 Fix: camelcase duplicate warning bug (fixes #10801) (#10802) (Julian Rosse)
@@ -33,11 +33,31 @@ module.exports = {
33
33
  url: "https://eslint.org/docs/rules/func-names"
34
34
  },
35
35
 
36
- schema: [
37
- {
38
- enum: ["always", "as-needed", "never"]
39
- }
40
- ],
36
+ schema: {
37
+ definitions: {
38
+ value: {
39
+ enum: [
40
+ "always",
41
+ "as-needed",
42
+ "never"
43
+ ]
44
+ }
45
+ },
46
+ items: [
47
+ {
48
+ $ref: "#/definitions/value"
49
+ },
50
+ {
51
+ type: "object",
52
+ properties: {
53
+ generators: {
54
+ $ref: "#/definitions/value"
55
+ }
56
+ },
57
+ additionalProperties: false
58
+ }
59
+ ]
60
+ },
41
61
  messages: {
42
62
  unnamed: "Unexpected unnamed {{name}}.",
43
63
  named: "Unexpected named {{name}}."
@@ -45,8 +65,23 @@ module.exports = {
45
65
  },
46
66
 
47
67
  create(context) {
48
- const never = context.options[0] === "never";
49
- const asNeeded = context.options[0] === "as-needed";
68
+
69
+ /**
70
+ * Returns the config option for the given node.
71
+ * @param {ASTNode} node - A node to get the config for.
72
+ * @returns {string} The config option.
73
+ */
74
+ function getConfigForNode(node) {
75
+ if (
76
+ node.generator &&
77
+ context.options.length > 1 &&
78
+ context.options[1].generators
79
+ ) {
80
+ return context.options[1].generators;
81
+ }
82
+
83
+ return context.options[0] || "always";
84
+ }
50
85
 
51
86
  /**
52
87
  * Determines whether the current FunctionExpression node is a get, set, or
@@ -83,6 +118,32 @@ module.exports = {
83
118
  (parent.type === "AssignmentPattern" && parent.right === node);
84
119
  }
85
120
 
121
+ /**
122
+ * Reports that an unnamed function should be named
123
+ * @param {ASTNode} node - The node to report in the event of an error.
124
+ * @returns {void}
125
+ */
126
+ function reportUnexpectedUnnamedFunction(node) {
127
+ context.report({
128
+ node,
129
+ messageId: "unnamed",
130
+ data: { name: astUtils.getFunctionNameWithKind(node) }
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Reports that a named function should be unnamed
136
+ * @param {ASTNode} node - The node to report in the event of an error.
137
+ * @returns {void}
138
+ */
139
+ function reportUnexpectedNamedFunction(node) {
140
+ context.report({
141
+ node,
142
+ messageId: "named",
143
+ data: { name: astUtils.getFunctionNameWithKind(node) }
144
+ });
145
+ }
146
+
86
147
  return {
87
148
  "FunctionExpression:exit"(node) {
88
149
 
@@ -94,23 +155,19 @@ module.exports = {
94
155
  }
95
156
 
96
157
  const hasName = Boolean(node.id && node.id.name);
97
- const name = astUtils.getFunctionNameWithKind(node);
158
+ const config = getConfigForNode(node);
98
159
 
99
- if (never) {
160
+ if (config === "never") {
100
161
  if (hasName) {
101
- context.report({
102
- node,
103
- messageId: "named",
104
- data: { name }
105
- });
162
+ reportUnexpectedNamedFunction(node);
163
+ }
164
+ } else if (config === "as-needed") {
165
+ if (!hasName && !hasInferredName(node)) {
166
+ reportUnexpectedUnnamedFunction(node);
106
167
  }
107
168
  } else {
108
- if (!hasName && (asNeeded ? !hasInferredName(node) : !isObjectOrClassMethod(node))) {
109
- context.report({
110
- node,
111
- messageId: "unnamed",
112
- data: { name }
113
- });
169
+ if (!hasName && !isObjectOrClassMethod(node)) {
170
+ reportUnexpectedUnnamedFunction(node);
114
171
  }
115
172
  }
116
173
  }
@@ -207,6 +207,8 @@ module.exports = {
207
207
  "ForStatement:exit": checkConstantConditionLoopInSet,
208
208
  FunctionDeclaration: enterFunction,
209
209
  "FunctionDeclaration:exit": exitFunction,
210
+ FunctionExpression: enterFunction,
211
+ "FunctionExpression:exit": exitFunction,
210
212
  YieldExpression: () => loopsInCurrentScope.clear()
211
213
  };
212
214
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {