]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/no-underscore-dangle.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / rules / no-underscore-dangle.js
index c83a5b3fe28435dad48abe97761d11767b233d00..f3e11cc3e76b05bb2afc27dab831a24560948908 100644 (file)
@@ -71,7 +71,10 @@ ruleTester.run("no-underscore-dangle", rule, {
         { code: "function foo( { _bar = 0 } = {}) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } },
         { code: "function foo(...[_bar]) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 2016 } },
         { code: "class foo { _field; }", parserOptions: { ecmaVersion: 2022 } },
-        { code: "class foo { #_field; }", parserOptions: { ecmaVersion: 2022 } }
+        { code: "class foo { _field; }", options: [{ enforceInClassFields: false }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class foo { #_field; }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class foo { #_field; }", options: [{ enforceInClassFields: false }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class foo { _field; }", options: [{}], parserOptions: { ecmaVersion: 2022 } }
     ],
     invalid: [
         { code: "var _foo = 1", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" }, type: "VariableDeclarator" }] },
@@ -109,6 +112,30 @@ ruleTester.run("no-underscore-dangle", rule, {
             options: [{ enforceInMethodNames: true }],
             parserOptions: { ecmaVersion: 2022 },
             errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }]
+        },
+        {
+            code: "class foo { _field; }",
+            options: [{ enforceInClassFields: true }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }]
+        },
+        {
+            code: "class foo { #_field; }",
+            options: [{ enforceInClassFields: true }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }]
+        },
+        {
+            code: "class foo { field_; }",
+            options: [{ enforceInClassFields: true }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }]
+        },
+        {
+            code: "class foo { #field_; }",
+            options: [{ enforceInClassFields: true }],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#field_" } }]
         }
     ]
 });