eslint 8.11.0 → 8.12.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.
@@ -87,6 +87,7 @@ module.exports = {
87
87
  upper: funcInfo,
88
88
  node,
89
89
  strict,
90
+ isTopLevelOfScript: false,
90
91
  defaultThis: false,
91
92
  initialized: strict
92
93
  };
@@ -222,12 +223,14 @@ module.exports = {
222
223
  strict =
223
224
  scope.isStrict ||
224
225
  node.sourceType === "module" ||
225
- (features.globalReturn && scope.childScopes[0].isStrict);
226
+ (features.globalReturn && scope.childScopes[0].isStrict),
227
+ isTopLevelOfScript = node.sourceType !== "module" && !features.globalReturn;
226
228
 
227
229
  funcInfo = {
228
230
  upper: null,
229
231
  node,
230
232
  strict,
233
+ isTopLevelOfScript,
231
234
  defaultThis: true,
232
235
  initialized: true
233
236
  };
@@ -269,7 +272,8 @@ module.exports = {
269
272
  );
270
273
  }
271
274
 
272
- if (!funcInfo.strict && funcInfo.defaultThis) {
275
+ // `this` at the top level of scripts always refers to the global object
276
+ if (funcInfo.isTopLevelOfScript || (!funcInfo.strict && funcInfo.defaultThis)) {
273
277
 
274
278
  // `this.eval` is possible built-in `eval`.
275
279
  report(node.parent);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview A rule to disallow `this` keywords outside of classes or class-like objects.
2
+ * @fileoverview A rule to disallow `this` keywords in contexts where the value of `this` is `undefined`.
3
3
  * @author Toru Nagashima
4
4
  */
5
5
 
@@ -36,7 +36,7 @@ module.exports = {
36
36
  type: "suggestion",
37
37
 
38
38
  docs: {
39
- description: "disallow `this` keywords outside of classes or class-like objects",
39
+ description: "disallow use of `this` in contexts where the value of `this` is `undefined`",
40
40
  recommended: false,
41
41
  url: "https://eslint.org/docs/rules/no-invalid-this"
42
42
  },
@@ -98,11 +98,11 @@ module.exports = {
98
98
  const scope = context.getScope();
99
99
  const features = context.parserOptions.ecmaFeatures || {};
100
100
 
101
+ // `this` at the top level of scripts always refers to the global object
101
102
  stack.push({
102
103
  init: true,
103
104
  node,
104
105
  valid: !(
105
- scope.isStrict ||
106
106
  node.sourceType === "module" ||
107
107
  (features.globalReturn && scope.childScopes[0].isStrict)
108
108
  )
@@ -450,8 +450,7 @@ module.exports = {
450
450
  type: "array",
451
451
  items: { enum: Object.keys(StatementTypes) },
452
452
  minItems: 1,
453
- uniqueItems: true,
454
- additionalItems: false
453
+ uniqueItems: true
455
454
  }
456
455
  ]
457
456
  }
@@ -466,8 +465,7 @@ module.exports = {
466
465
  },
467
466
  additionalProperties: false,
468
467
  required: ["blankLine", "prev", "next"]
469
- },
470
- additionalItems: false
468
+ }
471
469
  },
472
470
 
473
471
  messages: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.11.0",
3
+ "version": "8.12.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {