@@ -20,59 +20,72 @@ ruleTester.run('no-get', rule, {
20
20
21
21
// Nested property path.
22
22
{ code : "this.get('foo.bar');" , options : [ { ignoreNestedPaths : true } ] } ,
23
- { code : "get(this, 'foo.bar');" , options : [ { ignoreNestedPaths : true } ] } ,
23
+ {
24
+ code : "import { get } from '@ember/object'; get(this, 'foo.bar');" ,
25
+ options : [ { ignoreNestedPaths : true } ] ,
26
+ } ,
24
27
25
28
// Template literals.
26
29
{
27
30
code : 'this.get(`foo`);' ,
28
31
parserOptions : { ecmaVersion : 6 } ,
29
32
} ,
30
33
{
31
- code : ' get(this, `foo`);' ,
34
+ code : "import { get } from '@ember/object'; get(this, `foo`);" ,
32
35
parserOptions : { ecmaVersion : 6 } ,
33
36
} ,
34
37
35
38
// Not `this`.
36
39
"foo.get('bar');" ,
37
- "get(foo, 'bar');" ,
40
+ "import { get } from '@ember/object'; get(foo, 'bar');" ,
38
41
39
42
// Not `get`.
40
43
"this.foo('bar');" ,
41
44
"foo(this, 'bar');" ,
42
45
43
46
// Unknown extra argument.
44
47
"this.get('foo', 'bar');" ,
45
- "get(this, 'foo', 'bar');" ,
48
+ "import { get } from '@ember/object'; get(this, 'foo', 'bar');" ,
46
49
47
50
// Non-string parameter.
48
51
'this.get(5);' ,
49
52
'this.get(MY_PROP);' ,
50
- ' get(this, 5);' ,
51
- ' get(this, MY_PROP);' ,
53
+ "import { get } from '@ember/object'; get(this, 5);" ,
54
+ "import { get } from '@ember/object'; get(this, MY_PROP);" ,
52
55
53
56
// Unknown sub-function call:
54
57
"this.get.foo('bar');" ,
55
- "get.foo(this, 'bar');" ,
58
+ "import { get } from '@ember/object'; get.foo(this, 'bar');" ,
56
59
57
60
// In mirage directory
58
61
{
59
62
code : 'this.get("/resources")' ,
60
63
filename : path . join ( 'app' , 'mirage' , 'config.js' ) ,
61
64
} ,
62
65
66
+ // Missing import:
67
+ "get(this, 'foo');" ,
68
+
63
69
// **************************
64
70
// getProperties
65
71
// **************************
66
72
67
73
// Nested property path.
68
74
{ code : "this.getProperties('foo', 'bar.baz');" , options : [ { ignoreNestedPaths : true } ] } ,
69
75
{ code : "this.getProperties(['foo', 'bar.baz']);" , options : [ { ignoreNestedPaths : true } ] } , // With parameters in array.
70
- { code : "getProperties(this, 'foo', 'bar.baz');" , options : [ { ignoreNestedPaths : true } ] } ,
71
- { code : "getProperties(this, ['foo', 'bar.baz']);" , options : [ { ignoreNestedPaths : true } ] } , // With parameters in array.
76
+ {
77
+ code : "import { getProperties } from '@ember/object'; getProperties(this, 'foo', 'bar.baz');" ,
78
+ options : [ { ignoreNestedPaths : true } ] ,
79
+ } ,
80
+ {
81
+ code :
82
+ "import { getProperties } from '@ember/object'; getProperties(this, ['foo', 'bar.baz']);" ,
83
+ options : [ { ignoreNestedPaths : true } ] ,
84
+ } , // With parameters in array.
72
85
73
86
// Template literals.
74
87
'this.getProperties(`prop1`, `prop2`);' ,
75
- ' getProperties(this, `prop1`, `prop2`);' ,
88
+ "import { getProperties } from '@ember/object'; getProperties(this, `prop1`, `prop2`);" ,
76
89
77
90
// Not `this`.
78
91
"myObject.getProperties('prop1', 'prop2');" ,
@@ -84,13 +97,16 @@ ruleTester.run('no-get', rule, {
84
97
'this.getProperties(MY_PROP);' ,
85
98
'this.getProperties(...MY_PROPS);' ,
86
99
'this.getProperties([MY_PROP]);' ,
87
- ' getProperties(this, MY_PROP);' ,
88
- ' getProperties(this, ...MY_PROPS);' ,
89
- ' getProperties(this, [MY_PROP]);' ,
100
+ "import { getProperties } from '@ember/object'; getProperties(this, MY_PROP);" ,
101
+ "import { getProperties } from '@ember/object'; getProperties(this, ...MY_PROPS);" ,
102
+ "import { getProperties } from '@ember/object'; getProperties(this, [MY_PROP]);" ,
90
103
91
104
// Unknown sub-function call:
92
105
"this.getProperties.foo('prop1', 'prop2');" ,
93
106
107
+ // Missing import:
108
+ "getProperties(this, 'prop1', 'prop2');" ,
109
+
94
110
// With ignoreGetProperties: true
95
111
{
96
112
code : "this.getProperties('prop1', 'prop2');" ,
@@ -101,11 +117,12 @@ ruleTester.run('no-get', rule, {
101
117
options : [ { ignoreGetProperties : true } ] ,
102
118
} ,
103
119
{
104
- code : "getProperties(this, 'prop1', 'prop2');" ,
120
+ code : "import { getProperties } from '@ember/object'; getProperties(this, 'prop1', 'prop2');" ,
105
121
options : [ { ignoreGetProperties : true } ] ,
106
122
} ,
107
123
{
108
- code : "getProperties(this, ['prop1', 'prop2']);" , // With parameters in array.
124
+ code :
125
+ "import { getProperties } from '@ember/object'; getProperties(this, ['prop1', 'prop2']);" , // With parameters in array.
109
126
options : [ { ignoreGetProperties : true } ] ,
110
127
} ,
111
128
@@ -173,11 +190,32 @@ ruleTester.run('no-get', rule, {
173
190
errors : [ { message : "Use `this.foo` instead of `this.get('foo')`" , type : 'CallExpression' } ] ,
174
191
} ,
175
192
{
176
- code : "get(this, 'foo');" ,
177
- output : 'this.foo;' ,
193
+ code : `
194
+ import { get } from '@ember/object';
195
+ import { somethingElse } from '@ember/object';
196
+ import { random } from 'random';
197
+ get(this, 'foo');
198
+ ` ,
199
+ output : `
200
+ import { get } from '@ember/object';
201
+ import { somethingElse } from '@ember/object';
202
+ import { random } from 'random';
203
+ this.foo;
204
+ ` ,
178
205
// Error message intentionally written out to ensure it looks right.
179
206
errors : [ { message : "Use `this.foo` instead of `get(this, 'foo')`" , type : 'CallExpression' } ] ,
180
207
} ,
208
+ {
209
+ // With renamed import:
210
+ code : "import { get as g } from '@ember/object'; g(this, 'foo');" ,
211
+ output : "import { get as g } from '@ember/object'; this.foo;" ,
212
+ errors : [
213
+ {
214
+ message : makeErrorMessageForGet ( 'foo' , { isImportedGet : true } ) ,
215
+ type : 'CallExpression' ,
216
+ } ,
217
+ ] ,
218
+ } ,
181
219
{
182
220
code : "this.get('foo').someFunction();" ,
183
221
output : 'this.foo.someFunction();' ,
@@ -201,7 +239,7 @@ ruleTester.run('no-get', rule, {
201
239
} ,
202
240
{
203
241
// With invalid JS variable name:
204
- code : "get(this, 'foo-bar');" ,
242
+ code : "import { get } from '@ember/object'; get(this, 'foo-bar');" ,
205
243
output : null ,
206
244
errors : [
207
245
{
@@ -226,12 +264,24 @@ ruleTester.run('no-get', rule, {
226
264
errors : [ { message : ERROR_MESSAGE_GET_PROPERTIES , type : 'CallExpression' } ] ,
227
265
} ,
228
266
{
229
- code : "getProperties(this, 'prop1', 'prop2');" ,
267
+ code : `
268
+ import { getProperties } from '@ember/object';
269
+ import { somethingElse } from '@ember/object';
270
+ import { random } from 'random';
271
+ getProperties(this, 'prop1', 'prop2');
272
+ ` ,
230
273
output : null ,
231
274
errors : [ { message : ERROR_MESSAGE_GET_PROPERTIES , type : 'CallExpression' } ] ,
232
275
} ,
233
276
{
234
- code : "getProperties(this, ['prop1', 'prop2']);" , // With parameters in array.
277
+ // With renamed import:
278
+ code : "import { getProperties as gp } from '@ember/object'; gp(this, 'prop1', 'prop2');" ,
279
+ output : null ,
280
+ errors : [ { message : ERROR_MESSAGE_GET_PROPERTIES , type : 'CallExpression' } ] ,
281
+ } ,
282
+ {
283
+ code :
284
+ "import { getProperties } from '@ember/object'; getProperties(this, ['prop1', 'prop2']);" , // With parameters in array.
235
285
output : null ,
236
286
errors : [ { message : ERROR_MESSAGE_GET_PROPERTIES , type : 'CallExpression' } ] ,
237
287
} ,
@@ -248,7 +298,7 @@ ruleTester.run('no-get', rule, {
248
298
] ,
249
299
} ,
250
300
{
251
- code : "get(this, 'foo.bar');" ,
301
+ code : "import { get } from '@ember/object'; get(this, 'foo.bar');" ,
252
302
output : null ,
253
303
errors : [
254
304
{
@@ -263,7 +313,7 @@ ruleTester.run('no-get', rule, {
263
313
errors : [ { message : ERROR_MESSAGE_GET_PROPERTIES , type : 'CallExpression' } ] ,
264
314
} ,
265
315
{
266
- code : "getProperties(this, 'foo.bar');" ,
316
+ code : "import { getProperties } from '@ember/object'; getProperties(this, 'foo.bar');" ,
267
317
output : null ,
268
318
errors : [ { message : ERROR_MESSAGE_GET_PROPERTIES , type : 'CallExpression' } ] ,
269
319
} ,
@@ -296,9 +346,9 @@ ruleTester.run('no-get', rule, {
296
346
] ,
297
347
} ,
298
348
{
299
- code : "get(this, 'foo.bar');" ,
349
+ code : "import { get } from '@ember/object'; get(this, 'foo.bar');" ,
300
350
options : [ { useOptionalChaining : true } ] ,
301
- output : ' this.foo?.bar;' ,
351
+ output : "import { get } from '@ember/object'; this.foo?.bar;" ,
302
352
errors : [
303
353
{
304
354
message : makeErrorMessageForGet ( 'foo.bar' , {
@@ -310,9 +360,9 @@ ruleTester.run('no-get', rule, {
310
360
] ,
311
361
} ,
312
362
{
313
- code : "get(this, 'very.long.path');" ,
363
+ code : "import { get } from '@ember/object'; get(this, 'very.long.path');" ,
314
364
options : [ { useOptionalChaining : true } ] ,
315
- output : ' this.very?.long?.path;' ,
365
+ output : "import { get } from '@ember/object'; this.very?.long?.path;" ,
316
366
errors : [
317
367
{
318
368
message : makeErrorMessageForGet ( 'very.long.path' , {
0 commit comments