forked from sindresorhus/eslint-plugin-unicorn
/
prefer-trim-start-end.js
51 lines (47 loc) · 907 Bytes
/
prefer-trim-start-end.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import rule from '../rules/prefer-trim-start-end';
const ruleTester = avaRuleTester(test, {
env: {
es6: true
}
});
const errorTrimLeft = {
ruleId: 'prefer-trim-start-end',
messageId: 'trimLeft'
};
const errorTrimRight = {
ruleId: 'prefer-trim-start-end',
messageId: 'trimRight'
};
ruleTester.run('prefer-flat-map', rule, {
valid: [
'foo.trimStart()',
'foo.trimEnd()',
// Extra arguments
'foo.trimLeft(1)',
// New
'new foo.trimLeft()',
// Function call
'trimLeft()',
// Not call
'foo.trimLeft'
],
invalid: [
{
code: 'foo.trimLeft()',
output: 'foo.trimStart()',
errors: [errorTrimLeft]
},
{
code: 'foo.trimRight()',
output: 'foo.trimEnd()',
errors: [errorTrimRight]
},
{
code: '"foo".trimLeft()',
output: '"foo".trimStart()',
errors: [errorTrimLeft]
}
]
});