Skip to content

Commit 9e50568

Browse files
authored
Support Float16Array (#2622)
1 parent 48c54d9 commit 9e50568

10 files changed

+99
-39
lines changed

docs/rules/new-for-builtins.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Enforces the use of `new` for following builtins:
1919
- [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
2020
- [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2121
- [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
22+
- [`Float16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
2223
- [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)
2324
- [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array)
2425
- [`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)

rules/shared/typed-array.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const typedArrayTypes = [
77
'Uint16Array',
88
'Int32Array',
99
'Uint32Array',
10+
'Float16Array',
1011
'Float32Array',
1112
'Float64Array',
1213
'BigInt64Array',

test/new-for-builtins.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test.snapshot({
1414
'const foo = new BigUint64Array()',
1515
'const foo = new DataView()',
1616
'const foo = new Error()',
17+
'const foo = new Float16Array()',
1718
'const foo = new Float32Array()',
1819
'const foo = new Float64Array()',
1920
'const foo = new Function()',
@@ -206,6 +207,7 @@ test.snapshot({
206207
'const foo = DataView()',
207208
'const foo = Error()',
208209
'const foo = Error(\'Foo bar\')',
210+
'const foo = Float16Array()',
209211
'const foo = Float32Array()',
210212
'const foo = Float64Array()',
211213
'const foo = Function()',

test/no-instanceof-builtins.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const strictStrategyInvalid = [
4242
'foo instanceof Uint16Array',
4343
'foo instanceof Int32Array',
4444
'foo instanceof Uint32Array',
45+
'foo instanceof Float16Array',
4546
'foo instanceof Float32Array',
4647
'foo instanceof Float64Array',
4748
'foo instanceof BigInt64Array',

test/prefer-negative-index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ test({
226226
Int32Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
227227
Uint32Array.prototype.slice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
228228
Uint32Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
229+
Float16Array.prototype.slice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
230+
Float16Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
229231
Float32Array.prototype.slice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
230232
Float32Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
231233
Float64Array.prototype.slice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
@@ -237,7 +239,7 @@ test({
237239
NOT_SUPPORTED.prototype.slice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
238240
NOT_SUPPORTED.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
239241
`,
240-
errors: Array.from({length: 15}, () => error),
242+
errors: Array.from({length: 16}, () => error),
241243
output: outdent`
242244
Array.prototype.slice.call(foo, - 1, - 2, foo.length - 3);
243245
Array.prototype.splice.call(foo, - 1, foo.length - 2, foo.length - 3);
@@ -259,6 +261,8 @@ test({
259261
Int32Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
260262
Uint32Array.prototype.slice.call(foo, - 1, - 2, foo.length - 3);
261263
Uint32Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
264+
Float16Array.prototype.slice.call(foo, - 1, - 2, foo.length - 3);
265+
Float16Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
262266
Float32Array.prototype.slice.call(foo, - 1, - 2, foo.length - 3);
263267
Float32Array.prototype.splice.call(foo, foo.length - 1, foo.length - 2, foo.length - 3);
264268
Float64Array.prototype.slice.call(foo, - 1, - 2, foo.length - 3);
@@ -295,6 +299,8 @@ test({
295299
Int32Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
296300
Uint32Array.prototype.slice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
297301
Uint32Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
302+
Float16Array.prototype.slice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
303+
Float16Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
298304
Float32Array.prototype.slice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
299305
Float32Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
300306
Float64Array.prototype.slice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
@@ -306,7 +312,7 @@ test({
306312
NOT_SUPPORTED.prototype.slice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
307313
NOT_SUPPORTED.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
308314
`,
309-
errors: Array.from({length: 15}, () => error),
315+
errors: Array.from({length: 16}, () => error),
310316
output: outdent`
311317
Array.prototype.slice.apply(foo, [- 1, - 2, foo.length - 3]);
312318
Array.prototype.splice.apply(foo, [- 1, foo.length - 2, foo.length - 3]);
@@ -328,6 +334,8 @@ test({
328334
Int32Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
329335
Uint32Array.prototype.slice.apply(foo, [- 1, - 2, foo.length - 3]);
330336
Uint32Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
337+
Float16Array.prototype.slice.apply(foo, [- 1, - 2, foo.length - 3]);
338+
Float16Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
331339
Float32Array.prototype.slice.apply(foo, [- 1, - 2, foo.length - 3]);
332340
Float32Array.prototype.splice.apply(foo, [foo.length - 1, foo.length - 2, foo.length - 3]);
333341
Float64Array.prototype.slice.apply(foo, [- 1, - 2, foo.length - 3]);

test/prefer-spread.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ test.snapshot({
1616
'Uint16Array.from(set);',
1717
'Int32Array.from(set);',
1818
'Uint32Array.from(set);',
19+
'Float16Array.from(set);',
1920
'Float32Array.from(set);',
2021
'Float64Array.from(set);',
2122
'BigInt64Array.from(set);',

test/snapshots/new-for-builtins.js.md

+46-25
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,28 @@ Generated by [AVA](https://avajs.dev).
782782
| ^^^^^^^^^^^^^^^^ Use \`new Error()\` instead of \`Error()\`.␊
783783
`
784784

785-
## invalid(35): const foo = Float32Array()
785+
## invalid(35): const foo = Float16Array()
786+
787+
> Input
788+
789+
`␊
790+
1 | const foo = Float16Array()␊
791+
`
792+
793+
> Output
794+
795+
`␊
796+
1 | const foo = new Float16Array()␊
797+
`
798+
799+
> Error 1/1
800+
801+
`␊
802+
> 1 | const foo = Float16Array()␊
803+
| ^^^^^^^^^^^^^^ Use \`new Float16Array()\` instead of \`Float16Array()\`.␊
804+
`
805+
806+
## invalid(36): const foo = Float32Array()
786807

787808
> Input
788809
@@ -803,7 +824,7 @@ Generated by [AVA](https://avajs.dev).
803824
| ^^^^^^^^^^^^^^ Use \`new Float32Array()\` instead of \`Float32Array()\`.␊
804825
`
805826

806-
## invalid(36): const foo = Float64Array()
827+
## invalid(37): const foo = Float64Array()
807828

808829
> Input
809830
@@ -824,7 +845,7 @@ Generated by [AVA](https://avajs.dev).
824845
| ^^^^^^^^^^^^^^ Use \`new Float64Array()\` instead of \`Float64Array()\`.␊
825846
`
826847

827-
## invalid(37): const foo = Function()
848+
## invalid(38): const foo = Function()
828849

829850
> Input
830851
@@ -845,7 +866,7 @@ Generated by [AVA](https://avajs.dev).
845866
| ^^^^^^^^^^ Use \`new Function()\` instead of \`Function()\`.␊
846867
`
847868

848-
## invalid(38): const foo = Int8Array()
869+
## invalid(39): const foo = Int8Array()
849870

850871
> Input
851872
@@ -866,7 +887,7 @@ Generated by [AVA](https://avajs.dev).
866887
| ^^^^^^^^^^^ Use \`new Int8Array()\` instead of \`Int8Array()\`.␊
867888
`
868889

869-
## invalid(39): const foo = Int16Array()
890+
## invalid(40): const foo = Int16Array()
870891

871892
> Input
872893
@@ -887,7 +908,7 @@ Generated by [AVA](https://avajs.dev).
887908
| ^^^^^^^^^^^^ Use \`new Int16Array()\` instead of \`Int16Array()\`.␊
888909
`
889910

890-
## invalid(40): const foo = Int32Array()
911+
## invalid(41): const foo = Int32Array()
891912

892913
> Input
893914
@@ -908,7 +929,7 @@ Generated by [AVA](https://avajs.dev).
908929
| ^^^^^^^^^^^^ Use \`new Int32Array()\` instead of \`Int32Array()\`.␊
909930
`
910931

911-
## invalid(41): const foo = (( Map ))()
932+
## invalid(42): const foo = (( Map ))()
912933

913934
> Input
914935
@@ -929,7 +950,7 @@ Generated by [AVA](https://avajs.dev).
929950
| ^^^^^^^^^^^ Use \`new Map()\` instead of \`Map()\`.␊
930951
`
931952

932-
## invalid(42): const foo = Map([['foo', 'bar'], ['unicorn', 'rainbow']])
953+
## invalid(43): const foo = Map([['foo', 'bar'], ['unicorn', 'rainbow']])
933954

934955
> Input
935956
@@ -950,7 +971,7 @@ Generated by [AVA](https://avajs.dev).
950971
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use \`new Map()\` instead of \`Map()\`.␊
951972
`
952973

953-
## invalid(43): const foo = WeakMap()
974+
## invalid(44): const foo = WeakMap()
954975

955976
> Input
956977
@@ -971,7 +992,7 @@ Generated by [AVA](https://avajs.dev).
971992
| ^^^^^^^^^ Use \`new WeakMap()\` instead of \`WeakMap()\`.␊
972993
`
973994

974-
## invalid(44): const foo = Set()
995+
## invalid(45): const foo = Set()
975996

976997
> Input
977998
@@ -992,7 +1013,7 @@ Generated by [AVA](https://avajs.dev).
9921013
| ^^^^^ Use \`new Set()\` instead of \`Set()\`.␊
9931014
`
9941015

995-
## invalid(45): const foo = WeakSet()
1016+
## invalid(46): const foo = WeakSet()
9961017

9971018
> Input
9981019
@@ -1013,7 +1034,7 @@ Generated by [AVA](https://avajs.dev).
10131034
| ^^^^^^^^^ Use \`new WeakSet()\` instead of \`WeakSet()\`.␊
10141035
`
10151036

1016-
## invalid(46): const foo = Promise()
1037+
## invalid(47): const foo = Promise()
10171038

10181039
> Input
10191040
@@ -1034,7 +1055,7 @@ Generated by [AVA](https://avajs.dev).
10341055
| ^^^^^^^^^ Use \`new Promise()\` instead of \`Promise()\`.␊
10351056
`
10361057

1037-
## invalid(47): const foo = RegExp()
1058+
## invalid(48): const foo = RegExp()
10381059

10391060
> Input
10401061
@@ -1055,7 +1076,7 @@ Generated by [AVA](https://avajs.dev).
10551076
| ^^^^^^^^ Use \`new RegExp()\` instead of \`RegExp()\`.␊
10561077
`
10571078

1058-
## invalid(48): const foo = Uint8Array()
1079+
## invalid(49): const foo = Uint8Array()
10591080

10601081
> Input
10611082
@@ -1076,7 +1097,7 @@ Generated by [AVA](https://avajs.dev).
10761097
| ^^^^^^^^^^^^ Use \`new Uint8Array()\` instead of \`Uint8Array()\`.␊
10771098
`
10781099

1079-
## invalid(49): const foo = Uint16Array()
1100+
## invalid(50): const foo = Uint16Array()
10801101

10811102
> Input
10821103
@@ -1097,7 +1118,7 @@ Generated by [AVA](https://avajs.dev).
10971118
| ^^^^^^^^^^^^^ Use \`new Uint16Array()\` instead of \`Uint16Array()\`.␊
10981119
`
10991120

1100-
## invalid(50): const foo = Uint32Array()
1121+
## invalid(51): const foo = Uint32Array()
11011122

11021123
> Input
11031124
@@ -1118,7 +1139,7 @@ Generated by [AVA](https://avajs.dev).
11181139
| ^^^^^^^^^^^^^ Use \`new Uint32Array()\` instead of \`Uint32Array()\`.␊
11191140
`
11201141

1121-
## invalid(51): const foo = Uint8ClampedArray()
1142+
## invalid(52): const foo = Uint8ClampedArray()
11221143

11231144
> Input
11241145
@@ -1139,7 +1160,7 @@ Generated by [AVA](https://avajs.dev).
11391160
| ^^^^^^^^^^^^^^^^^^^ Use \`new Uint8ClampedArray()\` instead of \`Uint8ClampedArray()\`.␊
11401161
`
11411162

1142-
## invalid(52): const foo = new BigInt(123)
1163+
## invalid(53): const foo = new BigInt(123)
11431164

11441165
> Input
11451166
@@ -1160,7 +1181,7 @@ Generated by [AVA](https://avajs.dev).
11601181
| ^^^^^^^^^^^^^^^ Use \`BigInt()\` instead of \`new BigInt()\`.␊
11611182
`
11621183

1163-
## invalid(53): const foo = new Boolean()
1184+
## invalid(54): const foo = new Boolean()
11641185

11651186
> Input
11661187
@@ -1175,7 +1196,7 @@ Generated by [AVA](https://avajs.dev).
11751196
| ^^^^^^^^^^^^^ Use \`Boolean()\` instead of \`new Boolean()\`.␊
11761197
`
11771198

1178-
## invalid(54): const foo = new Number()
1199+
## invalid(55): const foo = new Number()
11791200

11801201
> Input
11811202
@@ -1190,7 +1211,7 @@ Generated by [AVA](https://avajs.dev).
11901211
| ^^^^^^^^^^^^ Use \`Number()\` instead of \`new Number()\`.␊
11911212
`
11921213

1193-
## invalid(55): const foo = new Number('123')
1214+
## invalid(56): const foo = new Number('123')
11941215

11951216
> Input
11961217
@@ -1205,7 +1226,7 @@ Generated by [AVA](https://avajs.dev).
12051226
| ^^^^^^^^^^^^^^^^^ Use \`Number()\` instead of \`new Number()\`.␊
12061227
`
12071228

1208-
## invalid(56): const foo = new String()
1229+
## invalid(57): const foo = new String()
12091230

12101231
> Input
12111232
@@ -1220,7 +1241,7 @@ Generated by [AVA](https://avajs.dev).
12201241
| ^^^^^^^^^^^^ Use \`String()\` instead of \`new String()\`.␊
12211242
`
12221243

1223-
## invalid(57): const foo = new Symbol()
1244+
## invalid(58): const foo = new Symbol()
12241245

12251246
> Input
12261247
@@ -1241,7 +1262,7 @@ Generated by [AVA](https://avajs.dev).
12411262
| ^^^^^^^^^^^^ Use \`Symbol()\` instead of \`new Symbol()\`.␊
12421263
`
12431264

1244-
## invalid(58): function varCheck() { { var WeakMap = function() {}; } // This should not reported return WeakMap() } function constCheck() { { const Array = function() {}; } return Array() } function letCheck() { { let Map = function() {}; } return Map() }
1265+
## invalid(59): function varCheck() { { var WeakMap = function() {}; } // This should not reported return WeakMap() } function constCheck() { { const Array = function() {}; } return Array() } function letCheck() { { let Map = function() {}; } return Map() }
12451266

12461267
> Input
12471268
@@ -1341,7 +1362,7 @@ Generated by [AVA](https://avajs.dev).
13411362
19 | }␊
13421363
`
13431364

1344-
## invalid(59): function foo() { return(globalThis).Map() }
1365+
## invalid(60): function foo() { return(globalThis).Map() }
13451366

13461367
> Input
13471368
25 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)