@@ -3,7 +3,7 @@ const rule = require('../../../lib/rules/assets-deprecation');
33const deprecationsJson = require ( '../../assets_deprecation.json' ) ;
44
55RuleTester . setDefaultConfig ( {
6- parser : 'babel-eslint' ,
6+ parser : require . resolve ( 'babel-eslint' ) ,
77 parserOptions : { ecmaVersion : 6 , ecmaFeatures : { jsx : true } }
88} ) ;
99
@@ -205,6 +205,23 @@ class Example extends React.Component {
205205
206206export default Example;` ;
207207
208+ const partialClassTest1 = `
209+ function createImages() {
210+ const IDs1 = require('my-ids-1');
211+ const {Assets} = require('${ ourSource } ');
212+ const IDs2 = require('my-ids-2');
213+
214+ const images = {};
215+ images[IDs1.ID1] = Assets.icons.valid;
216+ images[IDs1.ID2] = Assets.icons.deprecated;
217+ images[IDs1.ID3] = Assets.icons.general.valid;
218+ images[IDs1.ID4] = require('../../images/image1.png');
219+ images[IDs2.ID5] = require('../../images/image2.png');
220+ images[IDs2.ID6] = Assets.icons.general.valid2;
221+ images[IDs2.ID7] = Assets.icons.valid2;
222+ return images;
223+ }` ;
224+
208225const error =
209226 "'Assets.icons.deprecated' is deprecated. Please use 'Assets.icons.general.valid' instead (fix is available)." ;
210227const errorDate = ' Please fix this issue by 2 November, Friday!' ;
@@ -276,119 +293,115 @@ ruleTester.run('assets-deprecation', rule, {
276293 {
277294 options : options ,
278295 code : `${ ourImport } ${ constDeprecated1 } ` ,
279- output : `${ ourImport } const assets = Assets.icons.general.valid; ` ,
296+ output : `${ ourImport } ${ constValid1 } ` ,
280297 errors : [ { message : error } ]
281298 } ,
282299 {
283300 options : optionsWithDate ,
284301 code : `${ ourImport } ${ constDeprecated1 } ` ,
285- output : `${ ourImport } const assets = Assets.icons.general.valid; ` ,
302+ output : `${ ourImport } ${ constValid1 } ` ,
286303 errors : [ { message : error + errorDate } ]
287304 } ,
288305 {
289306 options : optionsWithDate ,
290307 code : `${ ourImport } ${ constDeprecated2 } ` ,
291- output : `${ ourImport } const assets = <Button iconSource={Assets.icons.general.valid}/>; ` ,
308+ output : `${ ourImport } ${ constValid2 } ` ,
292309 errors : [ { message : error + errorDate } ]
293310 } ,
294311 {
295312 options : options ,
296313 code : `${ ourImport } ${ jsxDeprecated1 } ${ jsx1 } ` ,
297- output : `${ ourImport } const others = {iconSource: Assets.icons.general.valid}; ${ jsx1 } ` ,
314+ output : `${ ourImport } ${ jsxValid1 } ${ jsx1 } ` ,
298315 errors : [ { message : error } ]
299316 } ,
300317 {
301318 options : options ,
302319 code : `${ ourImport } ${ jsxDeprecated2 } ` ,
303- output : `${ ourImport } <Button iconSource={Assets.icons.general.valid}/> ` ,
320+ output : `${ ourImport } ${ jsxValid2 } ` ,
304321 errors : [ { message : error } ]
305322 } ,
306323 {
307324 options : options ,
308325 code : `${ ourImport } ${ jsxDeprecated3 } ` ,
309- output : `${ ourImport } <View><Button iconSource={Assets.icons.general.valid}/></View> ` ,
326+ output : `${ ourImport } ${ jsxValid3 } ` ,
310327 errors : [ { message : error } ]
311328 } ,
312329 {
313330 options : options ,
314331 code : `${ ourImport } ${ jsxDeprecated4 } ` ,
315- output : `${ ourImport } const others = {iconSource: Assets.icons.general.valid}; const test = <Button {...others}/> ` ,
332+ output : `${ ourImport } ${ jsxValid4 } ` ,
316333 errors : [ { message : error } ]
317334 } ,
318335 {
319336 options : options ,
320337 code : `${ fullClassDeprecated } ` ,
338+ output : `${ fullClassValid } ` ,
321339 errors : [ { message : error } , { message : error } , { message : error } ]
322340 } ,
323341 {
324342 options : options ,
325343 code : `${ ourImportRenamed } ${ constDeprecatedRenamed1 } ` ,
326- output : `${ ourImportRenamed } const assets = UIAssets.icons.general.valid; ` ,
344+ output : `${ ourImportRenamed } ${ constValidRenamed1 } ` ,
327345 errors : [ { message : error } ]
328346 } ,
329347 {
330348 options : optionsWithDate ,
331349 code : `${ ourImportRenamed } ${ constDeprecatedRenamed1 } ` ,
350+ output : `${ ourImportRenamed } ${ constValidRenamed1 } ` ,
332351 errors : [ { message : error + errorDate } ]
333352 } ,
334353 {
335354 options : optionsWithDate ,
336355 code : `${ ourImportRenamed } ${ constDeprecatedRenamed2 } ` ,
356+ output : `${ ourImportRenamed } ${ constValidRenamed2 } ` ,
337357 errors : [ { message : error + errorDate } ]
338358 } ,
339359 {
340360 options : options ,
341361 code : `${ ourImportRenamed } ${ jsxDeprecatedRenamed1 } ${ jsx1 } ` ,
362+ output : `${ ourImportRenamed } ${ jsxValidRenamed1 } ${ jsx1 } ` ,
342363 errors : [ { message : error } ]
343364 } ,
344365 {
345366 options : options ,
346367 code : `${ ourImportRenamed } ${ jsxDeprecatedRenamed2 } ` ,
368+ output : `${ ourImportRenamed } ${ jsxValidRenamed2 } ` ,
347369 errors : [ { message : error } ]
348370 } ,
349371 {
350372 options : options ,
351373 code : `${ ourImportRenamed } ${ jsxDeprecatedRenamed3 } ` ,
374+ output : `${ ourImportRenamed } ${ jsxValidRenamed3 } ` ,
352375 errors : [ { message : error } ]
353376 } ,
354377 {
355378 options : options ,
356379 code : `${ ourImportRenamed } ${ jsxDeprecatedRenamed4 } ` ,
380+ output : `${ ourImportRenamed } ${ jsxValidRenamed4 } ` ,
357381 errors : [ { message : error } ]
358382 } ,
359383 {
360384 options : options ,
361385 code : `${ fullClassDeprecatedRenamed } ` ,
386+ output : `${ fullClassValidRenamed } ` ,
362387 errors : [ { message : error } , { message : error } , { message : error } ]
363388 } ,
364389 {
365390 options : options ,
366391 code : `${ fullClassTest1 } ` ,
392+ output : fullClassTest1 . replace ( 'Assets.icons.deprecated' , 'Assets.icons.general.valid' ) ,
367393 errors : [ { message : error } ]
368394 } ,
369395 {
370396 options : options ,
371397 code : `${ fullClassTest2 } ` ,
398+ output : fullClassTest2 . replace ( 'Assets.icons.deprecated' , 'Assets.icons.general.valid' ) ,
372399 errors : [ { message : error } ]
373400 } ,
374401 {
375402 options : options ,
376- code : `
377- function createImages() {
378- const IDs1 = require('my-ids-1');
379- const {Assets} = require('${ ourSource } ');
380- const IDs2 = require('my-ids-2');
381-
382- const images = {};
383- images[IDs1.ID1] = Assets.icons.valid;
384- images[IDs1.ID2] = Assets.icons.deprecated;
385- images[IDs1.ID3] = Assets.icons.general.valid;
386- images[IDs1.ID4] = require('../../images/image1.png');
387- images[IDs2.ID5] = require('../../images/image2.png');
388- images[IDs2.ID6] = Assets.icons.general.valid2;
389- images[IDs2.ID7] = Assets.icons.valid2;
390- return images;
391- }` ,
403+ code : `${ partialClassTest1 } ` ,
404+ output : partialClassTest1 . replace ( 'Assets.icons.deprecated' , 'Assets.icons.general.valid' ) ,
392405 errors : [ { message : error } ]
393406 } ,
394407 {
@@ -400,6 +413,14 @@ const props = {
400413 title: 'title',
401414 subtitle: 'subtitle',
402415 icon: Assets.icons.deprecated
416+ };` ,
417+ output : `
418+ ${ ourImport }
419+
420+ const props = {
421+ title: 'title',
422+ subtitle: 'subtitle',
423+ icon: Assets.icons.general.valid
403424};` ,
404425 errors : [ { message : error } ]
405426 } ,
@@ -412,6 +433,14 @@ const props = {
412433 title: 'title',
413434 subtitle: 'subtitle',
414435 icon: Assets.icons['deprecated']
436+ };` ,
437+ output : `
438+ ${ ourImport }
439+
440+ const props = {
441+ title: 'title',
442+ subtitle: 'subtitle',
443+ icon: Assets.icons.general.valid
415444};` ,
416445 errors : [ { message : error } ]
417446 }
0 commit comments