eslint 8.12.0 → 8.13.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.
@@ -56,6 +56,7 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]);
56
56
  /** @typedef {import("../shared/types").Plugin} Plugin */
57
57
  /** @typedef {import("../shared/types").RuleConf} RuleConf */
58
58
  /** @typedef {import("../shared/types").Rule} Rule */
59
+ /** @typedef {import("../shared/types").FormatterFunction} FormatterFunction */
59
60
  /** @typedef {ReturnType<CascadingConfigArrayFactory.getConfigArrayForFile>} ConfigArray */
60
61
  /** @typedef {ReturnType<ConfigArray.extractConfig>} ExtractedConfig */
61
62
 
@@ -1002,7 +1003,7 @@ class CLIEngine {
1002
1003
  * @param {string} [format] The name of the format to load or the path to a
1003
1004
  * custom formatter.
1004
1005
  * @throws {any} As may be thrown by requiring of formatter
1005
- * @returns {(Function|null)} The formatter function or null if the `format` is not a string.
1006
+ * @returns {(FormatterFunction|null)} The formatter function or null if the `format` is not a string.
1006
1007
  */
1007
1008
  getFormatter(format) {
1008
1009
 
@@ -151,7 +151,7 @@ function pageTemplate(it) {
151
151
  </script>
152
152
  </body>
153
153
  </html>
154
- `.trimLeft();
154
+ `.trimStart();
155
155
  }
156
156
 
157
157
  /**
@@ -222,7 +222,7 @@ function messageTemplate(it) {
222
222
  <a href="${ruleUrl ? ruleUrl : ""}" target="_blank" rel="noopener noreferrer">${ruleId ? ruleId : ""}</a>
223
223
  </td>
224
224
  </tr>
225
- `.trimLeft();
225
+ `.trimStart();
226
226
  }
227
227
 
228
228
  /**
@@ -280,7 +280,7 @@ function resultTemplate(it) {
280
280
  <span>${encodeHTML(summary)}</span>
281
281
  </th>
282
282
  </tr>
283
- `.trimLeft();
283
+ `.trimStart();
284
284
  }
285
285
 
286
286
  /**
@@ -35,10 +35,11 @@ const { version } = require("../../package.json");
35
35
  /** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
36
36
  /** @typedef {import("../shared/types").Plugin} Plugin */
37
37
  /** @typedef {import("../shared/types").Rule} Rule */
38
+ /** @typedef {import("../shared/types").LintResult} LintResult */
38
39
 
39
40
  /**
40
41
  * The main formatter object.
41
- * @typedef Formatter
42
+ * @typedef LoadedFormatter
42
43
  * @property {function(LintResult[]): string | Promise<string>} format format function.
43
44
  */
44
45
 
@@ -74,22 +75,6 @@ const { version } = require("../../package.json");
74
75
  * @property {Object} definition The plugin definition.
75
76
  */
76
77
 
77
- /**
78
- * A linting result.
79
- * @typedef {Object} LintResult
80
- * @property {string} filePath The path to the file that was linted.
81
- * @property {LintMessage[]} messages All of the messages for the result.
82
- * @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result.
83
- * @property {number} errorCount Number of errors for the result.
84
- * @property {number} fatalErrorCount Number of fatal errors for the result.
85
- * @property {number} warningCount Number of warnings for the result.
86
- * @property {number} fixableErrorCount Number of fixable errors for the result.
87
- * @property {number} fixableWarningCount Number of fixable warnings for the result.
88
- * @property {string} [source] The source code of the file that was linted.
89
- * @property {string} [output] The source code of the file that was linted, with as many fixes applied as possible.
90
- * @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules.
91
- */
92
-
93
78
  /**
94
79
  * Private members for the `ESLint` instance.
95
80
  * @typedef {Object} ESLintPrivateMembers
@@ -619,7 +604,7 @@ class ESLint {
619
604
  * - `@foo` → `@foo/eslint-formatter`
620
605
  * - `@foo/bar` → `@foo/eslint-formatter-bar`
621
606
  * - A file path ... Load the file.
622
- * @returns {Promise<Formatter>} A promise resolving to the formatter object.
607
+ * @returns {Promise<LoadedFormatter>} A promise resolving to the formatter object.
623
608
  * This promise will be rejected if the given formatter was not found or not
624
609
  * a function.
625
610
  */
@@ -639,7 +624,7 @@ class ESLint {
639
624
 
640
625
  /**
641
626
  * The main formatter method.
642
- * @param {LintResults[]} results The lint results to format.
627
+ * @param {LintResult[]} results The lint results to format.
643
628
  * @returns {string | Promise<string>} The formatted lint results.
644
629
  */
645
630
  format(results) {
@@ -66,7 +66,7 @@ function createIndividualDirectivesRemoval(directives, commentToken) {
66
66
  const listText = commentToken.value
67
67
  .slice(listStartOffset) // remove directive name and all whitespace before the list
68
68
  .split(/\s-{2,}\s/u)[0] // remove `-- comment`, if it exists
69
- .trimRight(); // remove all whitespace after the list
69
+ .trimEnd(); // remove all whitespace after the list
70
70
 
71
71
  /*
72
72
  * We can assume that `listText` contains multiple elements.
@@ -72,15 +72,18 @@ module.exports = {
72
72
  let funcInfo = null;
73
73
 
74
74
  /**
75
- * Pushs a variable scope (Program or Function) information to the stack.
75
+ * Pushs a `this` scope (non-arrow function, class static block, or class field initializer) information to the stack.
76
+ * Top-level scopes are handled separately.
76
77
  *
77
78
  * This is used in order to check whether or not `this` binding is a
78
79
  * reference to the global object.
79
- * @param {ASTNode} node A node of the scope. This is one of Program,
80
- * FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression.
80
+ * @param {ASTNode} node A node of the scope.
81
+ * For functions, this is one of FunctionDeclaration, FunctionExpression.
82
+ * For class static blocks, this is StaticBlock.
83
+ * For class field initializers, this can be any node that is PropertyDefinition#value.
81
84
  * @returns {void}
82
85
  */
83
- function enterVarScope(node) {
86
+ function enterThisScope(node) {
84
87
  const strict = context.getScope().isStrict;
85
88
 
86
89
  funcInfo = {
@@ -97,7 +100,7 @@ module.exports = {
97
100
  * Pops a variable scope from the stack.
98
101
  * @returns {void}
99
102
  */
100
- function exitVarScope() {
103
+ function exitThisScope() {
101
104
  funcInfo = funcInfo.upper;
102
105
  }
103
106
 
@@ -239,21 +242,19 @@ module.exports = {
239
242
  "Program:exit"() {
240
243
  const globalScope = context.getScope();
241
244
 
242
- exitVarScope();
245
+ exitThisScope();
243
246
  reportAccessingEval(globalScope);
244
247
  reportAccessingEvalViaGlobalObject(globalScope);
245
248
  },
246
249
 
247
- FunctionDeclaration: enterVarScope,
248
- "FunctionDeclaration:exit": exitVarScope,
249
- FunctionExpression: enterVarScope,
250
- "FunctionExpression:exit": exitVarScope,
251
- ArrowFunctionExpression: enterVarScope,
252
- "ArrowFunctionExpression:exit": exitVarScope,
253
- "PropertyDefinition > *.value": enterVarScope,
254
- "PropertyDefinition > *.value:exit": exitVarScope,
255
- StaticBlock: enterVarScope,
256
- "StaticBlock:exit": exitVarScope,
250
+ FunctionDeclaration: enterThisScope,
251
+ "FunctionDeclaration:exit": exitThisScope,
252
+ FunctionExpression: enterThisScope,
253
+ "FunctionExpression:exit": exitThisScope,
254
+ "PropertyDefinition > *.value": enterThisScope,
255
+ "PropertyDefinition > *.value:exit": exitThisScope,
256
+ StaticBlock: enterThisScope,
257
+ "StaticBlock:exit": exitThisScope,
257
258
 
258
259
  ThisExpression(node) {
259
260
  if (!isMember(node.parent, "eval")) {
@@ -76,8 +76,8 @@ module.exports = {
76
76
 
77
77
  fixable: "code",
78
78
  messages: {
79
- replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}=).",
80
- unexpected: "Unexpected operator assignment ({{operator}}=) shorthand."
79
+ replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}).",
80
+ unexpected: "Unexpected operator assignment ({{operator}}) shorthand."
81
81
  }
82
82
  },
83
83
 
@@ -109,11 +109,13 @@ module.exports = {
109
109
  const operator = expr.operator;
110
110
 
111
111
  if (isCommutativeOperatorWithShorthand(operator) || isNonCommutativeOperatorWithShorthand(operator)) {
112
+ const replacementOperator = `${operator}=`;
113
+
112
114
  if (astUtils.isSameReference(left, expr.left, true)) {
113
115
  context.report({
114
116
  node,
115
117
  messageId: "replaced",
116
- data: { operator },
118
+ data: { operator: replacementOperator },
117
119
  fix(fixer) {
118
120
  if (canBeFixed(left) && canBeFixed(expr.left)) {
119
121
  const equalsToken = getOperatorToken(node);
@@ -126,7 +128,7 @@ module.exports = {
126
128
  return null;
127
129
  }
128
130
 
129
- return fixer.replaceText(node, `${leftText}${expr.operator}=${rightText}`);
131
+ return fixer.replaceText(node, `${leftText}${replacementOperator}${rightText}`);
130
132
  }
131
133
  return null;
132
134
  }
@@ -141,7 +143,7 @@ module.exports = {
141
143
  context.report({
142
144
  node,
143
145
  messageId: "replaced",
144
- data: { operator }
146
+ data: { operator: replacementOperator }
145
147
  });
146
148
  }
147
149
  }
@@ -173,3 +173,27 @@ module.exports = {};
173
173
  * @property {string} ruleId The rule ID.
174
174
  * @property {string[]} replacedBy The rule IDs that replace this deprecated rule.
175
175
  */
176
+
177
+ /**
178
+ * A linting result.
179
+ * @typedef {Object} LintResult
180
+ * @property {string} filePath The path to the file that was linted.
181
+ * @property {LintMessage[]} messages All of the messages for the result.
182
+ * @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result.
183
+ * @property {number} errorCount Number of errors for the result.
184
+ * @property {number} fatalErrorCount Number of fatal errors for the result.
185
+ * @property {number} warningCount Number of warnings for the result.
186
+ * @property {number} fixableErrorCount Number of fixable errors for the result.
187
+ * @property {number} fixableWarningCount Number of fixable warnings for the result.
188
+ * @property {string} [source] The source code of the file that was linted.
189
+ * @property {string} [output] The source code of the file that was linted, with as many fixes applied as possible.
190
+ * @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules.
191
+ */
192
+
193
+ /**
194
+ * A formatter function.
195
+ * @callback FormatterFunction
196
+ * @param {LintResult[]} results The list of linting results.
197
+ * @param {{cwd: string, rulesMeta: Record<string, RuleMeta>}} [context] A context object.
198
+ * @returns {string | Promise<string>} Formatted text.
199
+ */
@@ -12,5 +12,5 @@ If you do want to lint these files, try the following solutions:
12
12
 
13
13
  * Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
14
14
  * Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.
15
- `.trimLeft();
15
+ `.trimStart();
16
16
  };
@@ -9,5 +9,5 @@ ESLint couldn't find the config "${configName}" to extend from. Please check tha
9
9
  The config "${configName}" was referenced from the config file in "${importerName}".
10
10
 
11
11
  If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.
12
- `.trimLeft();
12
+ `.trimStart();
13
13
  };
@@ -7,5 +7,5 @@ module.exports = function(it) {
7
7
  Failed to read JSON file at ${path}:
8
8
 
9
9
  ${message}
10
- `.trimLeft();
10
+ `.trimStart();
11
11
  };
@@ -6,5 +6,5 @@ module.exports = function(it) {
6
6
  return `
7
7
  No files matching the pattern "${pattern}"${globDisabled ? " (with disabling globs)" : ""} were found.
8
8
  Please check for typing mistakes in the pattern.
9
- `.trimLeft();
9
+ `.trimStart();
10
10
  };
@@ -11,5 +11,5 @@ ESLint couldn't find a configuration file. To set up a configuration file for th
11
11
  ESLint looked for configuration files in ${directoryPath} and its ancestors. If it found none, it then looked in your home directory.
12
12
 
13
13
  If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
14
- `.trimLeft();
14
+ `.trimStart();
15
15
  };
@@ -12,5 +12,5 @@ module.exports = function(it) {
12
12
  "${configName}" was referenced from the config file in "${importerName}".
13
13
 
14
14
  If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
15
- `.trimLeft();
15
+ `.trimStart();
16
16
  };
@@ -15,5 +15,5 @@ It's likely that the plugin isn't installed correctly. Try reinstalling by runni
15
15
  The plugin "${pluginName}" was referenced from the config file in "${importerName}".
16
16
 
17
17
  If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
18
- `.trimLeft();
18
+ `.trimStart();
19
19
  };
@@ -4,5 +4,5 @@ module.exports = function() {
4
4
  return `
5
5
  The '--print-config' CLI option requires a path to a source code file rather than a directory.
6
6
  See also: https://eslint.org/docs/user-guide/command-line-interface#--print-config
7
- `.trimLeft();
7
+ `.trimStart();
8
8
  };
@@ -7,5 +7,5 @@ module.exports = function(it) {
7
7
  ESLint couldn't find the plugin "${pluginName}". because there is whitespace in the name. Please check your configuration and remove all whitespace from the plugin name.
8
8
 
9
9
  If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
10
- `.trimLeft();
10
+ `.trimStart();
11
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.12.0",
3
+ "version": "8.13.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {