]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/object-shorthand.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / rules / object-shorthand.js
index 01a72f4e6f0a3259e949da7cf1354331fbbb89a2..58bb5708327592e8efda9fa42c5fe222798e9677 100644 (file)
@@ -185,6 +185,52 @@ ruleTester.run("object-shorthand", rule, {
             options: ["never"]
         },
 
+        // methodsIgnorePattern
+        {
+            code: "var x = { foo: function() {}  }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }]
+        },
+        {
+            code: "var x = { foo: function() {}  }",
+            options: ["methods", { methodsIgnorePattern: "^foo$" }]
+        },
+        {
+            code: "var x = { foo: function*() {}  }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }]
+        },
+        {
+            code: "var x = { foo: async function() {}  }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }]
+        },
+        {
+            code: "var x = { foo: () => { return 5; }  }",
+            options: ["always", { methodsIgnorePattern: "^foo$", avoidExplicitReturnArrows: true }]
+        },
+        {
+            code: "var x = { 'foo': function() {}  }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }]
+        },
+        {
+            code: "var x = { ['foo']: function() {}  }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }]
+        },
+        {
+            code: "var x = { 123: function() {}  }",
+            options: ["always", { methodsIgnorePattern: "^123$" }]
+        },
+        {
+            code: "var x = { afoob: function() {}  }",
+            options: ["always", { methodsIgnorePattern: "foo" }]
+        },
+        {
+            code: "var x = { afoob: function() {}  }",
+            options: ["always", { methodsIgnorePattern: "^.foo.$" }]
+        },
+        {
+            code: "var x = { '👍foo👍': function() {}  }", // this wouldn't pass without the "u" flag
+            options: ["always", { methodsIgnorePattern: "^.foo.$" }]
+        },
+
         // avoidQuotes
         {
             code: "var x = {'a': function(){}}",
@@ -781,6 +827,50 @@ ruleTester.run("object-shorthand", rule, {
             errors: [METHOD_ERROR]
         },
 
+        // methodsIgnorePattern
+        {
+            code: "var x = { afoob: function() {} }",
+            output: "var x = { afoob() {} }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }],
+            errors: [METHOD_ERROR]
+        },
+        {
+            code: "var x = { afoob: function() {} }",
+            output: "var x = { afoob() {} }",
+            options: ["methods", { methodsIgnorePattern: "^foo$" }],
+            errors: [METHOD_ERROR]
+        },
+        {
+            code: "var x = { 'afoob': function() {} }",
+            output: "var x = { 'afoob'() {} }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }],
+            errors: [METHOD_ERROR]
+        },
+        {
+            code: "var x = { 1234: function() {} }",
+            output: "var x = { 1234() {} }",
+            options: ["always", { methodsIgnorePattern: "^123$" }],
+            errors: [METHOD_ERROR]
+        },
+        {
+            code: "var x = { bar: function() {} }",
+            output: "var x = { bar() {} }",
+            options: ["always", { methodsIgnorePattern: "foo" }],
+            errors: [METHOD_ERROR]
+        },
+        {
+            code: "var x = { [foo]: function() {} }",
+            output: "var x = { [foo]() {} }",
+            options: ["always", { methodsIgnorePattern: "foo" }],
+            errors: [METHOD_ERROR]
+        },
+        {
+            code: "var x = { foo: foo }", // does not apply to properties
+            output: "var x = { foo }",
+            options: ["always", { methodsIgnorePattern: "^foo$" }],
+            errors: [PROPERTY_ERROR]
+        },
+
         // avoidQuotes
         {
             code: "var x = {a: a}",