-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
138 lines (135 loc) · 3.95 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import AvaRuleTester from 'eslint-ava-rule-tester'
import noUseExtendNative from '../index.js'
import test from 'ava'
const ruleTester = new AvaRuleTester(test)
const noUseExtendNativeRule = noUseExtendNative.rules['no-use-extend-native']
ruleTester.run('no-use-extend-native/no-use-extend-native', noUseExtendNativeRule, {
valid: [
'error.plugin',
'error.plugn()',
'array.custom',
'Object.assign()',
'Object.keys',
'Object.keys()',
'gulp.task()',
'Custom.prototype.custom',
'Array.prototype.map',
'Array.prototype.map.call([1,2,3], function (x) { console.log(x) })',
'Array.apply',
'Array.call(null, 1, 2, 3)',
'[].push(1)',
'[][0]',
'{}[i]',
'{}[3]',
'{}[j][k]',
'({foo: {bar: 1, baz: 2}}[i][j])',
'({}).toString()',
'/match_this/.test()',
'\'foo\'.length',
'\'hi\'.padEnd',
'\'hi\'.padEnd()',
'console.log(\'foo\'.length)',
'console.log(\'foo\'.toString)',
'console.log(\'foo\'.toString())',
'console.log(gulp.task)',
'console.log(gulp.task())',
'\'string\'.toString()',
'(1).toFixed()',
'1..toFixed()',
'1.0.toFixed()',
'(\'str\' + \'ing\').toString()',
'(\'str\' + \'i\' + \'ng\').toString()',
'(1 + 1).valueOf()',
'(1 + 1 + (1 + 1)).valueOf()',
'(1 + 1 + 1).valueOf()',
'(1 + \'string\').toString()',
'(/regex/ + /regex/).toString()',
'(/regex/ + 1).toString()',
'([1] + [2]).toString()',
'(function testFunction() {}).toString()',
'Test.prototype',
'new Array().toString()',
'new ArrayBuffer().constructor()',
'new Boolean().toString()',
'new DataView().buffer()',
'new Date().getDate()',
'new Error().message()',
'new Error().stack',
'new Error().stack.slice(1)',
'new Float32Array().values()',
'new Float64Array().values()',
'new Function().toString()',
'new Int16Array().values()',
'new Int32Array().values()',
'new Int8Array().values()',
'new Map().clear()',
'new Number().toString()',
'new Object().toString()',
'new Object().toString',
'new Promise().then()',
'new RegExp().test()',
'new Set().values()',
'new String().toString()',
'new Symbol().toString()',
'new Uint16Array().values()',
'new Uint32Array().values()',
'new Uint8ClampedArray().values()',
'new WeakMap().get()',
'new WeakSet().has()',
'new Array()[\'length\']',
'new Array()[\'toString\']()',
'Map.groupBy',
'Object.groupBy',
].map(code => ({code})),
invalid: [
'Array.prototype.custom',
'Array.to',
'Array.to()',
'[].length()',
'\'unicorn\'.green',
'[].custom()',
'({}).custom()',
'/match_this/.custom()',
'\'string\'.custom()',
'console.log(\'foo\'.custom)',
'console.log(\'foo\'.custom())',
'(\'str\' + \'ing\').custom()',
'(\'str\' + \'i\' + \'ng\').custom()',
'(1 + \'ing\').custom()',
'(/regex/ + \'ing\').custom()',
'(1 + 1).toLowerCase()',
'(1 + 1 + 1).toLowerCase()',
'(function testFunction() {}).custom()',
'new Array().custom()',
'new ArrayBuffer().custom()',
'new Boolean().custom()',
'new DataView().custom()',
'new Date().custom()',
'new Error().custom()',
'new Float32Array().custom()',
'new Float64Array().custom()',
'new Function().custom()',
'new Int16Array().custom()',
'new Int32Array().custom()',
'new Int8Array().custom()',
'new Map().custom()',
'new Number().custom()',
'new Object().custom()',
'new Promise().custom()',
'new RegExp().custom()',
'new Set().custom()',
'new String().custom()',
'new Symbol().custom()',
'new Uint16Array().custom()',
'new Uint32Array().custom()',
'new Uint8Array().custom()',
'new Uint8ClampedArray().custom()',
'new WeakMap().custom()',
'new WeakSet().custom()',
'new Array()[\'custom\']',
'new Array()[\'custom\']()'
].map(code => ({
code,
errors: [{message: 'Avoid using extended native objects'}]
}))
})