]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/prefer-reflect.js
2 * @fileoverview Tests for prefer-reflect rule.
4 * @deprecated in ESLint v3.9.0
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/prefer-reflect"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("prefer-reflect", rule
, {
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"] }] },
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"] }] },
35 // Reflect.getOwnPropertyDescriptor
36 "Reflect.getOwnPropertyDescriptor({}, 'foo');",
37 { code
: "Reflect.getOwnPropertyDescriptor({}, 'foo');", options
: [{ exceptions
: ["getOwnPropertyDescriptor"] }] },
38 { code
: "Object.getOwnPropertyDescriptor({}, 'foo');", options
: [{ exceptions
: ["getOwnPropertyDescriptor"] }] },
40 // Reflect.getPrototypeOf
41 "Reflect.getPrototypeOf({});",
42 { code
: "Reflect.getPrototypeOf({});", options
: [{ exceptions
: ["getPrototypeOf"] }] },
43 { code
: "Object.getPrototypeOf({});", options
: [{ exceptions
: ["getPrototypeOf"] }] },
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"] }] },
50 // Reflect.isExtensible
51 "Reflect.isExtensible({});",
52 { code
: "Reflect.isExtensible({});", options
: [{ exceptions
: ["isExtensible"] }] },
53 { code
: "Object.isExtensible({});", options
: [{ exceptions
: ["isExtensible"] }] },
55 // Reflect.getOwnPropertyNames
56 "Reflect.getOwnPropertyNames({});",
57 { code
: "Reflect.getOwnPropertyNames({});", options
: [{ exceptions
: ["getOwnPropertyNames"] }] },
58 { code
: "Object.getOwnPropertyNames({});", options
: [{ exceptions
: ["getOwnPropertyNames"] }] },
60 // Reflect.getOwnPropertyNames
61 "Reflect.preventExtensions({});",
62 { code
: "Reflect.preventExtensions({});", options
: [{ exceptions
: ["preventExtensions"] }] },
63 { code
: "Object.preventExtensions({});", options
: [{ exceptions
: ["preventExtensions"] }] },
65 // Reflect.getOwnPropertyNames
66 "Reflect.deleteProperty({}, 'foo');",
67 { code
: "Reflect.deleteProperty({}, 'foo');", options
: [{ exceptions
: ["delete"] }] },
69 { code
: "delete ({}).foo", options
: [{ exceptions
: ["delete"] }] }
74 code
: "(function(){}).apply(null, [1, 2])",
77 messageId
: "preferReflect",
78 data
: { existing
: "Function.prototype.apply", substitute
: "Reflect.apply" },
79 type
: "CallExpression"
84 code
: "(function(){}).apply(null, [1, 2])",
85 options
: [{ exceptions
: ["defineProperty"] }],
88 messageId
: "preferReflect",
89 data
: { existing
: "Function.prototype.apply", substitute
: "Reflect.apply" },
90 type
: "CallExpression"
95 code
: "(function(){}).call(null, 1, 2)",
98 messageId
: "preferReflect",
99 data
: { existing
: "Function.prototype.call", substitute
: "Reflect.apply" },
100 type
: "CallExpression"
105 code
: "(function(){}).call(null, 1, 2)",
106 options
: [{ exceptions
: ["defineProperty"] }],
109 messageId
: "preferReflect",
110 data
: { existing
: "Function.prototype.call", substitute
: "Reflect.apply" },
111 type
: "CallExpression"
116 code
: "Object.defineProperty({}, 'foo', { value: 1 })",
119 messageId
: "preferReflect",
120 data
: { existing
: "Object.defineProperty", substitute
: "Reflect.defineProperty" },
121 type
: "CallExpression"
126 code
: "Object.defineProperty({}, 'foo', { value: 1 })",
127 options
: [{ exceptions
: ["apply"] }],
130 messageId
: "preferReflect",
131 data
: { existing
: "Object.defineProperty", substitute
: "Reflect.defineProperty" },
132 type
: "CallExpression"
137 code
: "Object.getOwnPropertyDescriptor({}, 'foo')",
140 messageId
: "preferReflect",
141 data
: { existing
: "Object.getOwnPropertyDescriptor", substitute
: "Reflect.getOwnPropertyDescriptor" },
142 type
: "CallExpression"
147 code
: "Object.getOwnPropertyDescriptor({}, 'foo')",
148 options
: [{ exceptions
: ["apply"] }],
151 messageId
: "preferReflect",
152 data
: { existing
: "Object.getOwnPropertyDescriptor", substitute
: "Reflect.getOwnPropertyDescriptor" },
153 type
: "CallExpression"
158 code
: "Object.getPrototypeOf({})",
161 messageId
: "preferReflect",
162 data
: { existing
: "Object.getPrototypeOf", substitute
: "Reflect.getPrototypeOf" },
163 type
: "CallExpression"
168 code
: "Object.getPrototypeOf({})",
169 options
: [{ exceptions
: ["apply"] }],
172 messageId
: "preferReflect",
173 data
: { existing
: "Object.getPrototypeOf", substitute
: "Reflect.getPrototypeOf" },
174 type
: "CallExpression"
179 code
: "Object.setPrototypeOf({}, Object.prototype)",
182 messageId
: "preferReflect",
183 data
: { existing
: "Object.setPrototypeOf", substitute
: "Reflect.setPrototypeOf" },
184 type
: "CallExpression"
189 code
: "Object.setPrototypeOf({}, Object.prototype)",
190 options
: [{ exceptions
: ["apply"] }],
193 messageId
: "preferReflect",
194 data
: { existing
: "Object.setPrototypeOf", substitute
: "Reflect.setPrototypeOf" },
195 type
: "CallExpression"
200 code
: "Object.isExtensible({})",
203 messageId
: "preferReflect",
204 data
: { existing
: "Object.isExtensible", substitute
: "Reflect.isExtensible" },
205 type
: "CallExpression"
210 code
: "Object.isExtensible({})",
211 options
: [{ exceptions
: ["apply"] }],
214 messageId
: "preferReflect",
215 data
: { existing
: "Object.isExtensible", substitute
: "Reflect.isExtensible" },
216 type
: "CallExpression"
221 code
: "Object.getOwnPropertyNames({})",
224 messageId
: "preferReflect",
225 data
: { existing
: "Object.getOwnPropertyNames", substitute
: "Reflect.getOwnPropertyNames" },
226 type
: "CallExpression"
231 code
: "Object.getOwnPropertyNames({})",
232 options
: [{ exceptions
: ["apply"] }],
235 messageId
: "preferReflect",
236 data
: { existing
: "Object.getOwnPropertyNames", substitute
: "Reflect.getOwnPropertyNames" },
237 type
: "CallExpression"
242 code
: "Object.preventExtensions({})",
245 messageId
: "preferReflect",
246 data
: { existing
: "Object.preventExtensions", substitute
: "Reflect.preventExtensions" },
247 type
: "CallExpression"
252 code
: "Object.preventExtensions({})",
253 options
: [{ exceptions
: ["apply"] }],
256 messageId
: "preferReflect",
257 data
: { existing
: "Object.preventExtensions", substitute
: "Reflect.preventExtensions" },
258 type
: "CallExpression"
263 code
: "delete ({}).foo",
266 messageId
: "preferReflect",
267 data
: { existing
: "the delete keyword", substitute
: "Reflect.deleteProperty" },
268 type
: "UnaryExpression"
273 code
: "delete ({}).foo",
274 options
: [{ exceptions
: ["apply"] }],
277 messageId
: "preferReflect",
278 data
: { existing
: "the delete keyword", substitute
: "Reflect.deleteProperty" },
279 type
: "UnaryExpression"