]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-prototype-builtins.js
2 * @fileoverview Tests for no-prototype-built-ins
3 * @author Andrew Levine
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-prototype-builtins"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-prototype-builtins", rule
, {
23 "Object.prototype.hasOwnProperty.call(foo, 'bar')",
24 "Object.prototype.isPrototypeOf.call(foo, 'bar')",
25 "Object.prototype.propertyIsEnumerable.call(foo, 'bar')",
26 "Object.prototype.hasOwnProperty.apply(foo, ['bar'])",
27 "Object.prototype.isPrototypeOf.apply(foo, ['bar'])",
28 "Object.prototype.propertyIsEnumerable.apply(foo, ['bar'])",
30 "foo.hasOwnProperty.bar()",
31 "foo(hasOwnProperty)",
32 "hasOwnProperty(foo, 'bar')",
33 "isPrototypeOf(foo, 'bar')",
34 "propertyIsEnumerable(foo, 'bar')",
35 "({}.hasOwnProperty.call(foo, 'bar'))",
36 "({}.isPrototypeOf.call(foo, 'bar'))",
37 "({}.propertyIsEnumerable.call(foo, 'bar'))",
38 "({}.hasOwnProperty.apply(foo, ['bar']))",
39 "({}.isPrototypeOf.apply(foo, ['bar']))",
40 "({}.propertyIsEnumerable.apply(foo, ['bar']))",
41 "foo[hasOwnProperty]('bar')",
42 "foo['HasOwnProperty']('bar')",
43 { code
: "foo[`isPrototypeOff`]('bar')", parserOptions
: { ecmaVersion
: 2015 } },
44 { code
: "foo?.['propertyIsEnumerabl']('bar')", parserOptions
: { ecmaVersion
: 2020 } },
47 { code
: "class C { #hasOwnProperty; foo() { obj.#hasOwnProperty('bar'); } }", parserOptions
: { ecmaVersion
: 2022 } },
49 // out of scope for this rule
50 "foo['hasOwn' + 'Property']('bar')",
51 { code
: "foo[`hasOwnProperty${''}`]('bar')", parserOptions
: { ecmaVersion
: 2015 } }
56 code
: "foo.hasOwnProperty('bar')",
62 messageId
: "prototypeBuildIn",
63 data
: { prop
: "hasOwnProperty" },
64 type
: "CallExpression"
68 code
: "foo.isPrototypeOf('bar')",
74 messageId
: "prototypeBuildIn",
75 data
: { prop
: "isPrototypeOf" },
76 type
: "CallExpression"
80 code
: "foo.propertyIsEnumerable('bar')",
86 messageId
: "prototypeBuildIn",
87 data
: { prop
: "propertyIsEnumerable" }
91 code
: "foo.bar.hasOwnProperty('bar')",
97 messageId
: "prototypeBuildIn",
98 data
: { prop
: "hasOwnProperty" },
99 type
: "CallExpression"
103 code
: "foo.bar.baz.isPrototypeOf('bar')",
109 messageId
: "prototypeBuildIn",
110 data
: { prop
: "isPrototypeOf" },
111 type
: "CallExpression"
115 code
: "foo['hasOwnProperty']('bar')",
121 messageId
: "prototypeBuildIn",
122 data
: { prop
: "hasOwnProperty" },
123 type
: "CallExpression"
127 code
: "foo[`isPrototypeOf`]('bar').baz",
128 parserOptions
: { ecmaVersion
: 2015 },
134 messageId
: "prototypeBuildIn",
135 data
: { prop
: "isPrototypeOf" },
136 type
: "CallExpression"
140 code
: String
.raw
`foo.bar["propertyIsEnumerable"]('baz')`,
146 messageId
: "prototypeBuildIn",
147 data
: { prop
: "propertyIsEnumerable" },
148 type
: "CallExpression"
154 code
: "foo?.hasOwnProperty('bar')",
155 parserOptions
: { ecmaVersion
: 2020 },
156 errors
: [{ messageId
: "prototypeBuildIn", data
: { prop
: "hasOwnProperty" } }]
159 code
: "(foo?.hasOwnProperty)('bar')",
160 parserOptions
: { ecmaVersion
: 2020 },
161 errors
: [{ messageId
: "prototypeBuildIn", data
: { prop
: "hasOwnProperty" } }]
164 code
: "foo?.['hasOwnProperty']('bar')",
165 parserOptions
: { ecmaVersion
: 2020 },
166 errors
: [{ messageId
: "prototypeBuildIn", data
: { prop
: "hasOwnProperty" } }]
169 code
: "(foo?.[`hasOwnProperty`])('bar')",
170 parserOptions
: { ecmaVersion
: 2020 },
171 errors
: [{ messageId
: "prototypeBuildIn", data
: { prop
: "hasOwnProperty" } }]