]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-extend-native.js
2 * @fileoverview Tests for no-extend-native rule.
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-extend-native"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-extend-native", rule
, {
24 "x.prototype['p'] = 0",
26 "Object.toString.bind = 0",
27 "Object['toString'].bind = 0",
28 "Object.defineProperty(x, 'p', {value: 0})",
29 "Object.defineProperties(x, {p: {value: 0}})",
30 "global.Object.prototype.toString = 0",
31 "this.Object.prototype.toString = 0",
32 "with(Object) { prototype.p = 0; }",
33 "o = Object; o.prototype.toString = 0",
34 "eval('Object.prototype.toString = 0')",
35 "parseFloat.prototype.x = 1",
37 code
: "Object.prototype.g = 0",
38 options
: [{ exceptions
: ["Object"] }]
40 "obj[Object.prototype] = 0",
42 // https://github.com/eslint/eslint/issues/4438
43 "Object.defineProperty()",
44 "Object.defineProperties()",
46 // https://github.com/eslint/eslint/issues/8461
47 "function foo() { var Object = function() {}; Object.prototype.p = 0 }",
49 code
: "{ let Object = function() {}; Object.prototype.p = 0 }",
50 parserOptions
: { ecmaVersion
: 6 }
54 code
: "Object.prototype.p = 0",
56 messageId
: "unexpected",
57 data
: { builtin
: "Object" },
58 type
: "AssignmentExpression"
61 code
: "BigInt.prototype.p = 0",
62 env
: { es2020
: true },
64 messageId
: "unexpected",
65 data
: { builtin
: "BigInt" },
66 type
: "AssignmentExpression"
69 code
: "WeakRef.prototype.p = 0",
70 env
: { es2021
: true },
72 messageId
: "unexpected",
73 data
: { builtin
: "WeakRef" },
74 type
: "AssignmentExpression"
77 code
: "FinalizationRegistry.prototype.p = 0",
78 env
: { es2021
: true },
80 messageId
: "unexpected",
81 data
: { builtin
: "FinalizationRegistry" },
82 type
: "AssignmentExpression"
85 code
: "AggregateError.prototype.p = 0",
86 env
: { es2021
: true },
88 messageId
: "unexpected",
89 data
: { builtin
: "AggregateError" },
90 type
: "AssignmentExpression"
93 code
: "Function.prototype['p'] = 0",
95 messageId
: "unexpected",
96 data
: { builtin
: "Function" },
97 type
: "AssignmentExpression"
100 code
: "String['prototype'].p = 0",
102 messageId
: "unexpected",
103 data
: { builtin
: "String" },
104 type
: "AssignmentExpression"
107 code
: "Number['prototype']['p'] = 0",
109 messageId
: "unexpected",
110 data
: { builtin
: "Number" },
111 type
: "AssignmentExpression"
114 code
: "Object.defineProperty(Array.prototype, 'p', {value: 0})",
116 messageId
: "unexpected",
117 data
: { builtin
: "Array" },
118 type
: "CallExpression"
121 code
: "Object.defineProperties(Array.prototype, {p: {value: 0}})",
123 messageId
: "unexpected",
124 data
: { builtin
: "Array" },
125 type
: "CallExpression"
128 code
: "Object.defineProperties(Array.prototype, {p: {value: 0}, q: {value: 0}})",
130 messageId
: "unexpected",
131 data
: { builtin
: "Array" },
132 type
: "CallExpression"
136 code
: "Number['prototype']['p'] = 0",
137 options
: [{ exceptions
: ["Object"] }],
139 messageId
: "unexpected",
140 data
: { builtin
: "Number" },
141 type
: "AssignmentExpression"
145 code
: "Object.prototype.p = 0; Object.prototype.q = 0",
147 messageId
: "unexpected",
148 data
: { builtin
: "Object" },
149 type
: "AssignmentExpression",
152 messageId
: "unexpected",
153 data
: { builtin
: "Object" },
154 type
: "AssignmentExpression",
159 code
: "function foo() { Object.prototype.p = 0 }",
161 messageId
: "unexpected",
162 data
: { builtin
: "Object" },
163 type
: "AssignmentExpression"
169 code
: "(Object?.prototype).p = 0",
170 parserOptions
: { ecmaVersion
: 2020 },
171 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
174 code
: "Object.defineProperty(Object?.prototype, 'p', { value: 0 })",
175 parserOptions
: { ecmaVersion
: 2020 },
176 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
179 code
: "Object?.defineProperty(Object.prototype, 'p', { value: 0 })",
180 parserOptions
: { ecmaVersion
: 2020 },
181 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
184 code
: "(Object?.defineProperty)(Object.prototype, 'p', { value: 0 })",
185 parserOptions
: { ecmaVersion
: 2020 },
186 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
189 // Logical assignments
191 code
: "Array.prototype.p &&= 0",
192 parserOptions
: { ecmaVersion
: 2021 },
193 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Array" } }]
196 code
: "Array.prototype.p ||= 0",
197 parserOptions
: { ecmaVersion
: 2021 },
198 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Array" } }]
201 code
: "Array.prototype.p ??= 0",
202 parserOptions
: { ecmaVersion
: 2021 },
203 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Array" } }]