|
1 | 1 | import test from 'ava'; |
2 | 2 | import AvaRuleTester from 'eslint-ava-rule-tester'; |
3 | 3 | import rule from '../../rules/from-map'; |
| 4 | +import testCases from "../helpers/from-map-test-cases"; |
4 | 5 |
|
5 | 6 | const ruleTester = new AvaRuleTester(test, { |
6 | 7 | parserOptions: { |
7 | 8 | ecmaVersion: 2015 |
8 | 9 | } |
9 | 10 | }); |
10 | 11 |
|
11 | | -ruleTester.run('from-map', rule, { |
12 | | - valid: [ |
13 | | - 'array.map((t) => t.id)', |
14 | | - 'Array.from(iterable).some((t) => t !== "a")', |
15 | | - 'Array.from(iterable, (t) => t.id)' |
16 | | - ], |
17 | | - invalid: [ |
18 | | - { |
19 | | - code: 'Array.from(iterable).map((t) => t.id)', |
20 | | - errors: [ { |
21 | | - message: 'Use mapFn callback of Array.from instead of map()', |
22 | | - column: 1, |
23 | | - line: 1 |
24 | | - } ], |
25 | | - output: 'Array.from(iterable, (t) => t.id)' |
26 | | - }, |
27 | | - { |
28 | | - code: 'Array.from(iterable, (t) => t.id, a).map((t) => t[0], b)', |
29 | | - errors: [ { |
30 | | - message: 'Use mapFn callback of Array.from instead of map()', |
31 | | - column: 1, |
32 | | - line: 1 |
33 | | - } ], |
34 | | - output: 'Array.from(iterable, (t) => ((t) => t[0])(((t) => t.id)(t)), a)' |
35 | | - }, |
36 | | - { |
37 | | - code: 'Array.from(iterable, function(t) { return t.id; }, a).map((t) => t[0])', |
38 | | - errors: [ { |
39 | | - message: 'Use mapFn callback of Array.from instead of map()', |
40 | | - column: 1, |
41 | | - line: 1 |
42 | | - } ], |
43 | | - output: 'Array.from(iterable, function(t) { return ((t) => t[0])((function(t) { return t.id; }).call(this, t)); }, a)' |
44 | | - }, |
45 | | - { |
46 | | - code: 'Array.from(iterable, function(t) { return t.id; }, a).map(function(t) { return t[0]; }, b)', |
47 | | - errors: [ { |
48 | | - message: 'Use mapFn callback of Array.from instead of map()', |
49 | | - column: 1, |
50 | | - line: 1 |
51 | | - } ], |
52 | | - output: 'Array.from(iterable, function(t) { return (function(t) { return t[0]; }).call(b, (function(t) { return t.id; }).call(this, t)); }, a)' |
53 | | - }, |
54 | | - { |
55 | | - code: 'Array.from(iterable, function(u) { return u.id; }, a).map(function(t, i) { return t[0]; }, b)', |
56 | | - errors: [ { |
57 | | - message: 'Use mapFn callback of Array.from instead of map()', |
58 | | - column: 1, |
59 | | - line: 1 |
60 | | - } ], |
61 | | - output: 'Array.from(iterable, function(t, i) { return (function(t, i) { return t[0]; }).call(b, (function(u) { return u.id; }).call(this, t, i), i); }, a)' |
62 | | - }, |
63 | | - { |
64 | | - code: 'Array.from(iterable, function(u, i) { return u.id; }, a).map(function(t) { return t[0]; }, b)', |
65 | | - errors: [ { |
66 | | - message: 'Use mapFn callback of Array.from instead of map()', |
67 | | - column: 1, |
68 | | - line: 1 |
69 | | - } ], |
70 | | - output: 'Array.from(iterable, function(u, i) { return (function(t) { return t[0]; }).call(b, (function(u, i) { return u.id; }).call(this, u, i), i); }, a)' |
71 | | - } |
72 | | - ] |
73 | | -}); |
| 12 | +ruleTester.run('from-map', rule, testCases); |
0 commit comments