]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/prefer-reflect.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / prefer-reflect.js
1 /**
2 * @fileoverview Tests for prefer-reflect rule.
3 * @author Keith Cirkel
4 * @deprecated in ESLint v3.9.0
5 */
6
7 "use strict";
8
9 //------------------------------------------------------------------------------
10 // Requirements
11 //------------------------------------------------------------------------------
12 const rule = require("../../../lib/rules/prefer-reflect"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("prefer-reflect", rule, {
22 valid: [
23
24 // Reflect.apply
25 "Reflect.apply(function(){}, null, 1, 2);",
26 { code: "Reflect.apply(function(){}, null, 1, 2);", options: [{ exceptions: ["apply"] }] },
27 { code: "(function(){}).apply(null, [1, 2]);", options: [{ exceptions: ["apply"] }] },
28 { code: "(function(){}).call(null, 1, 2);", options: [{ exceptions: ["call"] }] },
29
30 // Reflect.defineProperty
31 "Reflect.defineProperty({}, 'foo', {value: 1})",
32 { code: "Reflect.defineProperty({}, 'foo', {value: 1})", options: [{ exceptions: ["defineProperty"] }] },
33 { code: "Object.defineProperty({}, 'foo', {value: 1})", options: [{ exceptions: ["defineProperty"] }] },
34
35 // Reflect.getOwnPropertyDescriptor
36 "Reflect.getOwnPropertyDescriptor({}, 'foo');",
37 { code: "Reflect.getOwnPropertyDescriptor({}, 'foo');", options: [{ exceptions: ["getOwnPropertyDescriptor"] }] },
38 { code: "Object.getOwnPropertyDescriptor({}, 'foo');", options: [{ exceptions: ["getOwnPropertyDescriptor"] }] },
39
40 // Reflect.getPrototypeOf
41 "Reflect.getPrototypeOf({});",
42 { code: "Reflect.getPrototypeOf({});", options: [{ exceptions: ["getPrototypeOf"] }] },
43 { code: "Object.getPrototypeOf({});", options: [{ exceptions: ["getPrototypeOf"] }] },
44
45 // Reflect.setPrototypeOf
46 "Reflect.setPrototypeOf({}, Object.prototype);",
47 { code: "Reflect.setPrototypeOf({}, Object.prototype);", options: [{ exceptions: ["setPrototypeOf"] }] },
48 { code: "Object.setPrototypeOf({}, Object.prototype);", options: [{ exceptions: ["setPrototypeOf"] }] },
49
50 // Reflect.isExtensible
51 "Reflect.isExtensible({});",
52 { code: "Reflect.isExtensible({});", options: [{ exceptions: ["isExtensible"] }] },
53 { code: "Object.isExtensible({});", options: [{ exceptions: ["isExtensible"] }] },
54
55 // Reflect.getOwnPropertyNames
56 "Reflect.getOwnPropertyNames({});",
57 { code: "Reflect.getOwnPropertyNames({});", options: [{ exceptions: ["getOwnPropertyNames"] }] },
58 { code: "Object.getOwnPropertyNames({});", options: [{ exceptions: ["getOwnPropertyNames"] }] },
59
60 // Reflect.getOwnPropertyNames
61 "Reflect.preventExtensions({});",
62 { code: "Reflect.preventExtensions({});", options: [{ exceptions: ["preventExtensions"] }] },
63 { code: "Object.preventExtensions({});", options: [{ exceptions: ["preventExtensions"] }] },
64
65 // Reflect.getOwnPropertyNames
66 "Reflect.deleteProperty({}, 'foo');",
67 { code: "Reflect.deleteProperty({}, 'foo');", options: [{ exceptions: ["delete"] }] },
68 "delete foo;",
69 { code: "delete ({}).foo", options: [{ exceptions: ["delete"] }] }
70 ],
71 invalid: [
72
73 {
74 code: "(function(){}).apply(null, [1, 2])",
75 errors: [
76 {
77 messageId: "preferReflect",
78 data: { existing: "Function.prototype.apply", substitute: "Reflect.apply" },
79 type: "CallExpression"
80 }
81 ]
82 },
83 {
84 code: "(function(){}).apply(null, [1, 2])",
85 options: [{ exceptions: ["defineProperty"] }],
86 errors: [
87 {
88 messageId: "preferReflect",
89 data: { existing: "Function.prototype.apply", substitute: "Reflect.apply" },
90 type: "CallExpression"
91 }
92 ]
93 },
94 {
95 code: "(function(){}).call(null, 1, 2)",
96 errors: [
97 {
98 messageId: "preferReflect",
99 data: { existing: "Function.prototype.call", substitute: "Reflect.apply" },
100 type: "CallExpression"
101 }
102 ]
103 },
104 {
105 code: "(function(){}).call(null, 1, 2)",
106 options: [{ exceptions: ["defineProperty"] }],
107 errors: [
108 {
109 messageId: "preferReflect",
110 data: { existing: "Function.prototype.call", substitute: "Reflect.apply" },
111 type: "CallExpression"
112 }
113 ]
114 },
115 {
116 code: "Object.defineProperty({}, 'foo', { value: 1 })",
117 errors: [
118 {
119 messageId: "preferReflect",
120 data: { existing: "Object.defineProperty", substitute: "Reflect.defineProperty" },
121 type: "CallExpression"
122 }
123 ]
124 },
125 {
126 code: "Object.defineProperty({}, 'foo', { value: 1 })",
127 options: [{ exceptions: ["apply"] }],
128 errors: [
129 {
130 messageId: "preferReflect",
131 data: { existing: "Object.defineProperty", substitute: "Reflect.defineProperty" },
132 type: "CallExpression"
133 }
134 ]
135 },
136 {
137 code: "Object.getOwnPropertyDescriptor({}, 'foo')",
138 errors: [
139 {
140 messageId: "preferReflect",
141 data: { existing: "Object.getOwnPropertyDescriptor", substitute: "Reflect.getOwnPropertyDescriptor" },
142 type: "CallExpression"
143 }
144 ]
145 },
146 {
147 code: "Object.getOwnPropertyDescriptor({}, 'foo')",
148 options: [{ exceptions: ["apply"] }],
149 errors: [
150 {
151 messageId: "preferReflect",
152 data: { existing: "Object.getOwnPropertyDescriptor", substitute: "Reflect.getOwnPropertyDescriptor" },
153 type: "CallExpression"
154 }
155 ]
156 },
157 {
158 code: "Object.getPrototypeOf({})",
159 errors: [
160 {
161 messageId: "preferReflect",
162 data: { existing: "Object.getPrototypeOf", substitute: "Reflect.getPrototypeOf" },
163 type: "CallExpression"
164 }
165 ]
166 },
167 {
168 code: "Object.getPrototypeOf({})",
169 options: [{ exceptions: ["apply"] }],
170 errors: [
171 {
172 messageId: "preferReflect",
173 data: { existing: "Object.getPrototypeOf", substitute: "Reflect.getPrototypeOf" },
174 type: "CallExpression"
175 }
176 ]
177 },
178 {
179 code: "Object.setPrototypeOf({}, Object.prototype)",
180 errors: [
181 {
182 messageId: "preferReflect",
183 data: { existing: "Object.setPrototypeOf", substitute: "Reflect.setPrototypeOf" },
184 type: "CallExpression"
185 }
186 ]
187 },
188 {
189 code: "Object.setPrototypeOf({}, Object.prototype)",
190 options: [{ exceptions: ["apply"] }],
191 errors: [
192 {
193 messageId: "preferReflect",
194 data: { existing: "Object.setPrototypeOf", substitute: "Reflect.setPrototypeOf" },
195 type: "CallExpression"
196 }
197 ]
198 },
199 {
200 code: "Object.isExtensible({})",
201 errors: [
202 {
203 messageId: "preferReflect",
204 data: { existing: "Object.isExtensible", substitute: "Reflect.isExtensible" },
205 type: "CallExpression"
206 }
207 ]
208 },
209 {
210 code: "Object.isExtensible({})",
211 options: [{ exceptions: ["apply"] }],
212 errors: [
213 {
214 messageId: "preferReflect",
215 data: { existing: "Object.isExtensible", substitute: "Reflect.isExtensible" },
216 type: "CallExpression"
217 }
218 ]
219 },
220 {
221 code: "Object.getOwnPropertyNames({})",
222 errors: [
223 {
224 messageId: "preferReflect",
225 data: { existing: "Object.getOwnPropertyNames", substitute: "Reflect.getOwnPropertyNames" },
226 type: "CallExpression"
227 }
228 ]
229 },
230 {
231 code: "Object.getOwnPropertyNames({})",
232 options: [{ exceptions: ["apply"] }],
233 errors: [
234 {
235 messageId: "preferReflect",
236 data: { existing: "Object.getOwnPropertyNames", substitute: "Reflect.getOwnPropertyNames" },
237 type: "CallExpression"
238 }
239 ]
240 },
241 {
242 code: "Object.preventExtensions({})",
243 errors: [
244 {
245 messageId: "preferReflect",
246 data: { existing: "Object.preventExtensions", substitute: "Reflect.preventExtensions" },
247 type: "CallExpression"
248 }
249 ]
250 },
251 {
252 code: "Object.preventExtensions({})",
253 options: [{ exceptions: ["apply"] }],
254 errors: [
255 {
256 messageId: "preferReflect",
257 data: { existing: "Object.preventExtensions", substitute: "Reflect.preventExtensions" },
258 type: "CallExpression"
259 }
260 ]
261 },
262 {
263 code: "delete ({}).foo",
264 errors: [
265 {
266 messageId: "preferReflect",
267 data: { existing: "the delete keyword", substitute: "Reflect.deleteProperty" },
268 type: "UnaryExpression"
269 }
270 ]
271 },
272 {
273 code: "delete ({}).foo",
274 options: [{ exceptions: ["apply"] }],
275 errors: [
276 {
277 messageId: "preferReflect",
278 data: { existing: "the delete keyword", substitute: "Reflect.deleteProperty" },
279 type: "UnaryExpression"
280 }
281 ]
282 }
283
284 ]
285 });