]>
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 }
53 // TODO(mdjermanovic): This test should become `invalid` in the next major version, when we upgrade the `globals` package.
55 code
: "WeakRef.prototype.p = 0",
60 code
: "Object.prototype.p = 0",
62 messageId
: "unexpected",
63 data
: { builtin
: "Object" },
64 type
: "AssignmentExpression"
67 code
: "BigInt.prototype.p = 0",
68 env
: { es2020
: true },
70 messageId
: "unexpected",
71 data
: { builtin
: "BigInt" },
72 type
: "AssignmentExpression"
75 code
: "Function.prototype['p'] = 0",
77 messageId
: "unexpected",
78 data
: { builtin
: "Function" },
79 type
: "AssignmentExpression"
82 code
: "String['prototype'].p = 0",
84 messageId
: "unexpected",
85 data
: { builtin
: "String" },
86 type
: "AssignmentExpression"
89 code
: "Number['prototype']['p'] = 0",
91 messageId
: "unexpected",
92 data
: { builtin
: "Number" },
93 type
: "AssignmentExpression"
96 code
: "Object.defineProperty(Array.prototype, 'p', {value: 0})",
98 messageId
: "unexpected",
99 data
: { builtin
: "Array" },
100 type
: "CallExpression"
103 code
: "Object.defineProperties(Array.prototype, {p: {value: 0}})",
105 messageId
: "unexpected",
106 data
: { builtin
: "Array" },
107 type
: "CallExpression"
110 code
: "Object.defineProperties(Array.prototype, {p: {value: 0}, q: {value: 0}})",
112 messageId
: "unexpected",
113 data
: { builtin
: "Array" },
114 type
: "CallExpression"
118 code
: "Number['prototype']['p'] = 0",
119 options
: [{ exceptions
: ["Object"] }],
121 messageId
: "unexpected",
122 data
: { builtin
: "Number" },
123 type
: "AssignmentExpression"
127 code
: "Object.prototype.p = 0; Object.prototype.q = 0",
129 messageId
: "unexpected",
130 data
: { builtin
: "Object" },
131 type
: "AssignmentExpression",
134 messageId
: "unexpected",
135 data
: { builtin
: "Object" },
136 type
: "AssignmentExpression",
141 code
: "function foo() { Object.prototype.p = 0 }",
143 messageId
: "unexpected",
144 data
: { builtin
: "Object" },
145 type
: "AssignmentExpression"
151 code
: "(Object?.prototype).p = 0",
152 parserOptions
: { ecmaVersion
: 2020 },
153 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
156 code
: "Object.defineProperty(Object?.prototype, 'p', { value: 0 })",
157 parserOptions
: { ecmaVersion
: 2020 },
158 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
161 code
: "Object?.defineProperty(Object.prototype, 'p', { value: 0 })",
162 parserOptions
: { ecmaVersion
: 2020 },
163 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
166 code
: "(Object?.defineProperty)(Object.prototype, 'p', { value: 0 })",
167 parserOptions
: { ecmaVersion
: 2020 },
168 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Object" } }]
171 // Logical assignments
173 code
: "Array.prototype.p &&= 0",
174 parserOptions
: { ecmaVersion
: 2021 },
175 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Array" } }]
178 code
: "Array.prototype.p ||= 0",
179 parserOptions
: { ecmaVersion
: 2021 },
180 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Array" } }]
183 code
: "Array.prototype.p ??= 0",
184 parserOptions
: { ecmaVersion
: 2021 },
185 errors
: [{ messageId
: "unexpected", data
: { builtin
: "Array" } }]