-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathno-deprecated.js
158 lines (133 loc) · 5.45 KB
/
no-deprecated.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { test } from '../utils'
import { RuleTester } from 'eslint'
const ruleTester = new RuleTester()
, rule = require('rules/no-deprecated')
ruleTester.run('no-deprecated', rule, {
valid: [
test({ code: "import { x } from './fake' " }),
test({ code: "import bar from './bar'" }),
test({ code: "import { fine } from './deprecated'" }),
test({ code: "import { _undocumented } from './deprecated'" }),
// naked namespace is fine
test({ code: "import * as depd from './deprecated'" }),
test({ code: "import * as depd from './deprecated'; console.log(depd.fine())" }),
test({ code: "import { deepDep } from './deep-deprecated'" }),
test({ code: "import { deepDep } from './deep-deprecated'; console.log(deepDep.fine())" }),
// redefined
test({
code: "import { deepDep } from './deep-deprecated'; function x(deepDep) { console.log(deepDep.MY_TERRIBLE_ACTION) }",
}),
],
invalid: [
// reports on parse errors even without specifiers
test({ code: "import './malformed.js'", errors: 1 }),
test({
code: "import { fn } from './deprecated'",
errors: ["Deprecated: please use 'x' instead."],
}),
test({
code: "import TerribleClass from './deprecated'",
errors: ['Deprecated: this is awful, use NotAsBadClass.'],
}),
test({
code: "import { MY_TERRIBLE_ACTION } from './deprecated'",
errors: ['Deprecated: please stop sending/handling this action type.'],
}),
// ignore redeclares
test({
code: "import { MY_TERRIBLE_ACTION } from './deprecated'; function shadow(MY_TERRIBLE_ACTION) { console.log(MY_TERRIBLE_ACTION); }",
errors: ['Deprecated: please stop sending/handling this action type.'],
}),
// ignore non-deprecateds
test({
code: "import { MY_TERRIBLE_ACTION, fine } from './deprecated'; console.log(fine)",
errors: ['Deprecated: please stop sending/handling this action type.'],
}),
// reflag on subsequent usages
test({
code: "import { MY_TERRIBLE_ACTION } from './deprecated'; console.log(MY_TERRIBLE_ACTION)",
errors: [
{ type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' },
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
// don't flag other members
test({
code: "import { MY_TERRIBLE_ACTION } from './deprecated'; console.log(someOther.MY_TERRIBLE_ACTION)",
errors: [
{ type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
// flag it even with members
test({
code: "import { MY_TERRIBLE_ACTION } from './deprecated'; console.log(MY_TERRIBLE_ACTION.whatever())",
errors: [
{ type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' },
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
// works for function calls too
test({
code: "import { MY_TERRIBLE_ACTION } from './deprecated'; console.log(MY_TERRIBLE_ACTION(this, is, the, worst))",
errors: [
{ type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' },
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
// deprecated full module
test({
code: "import Thing from './deprecated-file'",
errors: [
{ type: 'ImportDeclaration', message: 'Deprecated: this module is the worst.' },
],
}),
// don't flag as part of other member expressions
test({
code: "import Thing from './deprecated-file'; console.log(other.Thing)",
errors: [
{ type: 'ImportDeclaration', message: 'Deprecated: this module is the worst.' },
],
}),
// namespace following
test({
code: "import * as depd from './deprecated'; console.log(depd.MY_TERRIBLE_ACTION)",
errors: [
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
test({
code: "import * as deep from './deep-deprecated'; console.log(deep.deepDep.MY_TERRIBLE_ACTION)",
errors: [
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
test({
code: "import { deepDep } from './deep-deprecated'; console.log(deepDep.MY_TERRIBLE_ACTION)",
errors: [
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
test({
code: "import { deepDep } from './deep-deprecated'; function x(deepNDep) { console.log(deepDep.MY_TERRIBLE_ACTION) }",
errors: [
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
],
})
ruleTester.run('no-deprecated: hoisting', rule, {
valid: [
test({
code: "function x(deepDep) { console.log(deepDep.MY_TERRIBLE_ACTION) } import { deepDep } from './deep-deprecated'",
}),
],
invalid: [
test({
code: "console.log(MY_TERRIBLE_ACTION); import { MY_TERRIBLE_ACTION } from './deprecated'",
errors: [
{ type: 'Identifier', message: 'Deprecated: please stop sending/handling this action type.' },
{ type: 'ImportSpecifier', message: 'Deprecated: please stop sending/handling this action type.' },
],
}),
],
})