Skip to content

Commit 5ffdf5d

Browse files
authored
prefer-prototype-methods: Update tests (#1734)
1 parent e6de810 commit 5ffdf5d

File tree

4 files changed

+86
-35
lines changed

4 files changed

+86
-35
lines changed

rules/prefer-prototype-methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function create(context) {
4646
return {
4747
node,
4848
messageId: methodName ? 'known-method' : 'unknown-method',
49-
data: {constructorName, methodName: String(methodName)},
49+
data: {constructorName, methodName},
5050
* fix(fixer) {
5151
yield fixer.replaceText(node.object, `${constructorName}.prototype`);
5252

test/prefer-prototype-methods.mjs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,10 @@ test.snapshot({
5050
'const foo = ({}.toString.call)(bar);',
5151
'function foo(){return[].slice.call(bar);}',
5252
'function foo(){return{}.toString.call(bar)}',
53-
],
54-
});
55-
56-
test.babel({
57-
testerOptions: {
58-
env: {es2021: true},
59-
},
60-
valid: [],
61-
invalid: [
62-
{
63-
code: 'Reflect.apply({}[Symbol()], baz, [])',
64-
output: 'Reflect.apply(Object.prototype[Symbol()], baz, [])',
65-
errors: [{message: 'Prefer using method from `Object.prototype`.'}],
66-
},
67-
{
68-
code: 'Reflect.apply({}[Symbol("symbol description")], baz, [])',
69-
output: 'Reflect.apply(Object.prototype[Symbol("symbol description")], baz, [])',
70-
errors: [{message: 'Prefer using method from `Object.prototype`.'}],
71-
},
72-
{
73-
code: 'Reflect.apply([][Symbol()], baz, [])',
74-
output: 'Reflect.apply(Array.prototype[Symbol()], baz, [])',
75-
errors: [{message: 'Prefer using method from `Array.prototype`.'}],
76-
},
77-
{
78-
code: 'Reflect.apply({}[Symbol("symbol description")], baz, [])',
79-
output: 'Reflect.apply(Object.prototype[Symbol("symbol description")], baz, [])',
80-
errors: [{message: 'Prefer using method from `Object.prototype`.'}],
81-
},
82-
{
83-
code: '[][Symbol.iterator].call(foo)',
84-
output: 'Array.prototype[Symbol.iterator].call(foo)',
85-
errors: [{message: 'Prefer using `Array.prototype.Symbol(Symbol.iterator)`.'}],
86-
},
53+
'Reflect.apply({}[Symbol()], baz, [])',
54+
'Reflect.apply({}[Symbol("symbol description")], baz, [])',
55+
'Reflect.apply([][Symbol()], baz, [])',
56+
'Reflect.apply({}[Symbol("symbol description")], baz, [])',
57+
'[][Symbol.iterator].call(foo)',
8758
],
8859
});

test/snapshots/prefer-prototype-methods.mjs.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,83 @@ Generated by [AVA](https://avajs.dev).
259259
> 1 | function foo(){return{}.toString.call(bar)}␊
260260
| ^^^^^^^^^^^ Prefer using \`Object.prototype.toString\`.␊
261261
`
262+
263+
## Invalid #17
264+
1 | Reflect.apply({}[Symbol()], baz, [])
265+
266+
> Output
267+
268+
`␊
269+
1 | Reflect.apply(Object.prototype[Symbol()], baz, [])␊
270+
`
271+
272+
> Error 1/1
273+
274+
`␊
275+
> 1 | Reflect.apply({}[Symbol()], baz, [])␊
276+
| ^^^^^^^^^^^^ Prefer using method from \`Object.prototype\`.␊
277+
`
278+
279+
## Invalid #18
280+
1 | Reflect.apply({}[Symbol("symbol description")], baz, [])
281+
282+
> Output
283+
284+
`␊
285+
1 | Reflect.apply(Object.prototype[Symbol("symbol description")], baz, [])␊
286+
`
287+
288+
> Error 1/1
289+
290+
`␊
291+
> 1 | Reflect.apply({}[Symbol("symbol description")], baz, [])␊
292+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using method from \`Object.prototype\`.␊
293+
`
294+
295+
## Invalid #19
296+
1 | Reflect.apply([][Symbol()], baz, [])
297+
298+
> Output
299+
300+
`␊
301+
1 | Reflect.apply(Array.prototype[Symbol()], baz, [])␊
302+
`
303+
304+
> Error 1/1
305+
306+
`␊
307+
> 1 | Reflect.apply([][Symbol()], baz, [])␊
308+
| ^^^^^^^^^^^^ Prefer using method from \`Array.prototype\`.␊
309+
`
310+
311+
## Invalid #20
312+
1 | Reflect.apply({}[Symbol("symbol description")], baz, [])
313+
314+
> Output
315+
316+
`␊
317+
1 | Reflect.apply(Object.prototype[Symbol("symbol description")], baz, [])␊
318+
`
319+
320+
> Error 1/1
321+
322+
`␊
323+
> 1 | Reflect.apply({}[Symbol("symbol description")], baz, [])␊
324+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using method from \`Object.prototype\`.␊
325+
`
326+
327+
## Invalid #21
328+
1 | [][Symbol.iterator].call(foo)
329+
330+
> Output
331+
332+
`␊
333+
1 | Array.prototype[Symbol.iterator].call(foo)␊
334+
`
335+
336+
> Error 1/1
337+
338+
`␊
339+
> 1 | [][Symbol.iterator].call(foo)␊
340+
| ^^^^^^^^^^^^^^^^^^^ Prefer using method from \`Array.prototype\`.␊
341+
`
266 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)