eslint 8.50.0 → 8.51.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.
@@ -139,7 +139,7 @@ module.exports = class ConfigCommentParser {
139
139
  const items = {};
140
140
 
141
141
  string.split(",").forEach(name => {
142
- const trimmedName = name.trim();
142
+ const trimmedName = name.trim().replace(/^(?<quote>['"]?)(?<ruleId>.*)\k<quote>$/us, "$<ruleId>");
143
143
 
144
144
  if (trimmedName) {
145
145
  items[trimmedName] = true;
package/lib/options.js CHANGED
@@ -55,6 +55,7 @@ const optionator = require("optionator");
55
55
  * @property {string} [stdinFilename] Specify filename to process STDIN as
56
56
  * @property {boolean} quiet Report errors only
57
57
  * @property {boolean} [version] Output the version number
58
+ * @property {boolean} warnIgnored Show warnings when the file list includes ignored files
58
59
  * @property {string[]} _ Positional filenames or patterns
59
60
  */
60
61
 
@@ -139,6 +140,17 @@ module.exports = function(usingFlatConfig) {
139
140
  };
140
141
  }
141
142
 
143
+ let warnIgnoredFlag;
144
+
145
+ if (usingFlatConfig) {
146
+ warnIgnoredFlag = {
147
+ option: "warn-ignored",
148
+ type: "Boolean",
149
+ default: "true",
150
+ description: "Suppress warnings when the file list includes ignored files"
151
+ };
152
+ }
153
+
142
154
  return optionator({
143
155
  prepend: "eslint [options] file.js [file.js] [dir]",
144
156
  defaults: {
@@ -349,6 +361,7 @@ module.exports = function(usingFlatConfig) {
349
361
  default: "false",
350
362
  description: "Exit with exit code 2 in case of fatal error"
351
363
  },
364
+ warnIgnoredFlag,
352
365
  {
353
366
  option: "debug",
354
367
  type: "Boolean",
@@ -150,6 +150,31 @@ function isInsideWithBlock(node) {
150
150
  return node.parent.type === "WithStatement" && node.parent.body === node ? true : isInsideWithBlock(node.parent);
151
151
  }
152
152
 
153
+ /**
154
+ * Gets the leftmost operand of a consecutive logical expression.
155
+ * @param {SourceCode} sourceCode The ESLint source code object
156
+ * @param {LogicalExpression} node LogicalExpression
157
+ * @returns {Expression} Leftmost operand
158
+ */
159
+ function getLeftmostOperand(sourceCode, node) {
160
+ let left = node.left;
161
+
162
+ while (left.type === "LogicalExpression" && left.operator === node.operator) {
163
+
164
+ if (astUtils.isParenthesised(sourceCode, left)) {
165
+
166
+ /*
167
+ * It should have associativity,
168
+ * but ignore it if use parentheses to make the evaluation order clear.
169
+ */
170
+ return left;
171
+ }
172
+ left = left.left;
173
+ }
174
+ return left;
175
+
176
+ }
177
+
153
178
  //------------------------------------------------------------------------------
154
179
  // Rule Definition
155
180
  //------------------------------------------------------------------------------
@@ -318,7 +343,10 @@ module.exports = {
318
343
 
319
344
  // foo = foo || bar
320
345
  "AssignmentExpression[operator='='][right.type='LogicalExpression']"(assignment) {
321
- if (!astUtils.isSameReference(assignment.left, assignment.right.left)) {
346
+ const leftOperand = getLeftmostOperand(sourceCode, assignment.right);
347
+
348
+ if (!astUtils.isSameReference(assignment.left, leftOperand)
349
+ ) {
322
350
  return;
323
351
  }
324
352
 
@@ -342,10 +370,10 @@ module.exports = {
342
370
  yield ruleFixer.insertTextBefore(assignmentOperatorToken, assignment.right.operator);
343
371
 
344
372
  // -> foo ||= bar
345
- const logicalOperatorToken = getOperatorToken(assignment.right);
373
+ const logicalOperatorToken = getOperatorToken(leftOperand.parent);
346
374
  const firstRightOperandToken = sourceCode.getTokenAfter(logicalOperatorToken);
347
375
 
348
- yield ruleFixer.removeRange([assignment.right.range[0], firstRightOperandToken.range[0]]);
376
+ yield ruleFixer.removeRange([leftOperand.parent.range[0], firstRightOperandToken.range[0]]);
349
377
  }
350
378
  };
351
379
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.50.0",
3
+ "version": "8.51.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -63,7 +63,7 @@
63
63
  "@eslint-community/eslint-utils": "^4.2.0",
64
64
  "@eslint-community/regexpp": "^4.6.1",
65
65
  "@eslint/eslintrc": "^2.1.2",
66
- "@eslint/js": "8.50.0",
66
+ "@eslint/js": "8.51.0",
67
67
  "@humanwhocodes/config-array": "^0.11.11",
68
68
  "@humanwhocodes/module-importer": "^1.0.1",
69
69
  "@nodelib/fs.walk": "^1.2.8",