forked from microsoft/tslint-microsoft-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts.lint
73 lines (58 loc) · 2.66 KB
/
test.ts.lint
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
let a: string[];
let b: Array<string> = [];
~~~~~~~~~~~~~ [type % ("Array<string>")]
interface C {
myArray: Array<string>;
~~~~~~~~~~~~~ [type % ("Array<string>")]
}
var d: Array<string>;
~~~~~~~~~~~~~ [type % ("Array<string>")]
function e(param: Array<number>) { }
~~~~~~~~~~~~~ [type % ("Array<number>")]
var f = new Array();
~~~~~~~~~~~ [constructor % ("new Array()")]
var g = new Array(4, 5);
~~~~~~~~~~~~~~~ [constructor % ("new Array(4, 5)")]
var h = new Array(4);
var i = Array(2);
var j = new Array;
~~~~~~~~~ [constructor % ("new Array")]
// calls to Array function/constructor on global objects is forbidden
var nc1 = window.Array(1);
var nc2 = global.Array(1, 2);
~~~~~~~~~~~~~~~~~~ [function % ("global.Array(1, 2)")]
var nc3 = globalThis.Array('3');
~~~~~~~~~~~~~~~~~~~~~ [single-argument % ("function","globalThis.Array('3')")]
var nn1 = new window.Array(1);
var nn2 = new global.Array(1, 2);
~~~~~~~~~~~~~~~~~~~~~~ [constructor % ("new global.Array(1, 2)")]
var nn3 = new globalThis.Array('3');
~~~~~~~~~~~~~~~~~~~~~~~~~ [single-argument % ("constructor", "new globalThis.Array('3')")]
// calls to Array function/constructor from namespaces are valid
import { Types } from 'mongoose';
export const foo: Types.Array<number> = new Types.Array();
declare var num: number;
declare var str: string;
declare var unionA: number | Array<number>;
~~~~~~~~~~~~~ [type % ("Array<number>")]
declare var unionF: number | (() => number);
const t1 = Array(num);
const t2 = Array(str);
~~~~~~~~~~ [single-argument % ("function", "Array(str)")]
const t3 = Array(unionA);
~~~~~~~~~~~~~ [single-argument % ("function", "Array(unionA)")]
const t3 = Array(unionF);
~~~~~~~~~~~~~ [single-argument % ("function", "Array(unionF)")]
const t4 = Array(num + 1);
const t5 = Array(str + 1);
~~~~~~~~~~~~~~ [single-argument % ("function", "Array(str + 1)")]
const t6 = Array(10 + 1);
const t7 = Array(10 + '1');
~~~~~~~~~~~~~~~ [single-argument % ("function", "Array(10 + '1')")]
const t8 = Array(1.5); // no error - limitation of typed rule
const t9 = Array(-1); // no error - limitation of typed rule
const t10 = Array(-num); // no error - limitation of typed rule
[type]: Replace generic-typed Array with array literal: %s
[constructor]: Replace Array constructor with an array literal: %s
[function]: Replace Array function with an array literal: %s
[single-argument]: To create an array of given length you should use non-negative integer. Otherwise replace Array %s with an array literal: %s