@@ -2,7 +2,7 @@ const path = require('path');
2
2
const rule = require ( '../../../lib/rules/no-get' ) ;
3
3
const RuleTester = require ( 'eslint' ) . RuleTester ;
4
4
5
- const { makeErrorMessageForGet , ERROR_MESSAGE_GET_PROPERTIES } = rule ;
5
+ const { ERROR_MESSAGE_GET , ERROR_MESSAGE_GET_PROPERTIES } = rule ;
6
6
7
7
const ruleTester = new RuleTester ( {
8
8
parser : require . resolve ( 'babel-eslint' ) ,
@@ -186,8 +186,7 @@ ruleTester.run('no-get', rule, {
186
186
{
187
187
code : "this.get('foo');" ,
188
188
output : 'this.foo;' ,
189
- // Error message intentionally written out to ensure it looks right.
190
- errors : [ { message : "Use `this.foo` instead of `this.get('foo')`" , type : 'CallExpression' } ] ,
189
+ errors : [ { message : ERROR_MESSAGE_GET , type : 'CallExpression' } ] ,
191
190
} ,
192
191
{
193
192
code : `
@@ -202,16 +201,15 @@ ruleTester.run('no-get', rule, {
202
201
import { random } from 'random';
203
202
this.foo;
204
203
` ,
205
- // Error message intentionally written out to ensure it looks right.
206
- errors : [ { message : "Use `this.foo` instead of `get(this, 'foo')`" , type : 'CallExpression' } ] ,
204
+ errors : [ { message : ERROR_MESSAGE_GET , type : 'CallExpression' } ] ,
207
205
} ,
208
206
{
209
207
// With renamed import:
210
208
code : "import { get as g } from '@ember/object'; g(this, 'foo');" ,
211
209
output : "import { get as g } from '@ember/object'; this.foo;" ,
212
210
errors : [
213
211
{
214
- message : makeErrorMessageForGet ( 'foo' , { isImportedGet : true } ) ,
212
+ message : ERROR_MESSAGE_GET ,
215
213
type : 'CallExpression' ,
216
214
} ,
217
215
] ,
@@ -221,7 +219,7 @@ ruleTester.run('no-get', rule, {
221
219
output : 'this.foo.someFunction();' ,
222
220
errors : [
223
221
{
224
- message : makeErrorMessageForGet ( 'foo' , { isImportedGet : false } ) ,
222
+ message : ERROR_MESSAGE_GET ,
225
223
type : 'CallExpression' ,
226
224
} ,
227
225
] ,
@@ -232,7 +230,7 @@ ruleTester.run('no-get', rule, {
232
230
output : null ,
233
231
errors : [
234
232
{
235
- message : makeErrorMessageForGet ( 'foo-bar' , { isImportedGet : false } ) ,
233
+ message : ERROR_MESSAGE_GET ,
236
234
type : 'CallExpression' ,
237
235
} ,
238
236
] ,
@@ -243,7 +241,7 @@ ruleTester.run('no-get', rule, {
243
241
output : null ,
244
242
errors : [
245
243
{
246
- message : makeErrorMessageForGet ( 'foo-bar' , { isImportedGet : true } ) ,
244
+ message : ERROR_MESSAGE_GET ,
247
245
type : 'CallExpression' ,
248
246
} ,
249
247
] ,
@@ -292,7 +290,7 @@ ruleTester.run('no-get', rule, {
292
290
output : null ,
293
291
errors : [
294
292
{
295
- message : makeErrorMessageForGet ( 'foo.bar' , { isImportedGet : false } ) ,
293
+ message : ERROR_MESSAGE_GET ,
296
294
type : 'CallExpression' ,
297
295
} ,
298
296
] ,
@@ -302,7 +300,7 @@ ruleTester.run('no-get', rule, {
302
300
output : null ,
303
301
errors : [
304
302
{
305
- message : makeErrorMessageForGet ( 'foo.bar' , { isImportedGet : true } ) ,
303
+ message : ERROR_MESSAGE_GET ,
306
304
type : 'CallExpression' ,
307
305
} ,
308
306
] ,
@@ -325,8 +323,7 @@ ruleTester.run('no-get', rule, {
325
323
output : 'this.foo?.bar;' ,
326
324
errors : [
327
325
{
328
- // Error message intentionally written out to ensure it looks right.
329
- message : "Use `this.foo.bar` or `this.foo?.bar` instead of `this.get('foo.bar')`" ,
326
+ message : ERROR_MESSAGE_GET ,
330
327
type : 'CallExpression' ,
331
328
} ,
332
329
] ,
@@ -337,10 +334,7 @@ ruleTester.run('no-get', rule, {
337
334
output : 'this.very?.long?.path;' ,
338
335
errors : [
339
336
{
340
- message : makeErrorMessageForGet ( 'very.long.path' , {
341
- isImportedGet : false ,
342
- useOptionalChaining : true ,
343
- } ) ,
337
+ message : ERROR_MESSAGE_GET ,
344
338
type : 'CallExpression' ,
345
339
} ,
346
340
] ,
@@ -351,10 +345,7 @@ ruleTester.run('no-get', rule, {
351
345
output : "import { get } from '@ember/object'; this.foo?.bar;" ,
352
346
errors : [
353
347
{
354
- message : makeErrorMessageForGet ( 'foo.bar' , {
355
- isImportedGet : true ,
356
- useOptionalChaining : true ,
357
- } ) ,
348
+ message : ERROR_MESSAGE_GET ,
358
349
type : 'CallExpression' ,
359
350
} ,
360
351
] ,
@@ -365,10 +356,7 @@ ruleTester.run('no-get', rule, {
365
356
output : "import { get } from '@ember/object'; this.very?.long?.path;" ,
366
357
errors : [
367
358
{
368
- message : makeErrorMessageForGet ( 'very.long.path' , {
369
- isImportedGet : true ,
370
- useOptionalChaining : true ,
371
- } ) ,
359
+ message : ERROR_MESSAGE_GET ,
372
360
type : 'CallExpression' ,
373
361
} ,
374
362
] ,
@@ -379,10 +367,7 @@ ruleTester.run('no-get', rule, {
379
367
output : 'this.foo;' ,
380
368
errors : [
381
369
{
382
- message : makeErrorMessageForGet ( 'foo' , {
383
- isImportedGet : false ,
384
- useOptionalChaining : true ,
385
- } ) ,
370
+ message : ERROR_MESSAGE_GET ,
386
371
type : 'CallExpression' ,
387
372
} ,
388
373
] ,
@@ -395,10 +380,7 @@ ruleTester.run('no-get', rule, {
395
380
output : "this.foo.bar[123] = 'hello world';" ,
396
381
errors : [
397
382
{
398
- message : makeErrorMessageForGet ( 'foo.bar' , {
399
- isImportedGet : false ,
400
- useOptionalChaining : false ,
401
- } ) ,
383
+ message : ERROR_MESSAGE_GET ,
402
384
type : 'CallExpression' ,
403
385
} ,
404
386
] ,
@@ -411,10 +393,7 @@ ruleTester.run('no-get', rule, {
411
393
output : "this.foo.bar[123] = 'hello world';" ,
412
394
errors : [
413
395
{
414
- message : makeErrorMessageForGet ( 'foo.bar' , {
415
- isImportedGet : false ,
416
- useOptionalChaining : false ,
417
- } ) ,
396
+ message : ERROR_MESSAGE_GET ,
418
397
type : 'CallExpression' ,
419
398
} ,
420
399
] ,
@@ -442,7 +421,7 @@ ruleTester.run('no-get', rule, {
442
421
});
443
422
this.propertyOutsideClass;
444
423
` ,
445
- errors : [ { message : makeErrorMessageForGet ( 'propertyOutsideClass' ) , type : 'CallExpression' } ] ,
424
+ errors : [ { message : ERROR_MESSAGE_GET , type : 'CallExpression' } ] ,
446
425
} ,
447
426
{
448
427
// Reports violation after (native) proxy class.
@@ -466,7 +445,7 @@ ruleTester.run('no-get', rule, {
466
445
}
467
446
this.propertyOutsideClass;
468
447
` ,
469
- errors : [ { message : makeErrorMessageForGet ( 'propertyOutsideClass' ) , type : 'CallExpression' } ] ,
448
+ errors : [ { message : ERROR_MESSAGE_GET , type : 'CallExpression' } ] ,
470
449
} ,
471
450
472
451
{
@@ -491,7 +470,7 @@ ruleTester.run('no-get', rule, {
491
470
});
492
471
this.propertyOutsideClass;
493
472
` ,
494
- errors : [ { message : makeErrorMessageForGet ( 'propertyOutsideClass' ) , type : 'CallExpression' } ] ,
473
+ errors : [ { message : ERROR_MESSAGE_GET , type : 'CallExpression' } ] ,
495
474
} ,
496
475
{
497
476
// Reports violation after (native) class with `unknownProperty()`.
@@ -515,7 +494,7 @@ ruleTester.run('no-get', rule, {
515
494
}
516
495
this.propertyOutsideClass;
517
496
` ,
518
- errors : [ { message : makeErrorMessageForGet ( 'propertyOutsideClass' ) , type : 'CallExpression' } ] ,
497
+ errors : [ { message : ERROR_MESSAGE_GET , type : 'CallExpression' } ] ,
519
498
} ,
520
499
] ,
521
500
} ) ;
0 commit comments