eslint 5.7.0 → 5.8.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,18 @@
1
+ v5.8.0 - October 26, 2018
2
+
3
+ * 9152417 Fix: deprecation warning in RuleTester using Node v11 (#11009) (Teddy Katz)
4
+ * e349a03 Docs: Update issue templates to ask for PRs (#11012) (Nicholas C. Zakas)
5
+ * 3d88b38 Chore: avoid using legacy report API in no-irregular-whitespace (#11013) (Teddy Katz)
6
+ * 5a31a92 Build: compile espree's deps to ES5 when generating site (fixes #11014) (#11015) (Teddy Katz)
7
+ * 3943635 Update: Create Linter.version API (fixes #9271) (#11010) (Nicholas C. Zakas)
8
+ * a940cf4 Docs: Mention version for config glob patterns (fixes #8793) (Nicholas C. Zakas)
9
+ * 6e1c530 Build: run tests on Node 11 (#11008) (Teddy Katz)
10
+ * 58ff359 Docs: add instructions for npm 2FA (refs #10631) (#10992) (Teddy Katz)
11
+ * 2f87bb3 Upgrade: eslint-release@1.0.0 (refs #10631) (#10991) (Teddy Katz)
12
+ * 57ef0fd Fix: prefer-const when using destructuring assign (fixes #8308) (#10924) (Nicholas C. Zakas)
13
+ * 577cbf1 Chore: Add typescript-specific edge case tests to space-infix-ops (#10986) (Bence Dányi)
14
+ * d45b184 Chore: Using deconstruction assignment for shelljs (#10974) (ZYSzys)
15
+
1
16
  v5.7.0 - October 12, 2018
2
17
 
3
18
  * 6cb63fd Update: Add iife to padding-line-between-statements (fixes #10853) (#10916) (Kevin Partington)
package/lib/linter.js CHANGED
@@ -888,6 +888,15 @@ module.exports = class Linter {
888
888
  this.environments = new Environments();
889
889
  }
890
890
 
891
+ /**
892
+ * Getter for package version.
893
+ * @static
894
+ * @returns {string} The version from package.json.
895
+ */
896
+ static get version() {
897
+ return pkg.version;
898
+ }
899
+
891
900
  /**
892
901
  * Configuration object for the `verify` API. A JS representation of the eslintrc files.
893
902
  * @typedef {Object} ESLintConfig
@@ -81,9 +81,7 @@ module.exports = {
81
81
  const locStart = node.loc.start;
82
82
  const locEnd = node.loc.end;
83
83
 
84
- errors = errors.filter(error => {
85
- const errorLoc = error[1];
86
-
84
+ errors = errors.filter(({ loc: errorLoc }) => {
87
85
  if (errorLoc.line >= locStart.line && errorLoc.line <= locEnd.line) {
88
86
  if (errorLoc.column >= locStart.column && (errorLoc.column <= locEnd.column || errorLoc.line < locEnd.line)) {
89
87
  return false;
@@ -157,7 +155,7 @@ module.exports = {
157
155
  column: match.index
158
156
  };
159
157
 
160
- errors.push([node, location, "Irregular whitespace not allowed."]);
158
+ errors.push({ node, message: "Irregular whitespace not allowed.", loc: location });
161
159
  }
162
160
  });
163
161
  }
@@ -182,7 +180,7 @@ module.exports = {
182
180
  column: sourceLines[lineIndex].length
183
181
  };
184
182
 
185
- errors.push([node, location, "Irregular whitespace not allowed."]);
183
+ errors.push({ node, message: "Irregular whitespace not allowed.", loc: location });
186
184
  lastLineIndex = lineIndex;
187
185
  }
188
186
  }
@@ -224,9 +222,7 @@ module.exports = {
224
222
  }
225
223
 
226
224
  // If we have any errors remaining report on them
227
- errors.forEach(error => {
228
- context.report(...error);
229
- });
225
+ errors.forEach(error => context.report(error));
230
226
  };
231
227
  } else {
232
228
  nodes.Program = noop;
@@ -57,6 +57,7 @@ function canBecomeVariableDeclaration(identifier) {
57
57
  * @returns {boolean} Indicates if the variable is from outer scope or function parameters.
58
58
  */
59
59
  function isOuterVariableInDestructing(name, initScope) {
60
+
60
61
  if (initScope.through.find(ref => ref.resolved && ref.resolved.name === name)) {
61
62
  return true;
62
63
  }
@@ -96,6 +97,54 @@ function getDestructuringHost(reference) {
96
97
  return node;
97
98
  }
98
99
 
100
+ /**
101
+ * Determines if a destructuring assignment node contains
102
+ * any MemberExpression nodes. This is used to determine if a
103
+ * variable that is only written once using destructuring can be
104
+ * safely converted into a const declaration.
105
+ * @param {ASTNode} node The ObjectPattern or ArrayPattern node to check.
106
+ * @returns {boolean} True if the destructuring pattern contains
107
+ * a MemberExpression, false if not.
108
+ */
109
+ function hasMemberExpressionAssignment(node) {
110
+ switch (node.type) {
111
+ case "ObjectPattern":
112
+ return node.properties.some(prop => {
113
+ if (prop) {
114
+
115
+ /*
116
+ * Spread elements have an argument property while
117
+ * others have a value property. Because different
118
+ * parsers use different node types for spread elements,
119
+ * we just check if there is an argument property.
120
+ */
121
+ return hasMemberExpressionAssignment(prop.argument || prop.value);
122
+ }
123
+
124
+ return false;
125
+ });
126
+
127
+ case "ArrayPattern":
128
+ return node.elements.some(element => {
129
+ if (element) {
130
+ return hasMemberExpressionAssignment(element);
131
+ }
132
+
133
+ return false;
134
+ });
135
+
136
+ case "AssignmentPattern":
137
+ return hasMemberExpressionAssignment(node.left);
138
+
139
+ case "MemberExpression":
140
+ return true;
141
+
142
+ // no default
143
+ }
144
+
145
+ return false;
146
+ }
147
+
99
148
  /**
100
149
  * Gets an identifier node of a given variable.
101
150
  *
@@ -148,7 +197,8 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
148
197
 
149
198
  if (destructuringHost !== null && destructuringHost.left !== void 0) {
150
199
  const leftNode = destructuringHost.left;
151
- let hasOuterVariables = false;
200
+ let hasOuterVariables = false,
201
+ hasNonIdentifiers = false;
152
202
 
153
203
  if (leftNode.type === "ObjectPattern") {
154
204
  const properties = leftNode.properties;
@@ -157,16 +207,23 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
157
207
  .filter(prop => prop.value)
158
208
  .map(prop => prop.value.name)
159
209
  .some(name => isOuterVariableInDestructing(name, variable.scope));
210
+
211
+ hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
212
+
160
213
  } else if (leftNode.type === "ArrayPattern") {
161
214
  const elements = leftNode.elements;
162
215
 
163
216
  hasOuterVariables = elements
164
217
  .map(element => element && element.name)
165
218
  .some(name => isOuterVariableInDestructing(name, variable.scope));
219
+
220
+ hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
166
221
  }
167
- if (hasOuterVariables) {
222
+
223
+ if (hasOuterVariables || hasNonIdentifiers) {
168
224
  return null;
169
225
  }
226
+
170
227
  }
171
228
 
172
229
  writer = reference;
@@ -192,9 +249,11 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
192
249
  if (!shouldBeConst) {
193
250
  return null;
194
251
  }
252
+
195
253
  if (isReadBeforeInit) {
196
254
  return variable.defs[0].name;
197
255
  }
256
+
198
257
  return writer.identifier;
199
258
  }
200
259
 
@@ -295,7 +354,7 @@ module.exports = {
295
354
  create(context) {
296
355
  const options = context.options[0] || {};
297
356
  const sourceCode = context.getSourceCode();
298
- const checkingMixedDestructuring = options.destructuring !== "all";
357
+ const shouldMatchAnyDestructuredVariable = options.destructuring !== "all";
299
358
  const ignoreReadBeforeAssign = options.ignoreReadBeforeAssign === true;
300
359
  const variables = [];
301
360
 
@@ -316,7 +375,7 @@ module.exports = {
316
375
  function checkGroup(nodes) {
317
376
  const nodesToReport = nodes.filter(Boolean);
318
377
 
319
- if (nodes.length && (checkingMixedDestructuring || nodesToReport.length === nodes.length)) {
378
+ if (nodes.length && (shouldMatchAnyDestructuredVariable || nodesToReport.length === nodes.length)) {
320
379
  const varDeclParent = findUp(nodes[0], "VariableDeclaration", parentNode => parentNode.type.endsWith("Statement"));
321
380
  const shouldFix = varDeclParent &&
322
381
 
@@ -397,7 +397,7 @@ class RuleTester {
397
397
  */
398
398
  function assertASTDidntChange(beforeAST, afterAST) {
399
399
  if (!lodash.isEqual(beforeAST, afterAST)) {
400
- assert.fail(null, null, "Rule should not modify AST.");
400
+ assert.fail("Rule should not modify AST.");
401
401
  }
402
402
  }
403
403
 
@@ -551,7 +551,7 @@ class RuleTester {
551
551
  } else {
552
552
 
553
553
  // Message was an unexpected type
554
- assert.fail(message, null, "Error should be a string, object, or RegExp.");
554
+ assert.fail(`Error should be a string, object, or RegExp, but found (${util.inspect(message)})`);
555
555
  }
556
556
  }
557
557
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -11,11 +11,11 @@
11
11
  "test": "node Makefile.js test",
12
12
  "lint": "node Makefile.js lint",
13
13
  "fuzz": "node Makefile.js fuzz",
14
- "release": "node Makefile.js release",
15
- "ci-release": "node Makefile.js ciRelease",
16
- "alpharelease": "node Makefile.js prerelease -- alpha",
17
- "betarelease": "node Makefile.js prerelease -- beta",
18
- "rcrelease": "node Makefile.js prerelease -- rc",
14
+ "generate-release": "node Makefile.js generateRelease",
15
+ "generate-alpharelease": "node Makefile.js generatePrerelease -- alpha",
16
+ "generate-betarelease": "node Makefile.js generatePrerelease -- beta",
17
+ "generate-rcrelease": "node Makefile.js generatePrerelease -- rc",
18
+ "publish-release": "node Makefile.js publishRelease",
19
19
  "docs": "node Makefile.js docs",
20
20
  "gensite": "node Makefile.js gensite",
21
21
  "browserify": "node Makefile.js browserify",
@@ -90,7 +90,7 @@
90
90
  "eslint-plugin-eslint-plugin": "^1.2.0",
91
91
  "eslint-plugin-node": "^7.0.1",
92
92
  "eslint-plugin-rulesdir": "^0.1.0",
93
- "eslint-release": "^0.11.1",
93
+ "eslint-release": "^1.0.0",
94
94
  "eslint-rule-composer": "^0.3.0",
95
95
  "eslump": "^1.6.2",
96
96
  "esprima": "^4.0.1",