Repository: eslint/eslint
Pull request #15338 (2021-11-21 04:09:48)

feat: Update espree and eslint-scope
<!--
    Thank you for contributing!

    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

#### Prerequisites checklist

- [x] I have read the [contributing guidelines](https://github.com/eslint/eslint/blob/HEAD/CONTRIBUTING.md).

#### What is the purpose of this pull request? (put an "X" next to an item)

<!--
    The following template is intentionally not a markdown checkbox list for the reasons
    explained in https://github.com/eslint/eslint/pull/12848#issuecomment-580302888
-->

[ ] Documentation update
[ ] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/HEAD/templates/bug-report.md))
[ ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/HEAD/templates/rule-proposal.md))
[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/HEAD/templates/rule-change-proposal.md))
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain: Upgrade `espree` and `eslint-scope`

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (https://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

#### What changes did you make? (Give an overview)

These releases include support for ES2022 class static blocks and `sourceType: "commonjs"`.

#### Is there anything you'd like reviewers to focus on?

No


Patch:
diff --git a/docs/rules/max-depth.md b/docs/rules/max-depth.md
index b853d0267..ae8121e69 100644
--- a/docs/rules/max-depth.md
+++ b/docs/rules/max-depth.md
@@ -20,7 +20,6 @@ Examples of **incorrect** code for this rule with the default `{ "max": 4 }` opt
 
 ```js
 /*eslint max-depth: ["error", 4]*/
-/*eslint-env es6*/
 
 function foo() {
     for (;;) { // Nested 1 deep
@@ -40,7 +39,6 @@ Examples of **correct** code for this rule with the default `{ "max": 4 }` optio
 
 ```js
 /*eslint max-depth: ["error", 4]*/
-/*eslint-env es6*/
 
 function foo() {
     for (;;) { // Nested 1 deep
@@ -54,6 +52,48 @@ function foo() {
 }
 ```
 
+Note that class static blocks do not count as nested blocks, and that the depth in them is calculated separately from the enclosing context.
+
+Examples of **incorrect** code for this rule with `{ "max": 2 }` option:
+
+```js
+/*eslint max-depth: ["error", 2]*/
+
+function foo() {
+    if (true) { // Nested 1 deep
+        class C {
+            static {
+                if (true) { // Nested 1 deep
+                    if (true) { // Nested 2 deep
+                        if (true) { // Nested 3 deep
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+```
+
+Examples of **correct** code for this rule with `{ "max": 2 }` option:
+
+```js
+/*eslint max-depth: ["error", 2]*/
+
+function foo() {
+    if (true) { // Nested 1 deep
+        class C {
+            static {
+                if (true) { // Nested 1 deep
+                    if (true) { // Nested 2 deep
+                    }
+                }
+            }
+        }
+    }
+}
+```
+
 ## Related Rules
 
 * [complexity](complexity.md)
diff --git a/lib/rules/max-depth.js b/lib/rules/max-depth.js
index 415598b29..bdacc66af 100644
--- a/lib/rules/max-depth.js
+++ b/lib/rules/max-depth.js
@@ -118,6 +118,7 @@ module.exports = {
             FunctionDeclaration: startFunction,
             FunctionExpression: startFunction,
             ArrowFunctionExpression: startFunction,
+            StaticBlock: startFunction,
 
             IfStatement(node) {
                 if (node.parent.type !== "IfStatement") {
@@ -146,6 +147,7 @@ module.exports = {
             "FunctionDeclaration:exit": endFunction,
             "FunctionExpression:exit": endFunction,
             "ArrowFunctionExpression:exit": endFunction,
+            "StaticBlock:exit": endFunction,
             "Program:exit": endFunction
         };
 
diff --git a/package.json b/package.json
index 697da3abf..e36330582 100644
--- a/package.json
+++ b/package.json
@@ -56,10 +56,10 @@
     "doctrine": "^3.0.0",
     "enquirer": "^2.3.5",
     "escape-string-regexp": "^4.0.0",
-    "eslint-scope": "^7.0.0",
+    "eslint-scope": "^7.1.0",
     "eslint-utils": "^3.0.0",
     "eslint-visitor-keys": "^3.1.0",
-    "espree": "^9.0.0",
+    "espree": "^9.1.0",
     "esquery": "^1.4.0",
     "esutils": "^2.0.2",
     "fast-deep-equal": "^3.1.3",


Test patch:
diff --git a/tests/lib/rules/max-depth.js b/tests/lib/rules/max-depth.js
index 0b4f846dd..b35b60301 100644
--- a/tests/lib/rules/max-depth.js
+++ b/tests/lib/rules/max-depth.js
@@ -26,7 +26,18 @@ ruleTester.run("max-depth", rule, {
         "function foo() { if (true) { if (false) { if (true) { } } } }",
 
         // object property options
-        { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 3 }] }
+        { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 3 }] },
+
+        { code: "class C { static { if (1) { if (2) {} } } }", options: [2], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class C { static { if (1) { if (2) {} } if (1) { if (2) {} } } }", options: [2], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class C { static { if (1) { if (2) {} } } static { if (1) { if (2) {} } } }", options: [2], parserOptions: { ecmaVersion: 2022 } },
+        { code: "if (1) { class C { static { if (1) { if (2) {} } } } }", options: [2], parserOptions: { ecmaVersion: 2022 } },
+        { code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } } }", options: [2], parserOptions: { ecmaVersion: 2022 } },
+        {
+            code: "function foo() { if (1) { if (2) { class C { static { if (1) { if (2) {} } if (1) { if (2) {} } } } } } if (1) { if (2) {} } }",
+            options: [2],
+            parserOptions: { ecmaVersion: 2022 }
+        }
     ],
     invalid: [
         { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }] },
@@ -41,6 +52,51 @@ ruleTester.run("max-depth", rule, {
         { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 2 }], errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }] },
 
         { code: "function foo() { if (a) { if (b) { if (c) { if (d) { if (e) {} } } } } }", options: [{}], errors: [{ messageId: "tooDeeply", data: { depth: 5, maxDepth: 4 } }] },
-        { code: "function foo() { if (true) {} }", options: [{ max: 0 }], errors: [{ messageId: "tooDeeply", data: { depth: 1, maxDepth: 0 } }] }
+        { code: "function foo() { if (true) {} }", options: [{ max: 0 }], errors: [{ messageId: "tooDeeply", data: { depth: 1, maxDepth: 0 } }] },
+
+        {
+            code: "class C { static { if (1) { if (2) { if (3) {} } } } }",
+            options: [2],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{
+                messageId: "tooDeeply",
+                data: { depth: 3, maxDepth: 2 },
+                line: 1,
+                column: 38
+            }]
+        },
+        {
+            code: "if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } }",
+            options: [2],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{
+                messageId: "tooDeeply",
+                data: { depth: 3, maxDepth: 2 },
+                line: 1,
+                column: 47
+            }]
+        },
+        {
+            code: "function foo() { if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } } }",
+            options: [2],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{
+                messageId: "tooDeeply",
+                data: { depth: 3, maxDepth: 2 },
+                line: 1,
+                column: 64
+            }]
+        },
+        {
+            code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } if (2) { if (3) {} } } }",
+            options: [2],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{
+                messageId: "tooDeeply",
+                data: { depth: 3, maxDepth: 2 },
+                line: 1,
+                column: 80
+            }]
+        }
     ]
 });